📄 inventory.c
字号:
/* Copy information into the firmware independent pmem_ranges * array, skipping types we don't care about. Notice we said * "may" above. We'll use all the entries that were returned. */ npmem_ranges = 0; mtbl_ptr = mem_table; pmem_ptr = pmem_ranges; /* Global firmware independent table */ for (i = 0; i < entries; i++,mtbl_ptr++) { if ( (mtbl_ptr->entry_type != PAT_MEMORY_DESCRIPTOR) || (mtbl_ptr->memory_type != PAT_MEMTYPE_MEMORY) || (mtbl_ptr->pages == 0) || ( (mtbl_ptr->memory_usage != PAT_MEMUSE_GENERAL) && (mtbl_ptr->memory_usage != PAT_MEMUSE_GI) && (mtbl_ptr->memory_usage != PAT_MEMUSE_GNI) ) ) { continue; } if (npmem_ranges == MAX_PHYSMEM_RANGES) { printk(KERN_WARNING "This Machine has more memory ranges than we support!\n"); printk(KERN_WARNING "Some memory will not be used!\n"); break; } set_pmem_entry(pmem_ptr++,mtbl_ptr->paddr,mtbl_ptr->pages); npmem_ranges++; }}static int __init pat_inventory(void){ int status; ulong mod_index = 0; struct pdc_pat_cell_num cell_info; /* ** Note: Prelude (and it's successors: Lclass, A400/500) only ** implement PDC_PAT_CELL sub-options 0 and 2. */ status = pdc_pat_cell_get_number(&cell_info); if (status != PDC_OK) { return 0; }#ifdef DEBUG_PAT printk(KERN_DEBUG "CELL_GET_NUMBER: 0x%lx 0x%lx\n", cell_info.cell_num, cell_info.cell_loc);#endif while (PDC_OK == pat_query_module(cell_info.cell_loc, mod_index)) { mod_index++; } return mod_index;}/* We only look for extended memory ranges on a 64 bit capable box */static void __init sprockets_memconfig(void){ struct pdc_memory_table_raddr r_addr; struct pdc_memory_table mem_table[MAX_PHYSMEM_RANGES]; struct pdc_memory_table *mtbl_ptr; physmem_range_t *pmem_ptr; long status; int entries; int i; status = pdc_mem_mem_table(&r_addr,mem_table, (unsigned long)MAX_PHYSMEM_RANGES); if (status != PDC_OK) { /* The above pdc call only works on boxes with sprockets * firmware (newer B,C,J class). Other non PAT PDC machines * do support more than 3.75 Gb of memory, but we don't * support them yet. */ pagezero_memconfig(); return; } if (r_addr.entries_total > MAX_PHYSMEM_RANGES) { printk(KERN_WARNING "This Machine has more memory ranges than we support!\n"); printk(KERN_WARNING "Some memory will not be used!\n"); } entries = (int)r_addr.entries_returned; npmem_ranges = 0; mtbl_ptr = mem_table; pmem_ptr = pmem_ranges; /* Global firmware independent table */ for (i = 0; i < entries; i++,mtbl_ptr++) { set_pmem_entry(pmem_ptr++,mtbl_ptr->paddr,mtbl_ptr->pages); npmem_ranges++; }}#else /* !__LP64__ */#define pat_inventory() do { } while (0)#define pat_memconfig() do { } while (0)#define sprockets_memconfig() pagezero_memconfig()#endif /* !__LP64__ */#ifndef CONFIG_PA20/* Code to support Snake machines (7[2350], 7[235]5, 715/Scorpio) */static struct parisc_device * __initlegacy_create_device(struct pdc_memory_map *r_addr, struct pdc_module_path *module_path){ struct parisc_device *dev; int status = pdc_mem_map_hpa(r_addr, module_path); if (status != PDC_OK) return NULL; dev = alloc_pa_dev(r_addr->hpa, &module_path->path); if (dev == NULL) return NULL; register_parisc_device(dev); return dev;}/** * snake_inventory * * Before PDC_SYSTEM_MAP was invented, the PDC_MEM_MAP call was used. * To use it, we initialise the mod_path.bc to 0xff and try all values of * mod to get the HPA for the top-level devices. Bus adapters may have * sub-devices which are discovered by setting bc[5] to 0 and bc[4] to the * module, then trying all possible functions. */static void __init snake_inventory(void){ int mod; for (mod = 0; mod < 16; mod++) { struct parisc_device *dev; struct pdc_module_path module_path; struct pdc_memory_map r_addr; unsigned int func; memset(module_path.path.bc, 0xff, 6); module_path.path.mod = mod; dev = legacy_create_device(&r_addr, &module_path); if ((!dev) || (dev->id.hw_type != HPHW_BA)) continue; memset(module_path.path.bc, 0xff, 4); module_path.path.bc[4] = mod; for (func = 0; func < 16; func++) { module_path.path.bc[5] = 0; module_path.path.mod = func; legacy_create_device(&r_addr, &module_path); } }}#else /* CONFIG_PA20 */#define snake_inventory() do { } while (0)#endif /* CONFIG_PA20 *//* Common 32/64 bit based code goes here *//** * add_system_map_addresses - Add additional addresses to the parisc device. * @dev: The parisc device. * @num_addrs: Then number of addresses to add; * @module_instance: The system_map module instance. * * This function adds any additional addresses reported by the system_map * firmware to the parisc device. */static void __initadd_system_map_addresses(struct parisc_device *dev, int num_addrs, int module_instance){ int i; long status; struct pdc_system_map_addr_info addr_result; dev->addr = kmalloc(num_addrs * sizeof(unsigned long), GFP_KERNEL); if(!dev->addr) { printk(KERN_ERR "%s %s(): memory allocation failure\n", __FILE__, __FUNCTION__); return; } for(i = 1; i <= num_addrs; ++i) { status = pdc_system_map_find_addrs(&addr_result, module_instance, i); if(PDC_OK == status) { dev->addr[dev->num_addrs] = (unsigned long)addr_result.mod_addr; dev->num_addrs++; } else { printk(KERN_WARNING "Bad PDC_FIND_ADDRESS status return (%ld) for index %d\n", status, i); } }}/** * do_system_map_inventory - Retrieve firmware devices via SYSTEM_MAP. * * This function attempts to retrieve and register all the devices firmware * knows about via the SYSTEM_MAP PDC call. */static void __init system_map_inventory(void){ int i; long status = PDC_OK; /* * first stop the usb controller, otherwise the machine * might crash during iommu setup */ pdc_suspend_usb(); for (i = 0; status != PDC_BAD_PROC && status != PDC_NE_MOD; i++) { struct parisc_device *dev; struct pdc_system_map_mod_info module_result; struct pdc_module_path module_path; status = pdc_system_map_find_mods(&module_result, &module_path, i); if (status != PDC_OK) continue; dev = alloc_pa_dev(module_result.mod_addr, &module_path.path); if (!dev) continue; register_parisc_device(dev); /* if available, get the additional addresses for a module */ if (!module_result.add_addrs) continue; add_system_map_addresses(dev, module_result.add_addrs, i); } walk_central_bus(); return;}void __init do_memory_inventory(void){ switch (pdc_type) { case PDC_TYPE_PAT: pat_memconfig(); break; case PDC_TYPE_SYSTEM_MAP: sprockets_memconfig(); break; case PDC_TYPE_SNAKE: pagezero_memconfig(); return; default: panic("Unknown PDC type!\n"); } if (npmem_ranges == 0 || pmem_ranges[0].start_pfn != 0) { printk(KERN_WARNING "Bad memory configuration returned!\n"); printk(KERN_WARNING "Some memory may not be used!\n"); pagezero_memconfig(); }}void __init do_device_inventory(void){ printk(KERN_INFO "Searching for devices...\n"); switch (pdc_type) { case PDC_TYPE_PAT: pat_inventory(); break; case PDC_TYPE_SYSTEM_MAP: system_map_inventory(); break; case PDC_TYPE_SNAKE: snake_inventory(); break; default: panic("Unknown PDC type!\n"); } printk(KERN_INFO "Found devices:\n"); print_parisc_devices();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -