📄 devsupport.c
字号:
char *device_admin_info_get(devfs_handle_t dev_vhdl, char *info_lbl){#ifdef notyet char *info = 0; /* return value need not be GRAPH_SUCCESS as the labelled * info may not be present */ (void)hwgraph_info_get_LBL(dev_vhdl,info_lbl, (arbitrary_info_t *)&info); return info;#else FIXME("device_admin_info_get"); return(NULL);#endif}/* * set labelled info associated with a device. * called by hwgraph infrastructure . may also be called * by device drivers etc. */intdevice_admin_info_set(devfs_handle_t dev_vhdl, char *dev_info_lbl, char *dev_info_val){#ifdef notyet graph_error_t rv; arbitrary_info_t old_info; /* Handle the labelled info * intr_target * sw_level * in a special way. These are part of device_desc_t * Right now this is the only case where we have * a set of related device_admin attributes which * are grouped together. * In case there is a need for another set we need to * take a more generic approach to solving this. * Basically a registry should be implemented. This * registry is initialized with the callbacks for the * attributes which need to handled in a special way * For example: * Consider * device_desc * intr_target * intr_swlevel * register "do_intr_target" for intr_target * register "do_intr_swlevel" for intr_swlevel. * When the device_admin interface layer gets an <attr,val> pair * it looks in the registry to see if there is a function registered to * handle "attr. If not follow the default path of setting the <attr,val> * as labelled information hanging off the vertex. * In the above example: * "do_intr_target" does what is being done below for the ADMIN_LBL_INTR_TARGET * case */ if (!strcmp(dev_info_lbl,ADMIN_LBL_INTR_TARGET) || !strcmp(dev_info_lbl,ADMIN_LBL_INTR_SWLEVEL)) { device_desc_t device_desc; /* Check if there is a default device descriptor * information for this vertex. If not dup one . */ if (!(device_desc = device_desc_default_get(dev_vhdl))) { device_desc = device_desc_dup(dev_vhdl); device_desc_default_set(dev_vhdl,device_desc); } if (!strcmp(dev_info_lbl,ADMIN_LBL_INTR_TARGET)) { /* Check if a target cpu has been specified * for this device by a device administration * directive */#ifdef DEBUG printf(ADMIN_LBL_INTR_TARGET " dev = 0x%x " "dev_admin_info = %s" " target = 0x%x\n", dev_vhdl, dev_info_lbl, hwgraph_path_to_vertex(dev_info_val));#endif device_desc->intr_target = hwgraph_path_to_vertex(dev_info_val); } else if (!strcmp(dev_info_lbl,ADMIN_LBL_INTR_SWLEVEL)) { /* Check if the ithread priority level has been * specified for this device by a device administration * directive */#ifdef DEBUG printf(ADMIN_LBL_INTR_SWLEVEL " dev = 0x%x " "dev_admin_info = %s" " sw level = 0x%x\n", dev_vhdl, dev_info_lbl, atoi(dev_info_val));#endif device_desc->intr_swlevel = atoi(dev_info_val); } } if (!dev_info_val) rv = hwgraph_info_remove_LBL(dev_vhdl, dev_info_lbl, &old_info); else { rv = hwgraph_info_add_LBL(dev_vhdl, dev_info_lbl, (arbitrary_info_t)dev_info_val); if (rv == GRAPH_DUP) { rv = hwgraph_info_replace_LBL(dev_vhdl, dev_info_lbl, (arbitrary_info_t)dev_info_val, &old_info); } } ASSERT(rv == GRAPH_SUCCESS);#endif FIXME("device_admin_info_set"); return 0;}/* * return labelled info associated with a device driver * called by kernel code including device drivers */char *device_driver_admin_info_get(char *driver_prefix, char *driver_info_lbl){#ifdef notyet device_driver_t driver; driver = device_driver_get(driver_prefix); return (dev_admin_registry_find(&driver->dd_dev_admin_registry, driver_info_lbl));#else FIXME("device_driver_admin_info_get"); return(NULL);#endif}/* * set labelled info associated with a device driver. * called by hwgraph infrastructure . may also be called * from drivers etc. */intdevice_driver_admin_info_set(char *driver_prefix, char *driver_info_lbl, char *driver_info_val){#ifdef notyet device_driver_t driver; driver = device_driver_get(driver_prefix); dev_admin_registry_add(&driver->dd_dev_admin_registry, driver_info_lbl, driver_info_val);#endif FIXME("device_driver_admin_info_set"); return 0;}/*================== device / driver admin support routines================*//* static tables created by lboot */extern dev_admin_info_t dev_admin_table[];extern dev_admin_info_t drv_admin_table[];extern int dev_admin_table_size;extern int drv_admin_table_size;/* Extend the device admin table to allow the kernel startup code to * provide some device specific administrative hints */#define ADMIN_TABLE_CHUNK 100static dev_admin_info_t extended_dev_admin_table[ADMIN_TABLE_CHUNK]; static int extended_dev_admin_table_size = 0;static mrlock_t extended_dev_admin_table_lock;/* Initialize the extended device admin table */voiddevice_admin_table_init(void){#ifdef notyet extended_dev_admin_table_size = 0; mrinit(&extended_dev_admin_table_lock, "extended_dev_admin_table_lock");#endif FIXME("device_admin_table_init");}/* Add <device-name , parameter-name , parameter-value> triple to * the extended device administration info table. This is helpful * for kernel startup code to put some hints before the hwgraph * is setup */voiddevice_admin_table_update(char *name,char *label,char *value){#ifdef notyet dev_admin_info_t *p; mrupdate(&extended_dev_admin_table_lock); /* Safety check that we haven't exceeded array limits */ ASSERT(extended_dev_admin_table_size < ADMIN_TABLE_CHUNK); if (extended_dev_admin_table_size == ADMIN_TABLE_CHUNK) goto out; /* Get the pointer to the entry in the table where we are * going to put the new information */ p = &extended_dev_admin_table[extended_dev_admin_table_size++]; /* Allocate memory for the strings and copy them in */ p->dai_name = (char *)kern_calloc(1,strlen(name)+1); strcpy(p->dai_name,name); p->dai_param_name = (char *)kern_calloc(1,strlen(label)+1); strcpy(p->dai_param_name,label); p->dai_param_val = (char *)kern_calloc(1,strlen(value)+1); strcpy(p->dai_param_val,value);out: mrunlock(&extended_dev_admin_table_lock);#endif FIXME("device_admin_table_update");}/* Extend the device driver admin table to allow the kernel startup code to * provide some device driver specific administrative hints */static dev_admin_info_t extended_drv_admin_table[ADMIN_TABLE_CHUNK]; static int extended_drv_admin_table_size = 0;mrlock_t extended_drv_admin_table_lock;/* Initialize the extended device driver admin table */voiddevice_driver_admin_table_init(void){#ifdef notyet extended_drv_admin_table_size = 0; mrinit(&extended_drv_admin_table_lock, "extended_drv_admin_table_lock");#endif FIXME("device_driver_admin_table_init");}/* Add <device-driver prefix , parameter-name , parameter-value> triple to * the extended device administration info table. This is helpful * for kernel startup code to put some hints before the hwgraph * is setup */voiddevice_driver_admin_table_update(char *name,char *label,char *value){#ifdef notyet dev_admin_info_t *p; mrupdate(&extended_dev_admin_table_lock); /* Safety check that we haven't exceeded array limits */ ASSERT(extended_drv_admin_table_size < ADMIN_TABLE_CHUNK); if (extended_drv_admin_table_size == ADMIN_TABLE_CHUNK) goto out; /* Get the pointer to the entry in the table where we are * going to put the new information */ p = &extended_drv_admin_table[extended_drv_admin_table_size++]; /* Allocate memory for the strings and copy them in */ p->dai_name = (char *)kern_calloc(1,strlen(name)+1); strcpy(p->dai_name,name); p->dai_param_name = (char *)kern_calloc(1,strlen(label)+1); strcpy(p->dai_param_name,label); p->dai_param_val = (char *)kern_calloc(1,strlen(value)+1); strcpy(p->dai_param_val,value);out: mrunlock(&extended_drv_admin_table_lock);#endif FIXME("device_driver_admin_table_update");}/* * keeps on adding the labelled info for each new (lbl,value) pair * that it finds in the static dev admin table ( created by lboot) * and the extended dev admin table ( created if at all by the kernel startup * code) corresponding to a device in the hardware graph. */voiddevice_admin_info_update(devfs_handle_t dev_vhdl){#ifdef notyet int i = 0; dev_admin_info_t *scan; devfs_handle_t scan_vhdl; /* Check the static device administration info table */ scan = dev_admin_table; while (i < dev_admin_table_size) { scan_vhdl = hwgraph_path_to_dev(scan->dai_name); if (scan_vhdl == dev_vhdl) { device_admin_info_set(dev_vhdl, scan->dai_param_name, scan->dai_param_val); } if (scan_vhdl != NODEV) hwgraph_vertex_unref(scan_vhdl); scan++;i++; } i = 0; /* Check the extended device administration info table */ scan = extended_dev_admin_table; while (i < extended_dev_admin_table_size) { scan_vhdl = hwgraph_path_to_dev(scan->dai_name); if (scan_vhdl == dev_vhdl) { device_admin_info_set(dev_vhdl, scan->dai_param_name, scan->dai_param_val); } if (scan_vhdl != NODEV) hwgraph_vertex_unref(scan_vhdl); scan++;i++; }#endif FIXME("device_admin_info_update");}/* looks up the static drv admin table ( created by the lboot) and the extended * drv admin table (created if at all by the kernel startup code) * for this driver specific administration info and adds it to the admin info * associated with this device driver's object */voiddevice_driver_admin_info_update(device_driver_t driver){#ifdef notyet int i = 0; dev_admin_info_t *scan; /* Check the static device driver administration info table */ scan = drv_admin_table; while (i < drv_admin_table_size) { if (strcmp(scan->dai_name,driver->dd_prefix) == 0) { dev_admin_registry_add(&driver->dd_dev_admin_registry, scan->dai_param_name, scan->dai_param_val); } scan++;i++; } i = 0; /* Check the extended device driver administration info table */ scan = extended_drv_admin_table; while (i < extended_drv_admin_table_size) { if (strcmp(scan->dai_name,driver->dd_prefix) == 0) { dev_admin_registry_add(&driver->dd_dev_admin_registry, scan->dai_param_name, scan->dai_param_val); } scan++;i++; }#endif FIXME("device_driver_admin_info_update");}/* =====Device Driver Support===== *//*** Generic device driver support routines for use by kernel modules that** deal with device drivers (but NOT for use by the drivers themselves).** EVERY registered driver currently in the system -- static or loadable --** has an entry in the device_driver_hash table. A pointer to such an entry** serves as a generic device driver handle.*/#define DEVICE_DRIVER_HASH_SIZE 32#ifdef notyetlock_t device_driver_lock[DEVICE_DRIVER_HASH_SIZE];device_driver_t device_driver_hash[DEVICE_DRIVER_HASH_SIZE];static struct string_table driver_prefix_string_table;#endif/*** Initialize device driver infrastructure.*/voiddevice_driver_init(void){#ifdef notyet int i; extern void alenlist_init(void); extern void hwgraph_init(void); extern void device_desc_init(void); ASSERT(DEVICE_DRIVER_NONE == NULL); alenlist_init(); hwgraph_init(); device_desc_init(); string_table_init(&driver_prefix_string_table); for (i=0; i<DEVICE_DRIVER_HASH_SIZE; i++) { spinlock_init(&device_driver_lock[i], "devdrv"); device_driver_hash[i] = NULL; } /* Initialize static drivers from master.c table */ for (i=0; i<static_devsw_count; i++) { device_driver_t driver; static_device_driver_desc_t desc; int pri; desc = &static_device_driver_table[i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -