📄 pciio.c
字号:
}/****** Generic pci slot information interfaces ******/pciio_info_tpciio_info_chk(devfs_handle_t pciio){ arbitrary_info_t ainfo = 0; hwgraph_info_get_LBL(pciio, INFO_LBL_PCIIO, &ainfo); return (pciio_info_t) ainfo;}pciio_info_tpciio_info_get(devfs_handle_t pciio){ pciio_info_t pciio_info; pciio_info = (pciio_info_t) hwgraph_fastinfo_get(pciio);#ifdef DEBUG_PCIIO { int pos; char dname[256]; pos = devfs_generate_path(pciio, dname, 256); printk("%s : path= %s\n", __FUNCTION__, &dname[pos]); }#endif /* DEBUG_PCIIO */ if ((pciio_info != NULL) && (pciio_info->c_fingerprint != pciio_info_fingerprint) && (pciio_info->c_fingerprint != NULL)) { return((pciio_info_t)-1); /* Should panic .. */ } return pciio_info;}voidpciio_info_set(devfs_handle_t pciio, pciio_info_t pciio_info){ if (pciio_info != NULL) pciio_info->c_fingerprint = pciio_info_fingerprint; hwgraph_fastinfo_set(pciio, (arbitrary_info_t) pciio_info); /* Also, mark this vertex as a PCI slot * and use the pciio_info, so pciio_info_chk * can work (and be fairly efficient). */ hwgraph_info_add_LBL(pciio, INFO_LBL_PCIIO, (arbitrary_info_t) pciio_info);}devfs_handle_tpciio_info_dev_get(pciio_info_t pciio_info){ return (pciio_info->c_vertex);}pciio_slot_tpciio_info_slot_get(pciio_info_t pciio_info){ return (pciio_info->c_slot);}pciio_function_tpciio_info_function_get(pciio_info_t pciio_info){ return (pciio_info->c_func);}pciio_vendor_id_tpciio_info_vendor_id_get(pciio_info_t pciio_info){ return (pciio_info->c_vendor);}pciio_device_id_tpciio_info_device_id_get(pciio_info_t pciio_info){ return (pciio_info->c_device);}devfs_handle_tpciio_info_master_get(pciio_info_t pciio_info){ return (pciio_info->c_master);}arbitrary_info_tpciio_info_mfast_get(pciio_info_t pciio_info){ return (pciio_info->c_mfast);}pciio_provider_t *pciio_info_pops_get(pciio_info_t pciio_info){ return (pciio_info->c_pops);}error_handler_f *pciio_info_efunc_get(pciio_info_t pciio_info){ return (pciio_info->c_efunc);}error_handler_arg_t *pciio_info_einfo_get(pciio_info_t pciio_info){ return (pciio_info->c_einfo);}pciio_space_tpciio_info_bar_space_get(pciio_info_t info, int win){ return info->c_window[win].w_space;}iopaddr_tpciio_info_bar_base_get(pciio_info_t info, int win){ return info->c_window[win].w_base;}size_tpciio_info_bar_size_get(pciio_info_t info, int win){ return info->c_window[win].w_size;}iopaddr_tpciio_info_rom_base_get(pciio_info_t info){ return info->c_rbase;}size_tpciio_info_rom_size_get(pciio_info_t info){ return info->c_rsize;}/* ===================================================================== * GENERIC PCI INITIALIZATION FUNCTIONS *//* * pciioinit: called once during device driver * initializtion if this driver is configured into * the system. */voidpciio_init(void){ cdl_p cp;#if DEBUG && ATTACH_DEBUG printf("pciio_init\n");#endif /* Allocate the registry. * We might already have one. * If we don't, go get one. * MPness: someone might have * set one up for us while we * were not looking; use an atomic * compare-and-swap to commit to * using the new registry if and * only if nobody else did first. * If someone did get there first, * toss the one we allocated back * into the pool. */ if (pciio_registry == NULL) { cp = cdl_new(EDGE_LBL_PCI, "vendor", "device"); if (!compare_and_swap_ptr((void **) &pciio_registry, NULL, (void *) cp)) { cdl_del(cp); } } ASSERT(pciio_registry != NULL);}/* * pciioattach: called for each vertex in the graph * that is a PCI provider. *//*ARGSUSED */intpciio_attach(devfs_handle_t pciio){#if DEBUG && ATTACH_DEBUG#if defined(SUPPORT_PRINTING_V_FORMAT) printk("%v: pciio_attach\n", pciio);#else printk("0x%x: pciio_attach\n", pciio);#endif#endif return 0;}/* * Associate a set of pciio_provider functions with a vertex. */voidpciio_provider_register(devfs_handle_t provider, pciio_provider_t *pciio_fns){ hwgraph_info_add_LBL(provider, INFO_LBL_PFUNCS, (arbitrary_info_t) pciio_fns);}/* * Disassociate a set of pciio_provider functions with a vertex. */voidpciio_provider_unregister(devfs_handle_t provider){ arbitrary_info_t ainfo; hwgraph_info_remove_LBL(provider, INFO_LBL_PFUNCS, (long *) &ainfo);}/* * Obtain a pointer to the pciio_provider functions for a specified Crosstalk * provider. */pciio_provider_t *pciio_provider_fns_get(devfs_handle_t provider){ arbitrary_info_t ainfo = 0; (void) hwgraph_info_get_LBL(provider, INFO_LBL_PFUNCS, &ainfo); return (pciio_provider_t *) ainfo;}/*ARGSUSED4 */intpciio_driver_register( pciio_vendor_id_t vendor_id, pciio_device_id_t device_id, char *driver_prefix, unsigned flags){ /* a driver's init routine might call * pciio_driver_register before the * system calls pciio_init; so we * make the init call ourselves here. */ if (pciio_registry == NULL) pciio_init(); return cdl_add_driver(pciio_registry, vendor_id, device_id, driver_prefix, flags, NULL);}/* * Remove an initialization function. */voidpciio_driver_unregister( char *driver_prefix){ /* before a driver calls unregister, * it must have called register; so * we can assume we have a registry here. */ ASSERT(pciio_registry != NULL); cdl_del_driver(pciio_registry, driver_prefix, NULL);}/* * Set the slot status for a device supported by the * driver being registered. */voidpciio_driver_reg_callback( devfs_handle_t pconn_vhdl, int key1, int key2, int error){}/* * Set the slot status for a device supported by the * driver being unregistered. */voidpciio_driver_unreg_callback( devfs_handle_t pconn_vhdl, int key1, int key2, int error){}/* * Call some function with each vertex that * might be one of this driver's attach points. */voidpciio_iterate(char *driver_prefix, pciio_iter_f * func){ /* a driver's init routine might call * pciio_iterate before the * system calls pciio_init; so we * make the init call ourselves here. */ if (pciio_registry == NULL) pciio_init(); ASSERT(pciio_registry != NULL); cdl_iterate(pciio_registry, driver_prefix, (cdl_iter_f *) func);}devfs_handle_tpciio_device_register( devfs_handle_t connectpt, /* vertex for /hw/.../pciio/%d */ devfs_handle_t master, /* card's master ASIC (PCI provider) */ pciio_slot_t slot, /* card's slot */ pciio_function_t func, /* card's func */ pciio_vendor_id_t vendor_id, pciio_device_id_t device_id){ return pciio_device_info_register (connectpt, pciio_device_info_new (NULL, master, slot, func, vendor_id, device_id));}voidpciio_device_unregister(devfs_handle_t pconn){ DEV_FUNC(pconn,device_unregister)(pconn);}pciio_info_tpciio_device_info_new( pciio_info_t pciio_info, devfs_handle_t master, pciio_slot_t slot, pciio_function_t func, pciio_vendor_id_t vendor_id, pciio_device_id_t device_id){ if (!pciio_info) GET_NEW(pciio_info); ASSERT(pciio_info != NULL); pciio_info->c_slot = slot; pciio_info->c_func = func; pciio_info->c_vendor = vendor_id; pciio_info->c_device = device_id; pciio_info->c_master = master; pciio_info->c_mfast = hwgraph_fastinfo_get(master); pciio_info->c_pops = pciio_provider_fns_get(master); pciio_info->c_efunc = 0; pciio_info->c_einfo = 0; return pciio_info;}voidpciio_device_info_free(pciio_info_t pciio_info){ /* NOTE : pciio_info is a structure within the pcibr_info * and not a pointer to memory allocated on the heap !! */ BZERO((char *)pciio_info,sizeof(pciio_info));}devfs_handle_tpciio_device_info_register( devfs_handle_t connectpt, /* vertex at center of bus */ pciio_info_t pciio_info) /* details about the connectpt */{ char name[32]; devfs_handle_t pconn; int device_master_set(devfs_handle_t, devfs_handle_t); pciio_slot_func_to_name(name, pciio_info->c_slot, pciio_info->c_func); if (GRAPH_SUCCESS != hwgraph_path_add(connectpt, name, &pconn)) return pconn; pciio_info->c_vertex = pconn; pciio_info_set(pconn, pciio_info);#ifdef DEBUG_PCIIO { int pos; char dname[256]; pos = devfs_generate_path(pconn, dname, 256); printk("%s : pconn path= %s \n", __FUNCTION__, &dname[pos]); }#endif /* DEBUG_PCIIO */ /* * create link to our pci provider */ device_master_set(pconn, pciio_info->c_master);#if USRPCI /* * Call into usrpci provider to let it initialize for * the given slot. */ if (pciio_info->c_slot != PCIIO_SLOT_NONE) usrpci_device_register(pconn, pciio_info->c_master, pciio_info->c_slot);#endif return pconn;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -