Changeset 5dc9622 in mainline
- Timestamp:
- 2010-04-18T19:44:17Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5fe1c32
- Parents:
- c1a8ae52
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/arch/amd64/Makefile.inc
rc1a8ae52 r5dc9622 42 42 isa 43 43 44 RD_DRV_CONF = \ 45 isa/isa.dev 46 44 47 MODULES := $(notdir $(COMPONENTS)) 45 48 … … 75 78 cp $(USPACEDIR)/srv/drivers/$$driver/$$driver $(USPACEDIR)/dist/srv/drivers/$$driver/ ; \ 76 79 done 80 for drv_conf in $(RD_DRV_CONF); do \ 81 cp $(USPACEDIR)/srv/drivers/$$drv_conf $(USPACEDIR)/dist/srv/drivers/$$drv_conf ; \ 82 done 77 83 for file in $(RD_APPS) ; do \ 78 84 cp $$file $(USPACEDIR)/dist/app/ ; \ … … 93 99 rm -f $(USPACEDIR)/dist/srv/`basename $$file` ; \ 94 100 done 101 for drv_conf in $(RD_DRV_CONF) ; do \ 102 rm -r $(USPACEDIR)/dist/srv/drivers/$$drv_conf ; \ 103 done 95 104 for driver in $(RD_DRVS) ; do \ 96 105 rm -r $(USPACEDIR)/dist/srv/drivers/$$driver ; \ -
uspace/lib/libc/include/device/hw_res.h
rc1a8ae52 r5dc9622 39 39 #include <bool.h> 40 40 41 // HW resource provider interface 42 43 typedef enum { 44 GET_RESOURCE_LIST = 0, 45 ENABLE_INTERRUPT 46 } hw_res_funcs_t; 47 48 /** HW resource types. */ 49 typedef enum { 50 INTERRUPT, 51 IO_RANGE, 52 MEM_RANGE 53 } hw_res_type_t; 54 55 typedef enum { 56 LITTLE_ENDIAN = 0, 57 BIG_ENDIAN 58 } endianness_t; 59 60 41 61 /** HW resource (e.g. interrupt, memory register, i/o register etc.). */ 42 62 typedef struct hw_resource { … … 74 94 75 95 96 76 97 bool get_hw_resources(int dev_phone, hw_resource_list_t *hw_resources); 77 98 -
uspace/lib/libc/include/ipc/dev_iface.h
rc1a8ae52 r5dc9622 47 47 48 48 49 50 // HW resource provider interface51 52 typedef enum {53 GET_RESOURCE_LIST = 0,54 ENABLE_INTERRUPT55 } hw_res_funcs_t;56 57 /** HW resource types. */58 typedef enum {59 INTERRUPT,60 IO_RANGE,61 MEM_RANGE62 } hw_res_type_t;63 64 typedef enum {65 LITTLE_ENDIAN = 0,66 BIG_ENDIAN67 } endianness_t;68 69 49 #endif -
uspace/srv/drivers/isa/isa.c
rc1a8ae52 r5dc9622 51 51 52 52 #include <driver.h> 53 #include <resource.h> 54 53 55 #include <devman.h> 54 56 #include <ipc/devman.h> 57 #include <device/hw_res.h> 55 58 56 59 #define NAME "isa" 57 60 #define CHILD_DEV_CONF_PATH "/srv/drivers/isa/isa.dev" 61 62 #define ISA_MAX_HW_RES 4 63 64 typedef struct isa_child_data { 65 hw_resource_list_t hw_resources; 66 } isa_child_data_t; 67 68 static hw_resource_list_t * isa_get_child_resources(device_t *dev) 69 { 70 isa_child_data_t *dev_data = (isa_child_data_t *)dev->driver_data; 71 if (NULL == dev_data) { 72 return NULL; 73 } 74 return &dev_data->hw_resources; 75 } 76 77 static bool isa_enable_child_interrupt(device_t *dev) 78 { 79 // TODO 80 81 return false; 82 } 83 84 static resource_iface_t isa_child_res_iface = { 85 &isa_get_child_resources, 86 &isa_enable_child_interrupt 87 }; 88 89 static device_class_t isa_child_class; 58 90 59 91 static bool isa_add_device(device_t *dev); … … 71 103 .driver_ops = &isa_ops 72 104 }; 73 74 typedef struct isa_child_data {75 hw_resource_list_t hw_resources;76 } isa_child_data_t;77 105 78 106 … … 154 182 } 155 183 156 static char * str_get_line(char *str) { 157 return strtok(str, "\n"); 184 static char * str_get_line(char *str, char **next) { 185 char *line = str; 186 while (0 != *str && '\n' != *str) { 187 str++; 188 } 189 190 if (0 != *str) { 191 *next = str + 1; 192 } else { 193 *next = NULL; 194 } 195 196 *str = 0; 197 198 return line; 158 199 } 159 200 … … 180 221 181 222 // alloc output buffer 182 size_t len = str_size(line);183 char *name = malloc( len + 1);223 size_t size = str_size(line) + 1; 224 char *name = malloc(size); 184 225 185 226 if (NULL != name) { 186 227 // copy the result to the output buffer 187 str_cpy(name, len, line);228 str_cpy(name, size, line); 188 229 } 189 230 … … 201 242 202 243 203 void isa_child_set_irq(device_t *dev, int irq) 204 { 205 // TODO 244 static void isa_child_set_irq(device_t *dev, int irq) 245 { 246 isa_child_data_t *data = (isa_child_data_t *)dev->driver_data; 247 248 size_t count = data->hw_resources.count; 249 hw_resource_t *resources = data->hw_resources.resources; 250 251 if (count < ISA_MAX_HW_RES) { 252 resources[count].type = INTERRUPT; 253 resources[count].res.interrupt.irq = irq; 254 255 data->hw_resources.count++; 256 } 257 } 258 259 static void isa_child_set_io_range(device_t *dev, size_t addr, size_t len) 260 { 261 isa_child_data_t *data = (isa_child_data_t *)dev->driver_data; 262 263 size_t count = data->hw_resources.count; 264 hw_resource_t *resources = data->hw_resources.resources; 265 266 if (count < ISA_MAX_HW_RES) { 267 resources[count].type = IO_RANGE; 268 resources[count].res.io_range.address = addr; 269 resources[count].res.io_range.size = len; 270 resources[count].res.io_range.endianness = LITTLE_ENDIAN; 271 data->hw_resources.count++; 272 } 206 273 } 207 274 … … 212 279 213 280 val = skip_spaces(val); 214 irq = strtol(val, &end, 0x10);281 irq = (int)strtol(val, &end, 0x10); 215 282 216 283 if (val != end) { … … 221 288 static void get_dev_io_range(device_t *dev, char *val) 222 289 { 223 // TODO 224 } 225 226 static void get_dev_macth_id(device_t *dev, char *val) 227 { 228 // TODO 290 size_t addr, len; 291 char *end = NULL; 292 293 val = skip_spaces(val); 294 addr = strtol(val, &end, 0x10); 295 296 if (val == end) { 297 return; 298 } 299 300 val = skip_spaces(end); 301 len = strtol(val, &end, 0x10); 302 303 if (val == end) { 304 return; 305 } 306 307 isa_child_set_io_range(dev, addr, len); 308 } 309 310 static void get_match_id(char **id, char *val) 311 { 312 char *end = val; 313 314 while (isspace(*end)) { 315 end++; 316 } 317 *end = 0; 318 319 size_t size = str_size(val) + 1; 320 *id = (char *)malloc(size); 321 str_cpy(*id, size, val); 322 } 323 324 static void get_dev_match_id(device_t *dev, char *val) 325 { 326 char *id = NULL; 327 int score = 0; 328 char *end = NULL; 329 330 val = skip_spaces(val); 331 332 score = (int)strtol(val, &end, 0x10); 333 if (val == end) { 334 return; 335 } 336 337 match_id_t *match_id = create_match_id(); 338 if (NULL == match_id) { 339 return; 340 } 341 342 val = skip_spaces(end); 343 get_match_id(&id, val); 344 if (NULL == id) { 345 delete_match_id(match_id); 346 return; 347 } 348 349 match_id->id = id; 350 match_id->score = score; 351 352 add_match_id(&dev->match_ids, match_id); 229 353 } 230 354 … … 242 366 get_dev_irq(dev, val); 243 367 } else if (NULL != (val = strtok(line, "match"))) { 244 get_dev_ma cth_id(dev, val);368 get_dev_match_id(dev, val); 245 369 } 246 370 } 247 371 372 static void child_alloc_hw_res(device_t *dev) 373 { 374 isa_child_data_t *data = (isa_child_data_t *)dev->driver_data; 375 data->hw_resources.resources = 376 (hw_resource_t *)malloc(sizeof(hw_resource_t) * ISA_MAX_HW_RES); 377 378 } 379 248 380 static char * read_isa_dev_info(char *dev_conf, device_t *parent) 249 381 { 250 382 char *line; 251 bool cont = true;252 383 char *dev_name = NULL; 253 384 254 385 // skip empty lines 255 while (cont) { 256 line = dev_conf; 257 dev_conf = str_get_line(line); 258 259 if (NULL == dev_conf) { 386 while (true) { 387 line = str_get_line(dev_conf, &dev_conf); 388 389 if (NULL == line) { 260 390 // no more lines 261 391 return NULL; … … 264 394 if (!line_empty(line)) { 265 395 break; 266 }267 268 if (NULL == dev_conf) {269 return NULL;270 396 } 271 397 } … … 284 410 dev->name = dev_name; 285 411 412 // allocate buffer for the list of hardware resources of the device 413 child_alloc_hw_res(dev); 414 286 415 // get properties of the device (match ids, irq and io range) 287 cont = true; 288 while (cont) { 289 line = dev_conf; 290 dev_conf = str_get_line(line); 291 cont = line_empty(line); 416 while (true) { 417 line = str_get_line(dev_conf, &dev_conf); 418 419 if (line_empty(line)) { 420 // no more device properties 421 break; 422 } 423 292 424 // get the device's property from the configuration line and store it in the device structure 293 if (cont) {294 get_dev_prop(dev, line);295 }296 }297 298 // TODO class & interfaces !!!425 get_dev_prop(dev, line); 426 } 427 428 // set a class (including the corresponding set of interfaces) to the device 429 dev->class = &isa_child_class; 430 299 431 child_device_register(dev, parent); 300 432 … … 328 460 } 329 461 462 static void isa_init() 463 { 464 isa_child_class.id = 0; // TODO 465 isa_child_class.interfaces[HW_RES_DEV_IFACE] = &isa_child_res_iface; 466 } 467 330 468 int main(int argc, char *argv[]) 331 469 { 332 470 printf(NAME ": HelenOS ISA bus driver\n"); 471 isa_init(); 333 472 return driver_main(&isa_driver); 334 473 }
Note:
See TracChangeset
for help on using the changeset viewer.