Changeset 132ab5d1 in mainline for uspace/srv/hid/output/port/chardev.c
- Timestamp:
- 2018-01-30T03:20:45Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5a6cc679
- Parents:
- 8bfb163 (diff), 6a5d05b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
uspace/srv/hid/output/port/chardev.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/output/port/chardev.c
r8bfb163 r132ab5d1 1 1 /* 2 2 * Copyright (c) 2016 Jakub Jermar 3 * Copyright (c) 2017 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 30 31 */ 31 32 33 #include <async.h> 34 #include <config.h> 35 #include <errno.h> 36 #include <fibril_synch.h> 37 #include <io/chardev.h> 38 #include <loc.h> 32 39 #include <stddef.h> 33 40 #include <stdint.h> 34 #include <char_dev_iface.h>35 41 #include <stdio.h> 36 42 #include <stdlib.h> 37 #include <async.h>38 #include <fibril_synch.h>39 #include <loc.h>40 #include <errno.h>41 43 #include <str.h> 42 #include <config.h>43 44 #include "../ctl/serial.h" 44 45 #include "../output.h" 45 46 #include "chardev.h" 46 47 48 enum { 49 chardev_buf_size = 4096 50 }; 51 47 52 static char *console; 48 53 49 54 static async_sess_t *sess; 55 static chardev_t *chardev; 50 56 static service_id_t serial_cat_id; 57 static service_id_t console_cat_id; 58 59 static uint8_t chardev_buf[chardev_buf_size]; 60 static size_t chardev_bused; 51 61 52 62 static FIBRIL_MUTEX_INITIALIZE(discovery_lock); … … 54 64 static FIBRIL_CONDVAR_INITIALIZE(discovery_cv); 55 65 66 static void chardev_flush(void) 67 { 68 size_t nwr; 69 70 if (chardev_bused == 0) 71 return; 72 73 chardev_write(chardev, chardev_buf, chardev_bused, &nwr); 74 /* XXX Handle error */ 75 76 chardev_bused = 0; 77 } 78 56 79 static void chardev_putchar(wchar_t ch) 57 80 { 58 uint8_t byte = (uint8_t) ch; 59 char_dev_write(sess, &byte, 1); 81 if (chardev_bused == chardev_buf_size) 82 chardev_flush(); 83 if (!ascii_check(ch)) 84 ch = '?'; 85 chardev_buf[chardev_bused++] = (uint8_t) ch; 60 86 } 61 87 62 88 static void chardev_control_puts(const char *str) 63 89 { 64 char_dev_write(sess, (void *) str, str_size(str)); 90 const char *p; 91 92 p = str; 93 while (*p != '\0') 94 chardev_putchar(*p++); 95 } 96 97 static bool find_output_dev(service_id_t *svcid) 98 { 99 service_id_t *svc; 100 size_t svcs; 101 int rc; 102 103 rc = loc_category_get_svcs(serial_cat_id, &svc, &svcs); 104 if (rc != EOK) { 105 fibril_mutex_unlock(&discovery_lock); 106 printf("%s: Failed to get services\n", NAME); 107 return false; 108 } 109 110 for (size_t i = 0; i < svcs; i++) { 111 char *name; 112 113 rc = loc_service_get_name(svc[i], &name); 114 if (rc != EOK) 115 continue; 116 117 if (!str_cmp(console, name)) { 118 /* 119 * This is the serial console service that the user 120 * wanted to use. 121 */ 122 *svcid = svc[i]; 123 free(svc); 124 return true; 125 } 126 127 free(name); 128 } 129 130 free(svc); 131 132 /* Look for any service in the 'console' category */ 133 134 rc = loc_category_get_svcs(console_cat_id, &svc, &svcs); 135 if (rc != EOK) { 136 fibril_mutex_unlock(&discovery_lock); 137 printf("%s: Failed to get services\n", NAME); 138 return false; 139 } 140 141 if (svcs > 0) { 142 *svcid = svc[0]; 143 free(svc); 144 return true; 145 } 146 147 free(svc); 148 return false; 65 149 } 66 150 … … 74 158 { 75 159 int rc; 160 bool found; 161 service_id_t sid; 76 162 77 163 fibril_mutex_lock(&discovery_lock); … … 82 168 } 83 169 84 service_id_t *svc; 85 size_t svcs; 86 rc = loc_category_get_svcs(serial_cat_id, &svc, &svcs); 87 if (rc != EOK) { 88 fibril_mutex_unlock(&discovery_lock); 89 printf("%s: Failed to get services\n", NAME); 90 return; 91 } 92 93 service_id_t sid; 94 bool found = false; 95 96 for (size_t i = 0; i < svcs && !found; i++) { 97 char *name; 98 99 rc = loc_service_get_name(svc[i], &name); 100 if (rc != EOK) 101 continue; 102 103 if (!str_cmp(console, name)) { 104 /* 105 * This is the serial console service that the user 106 * wanted to use. 107 */ 108 found = true; 109 sid = svc[i]; 110 } 111 112 free(name); 113 } 114 115 free(svc); 116 170 found = find_output_dev(&sid); 117 171 if (!found) { 118 172 fibril_mutex_unlock(&discovery_lock); 119 173 return; 120 174 } 175 176 printf("%s: Connecting service %zu\n", NAME, sid); 177 char *name; 178 rc = loc_service_get_name(sid, &name); 179 if (rc != EOK) { 180 fibril_mutex_unlock(&discovery_lock); 181 return; 182 } 183 printf("%s: Service name is %s\n", NAME, name); 184 free(name); 121 185 122 186 sess = loc_service_connect(sid, INTERFACE_DDF, IPC_FLAG_BLOCKING); … … 126 190 return; 127 191 } 128 serial_init(chardev_putchar, chardev_control_puts); 192 193 rc = chardev_open(sess, &chardev); 194 if (rc != EOK) { 195 fibril_mutex_unlock(&discovery_lock); 196 printf("%s: Failed opening character device\n", NAME); 197 return; 198 } 199 200 serial_init(chardev_putchar, chardev_control_puts, chardev_flush); 129 201 130 202 discovery_finished = true; … … 135 207 int chardev_init(void) 136 208 { 137 console = config_get_value("console"); 138 if (!console) { 139 /* 140 * The system is not configured to use serial console. 141 */ 209 if (!config_key_exists("console")) { 210 console = NULL; 211 #ifdef MACHINE_ski 212 /* OK */ 213 #elif defined(UARCH_sparc64) && defined(PROCESSOR_sun4v) 214 /* OK */ 215 #elif defined(MACHINE_msim) 216 /* OK */ 217 #else 142 218 return EOK; 219 #endif 220 } else { 221 console = config_get_value("console"); 222 if (!console) 223 return EOK; 143 224 } 144 225 … … 149 230 } 150 231 232 rc = loc_category_get_id("console", &console_cat_id, IPC_FLAG_BLOCKING); 233 if (rc != EOK) { 234 printf("%s: Failed to get \"console\" category ID.\n", NAME); 235 return rc; 236 } 237 151 238 rc = loc_register_cat_change_cb(check_for_dev); 152 239 if (rc != EOK) { … … 155 242 return rc; 156 243 } 244 245 check_for_dev(); 157 246 158 247 fibril_mutex_lock(&discovery_lock);
Note:
See TracChangeset
for help on using the changeset viewer.
