Changes in uspace/srv/hid/output/port/chardev.c [bbc6277:8d2dd7f2] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/output/port/chardev.c
rbbc6277 r8d2dd7f2 1 1 /* 2 2 * Copyright (c) 2016 Jakub Jermar 3 * Copyright (c) 2017 Jiri Svoboda4 3 * All rights reserved. 5 4 * … … 31 30 */ 32 31 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>39 32 #include <stddef.h> 40 33 #include <stdint.h> 34 #include <char_dev_iface.h> 41 35 #include <stdio.h> 42 36 #include <stdlib.h> 37 #include <async.h> 38 #include <fibril_synch.h> 39 #include <loc.h> 40 #include <errno.h> 43 41 #include <str.h> 42 #include <config.h> 44 43 #include "../ctl/serial.h" 45 44 #include "../output.h" 46 45 #include "chardev.h" 47 46 48 enum {49 chardev_buf_size = 409650 };51 52 47 static char *console; 53 48 54 49 static async_sess_t *sess; 55 static chardev_t *chardev;56 50 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;61 51 62 52 static FIBRIL_MUTEX_INITIALIZE(discovery_lock); … … 64 54 static FIBRIL_CONDVAR_INITIALIZE(discovery_cv); 65 55 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 79 56 static void chardev_putchar(wchar_t ch) 80 57 { 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; 58 uint8_t byte = (uint8_t) ch; 59 char_dev_write(sess, &byte, 1); 86 60 } 87 61 88 62 static void chardev_control_puts(const char *str) 89 63 { 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; 64 char_dev_write(sess, (void *) str, str_size(str)); 149 65 } 150 66 … … 158 74 { 159 75 int rc; 160 bool found;161 service_id_t sid;162 76 163 77 fibril_mutex_lock(&discovery_lock); … … 168 82 } 169 83 170 found = find_output_dev(&sid); 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 171 117 if (!found) { 172 118 fibril_mutex_unlock(&discovery_lock); 173 119 return; 174 120 } 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);185 121 186 122 sess = loc_service_connect(sid, INTERFACE_DDF, IPC_FLAG_BLOCKING); … … 190 126 return; 191 127 } 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); 128 serial_init(chardev_putchar, chardev_control_puts); 201 129 202 130 discovery_finished = true; … … 207 135 int chardev_init(void) 208 136 { 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 137 console = config_get_value("console"); 138 if (!console) { 139 /* 140 * The system is not configured to use serial console. 141 */ 218 142 return EOK; 219 #endif220 } else {221 console = config_get_value("console");222 if (!console)223 return EOK;224 143 } 225 144 … … 227 146 if (rc != EOK) { 228 147 printf("%s: Failed to get \"serial\" category ID.\n", NAME); 229 return rc;230 }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 148 return rc; 236 149 } … … 242 155 return rc; 243 156 } 244 245 check_for_dev();246 157 247 158 fibril_mutex_lock(&discovery_lock);
Note:
See TracChangeset
for help on using the changeset viewer.