inventory.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * inventory.c
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. *
  9. * Copyright (c) 1999 The Puffin Group (David Kennedy and Alex deVries)
  10. * Copyright (c) 2001 Matthew Wilcox for Hewlett-Packard
  11. *
  12. * These are the routines to discover what hardware exists in this box.
  13. * This task is complicated by there being 3 different ways of
  14. * performing an inventory, depending largely on the age of the box.
  15. * The recommended way to do this is to check to see whether the machine
  16. * is a `Snake' first, then try System Map, then try PAT. We try System
  17. * Map before checking for a Snake -- this probably doesn't cause any
  18. * problems, but...
  19. */
  20. #include <linux/types.h>
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/slab.h>
  24. #include <linux/mm.h>
  25. #include <asm/hardware.h>
  26. #include <asm/io.h>
  27. #include <asm/mmzone.h>
  28. #include <asm/pdc.h>
  29. #include <asm/pdcpat.h>
  30. #include <asm/processor.h>
  31. #include <asm/page.h>
  32. #include <asm/parisc-device.h>
  33. /*
  34. ** Debug options
  35. ** DEBUG_PAT Dump details which PDC PAT provides about ranges/devices.
  36. */
  37. #undef DEBUG_PAT
  38. int pdc_type __read_mostly = PDC_TYPE_ILLEGAL;
  39. void __init setup_pdc(void)
  40. {
  41. long status;
  42. unsigned int bus_id;
  43. struct pdc_system_map_mod_info module_result;
  44. struct pdc_module_path module_path;
  45. struct pdc_model model;
  46. #ifdef CONFIG_64BIT
  47. struct pdc_pat_cell_num cell_info;
  48. #endif
  49. /* Determine the pdc "type" used on this machine */
  50. printk(KERN_INFO "Determining PDC firmware type: ");
  51. status = pdc_system_map_find_mods(&module_result, &module_path, 0);
  52. if (status == PDC_OK) {
  53. pdc_type = PDC_TYPE_SYSTEM_MAP;
  54. printk("System Map.\n");
  55. return;
  56. }
  57. /*
  58. * If the machine doesn't support PDC_SYSTEM_MAP then either it
  59. * is a pdc pat box, or it is an older box. All 64 bit capable
  60. * machines are either pdc pat boxes or they support PDC_SYSTEM_MAP.
  61. */
  62. /*
  63. * TODO: We should test for 64 bit capability and give a
  64. * clearer message.
  65. */
  66. #ifdef CONFIG_64BIT
  67. status = pdc_pat_cell_get_number(&cell_info);
  68. if (status == PDC_OK) {
  69. pdc_type = PDC_TYPE_PAT;
  70. printk("64 bit PAT.\n");
  71. return;
  72. }
  73. #endif
  74. /* Check the CPU's bus ID. There's probably a better test. */
  75. status = pdc_model_info(&model);
  76. bus_id = (model.hversion >> (4 + 7)) & 0x1f;
  77. switch (bus_id) {
  78. case 0x4: /* 720, 730, 750, 735, 755 */
  79. case 0x6: /* 705, 710 */
  80. case 0x7: /* 715, 725 */
  81. case 0x8: /* 745, 747, 742 */
  82. case 0xA: /* 712 and similar */
  83. case 0xC: /* 715/64, at least */
  84. pdc_type = PDC_TYPE_SNAKE;
  85. printk("Snake.\n");
  86. return;
  87. default: /* Everything else */
  88. printk("Unsupported.\n");
  89. panic("If this is a 64-bit machine, please try a 64-bit kernel.\n");
  90. }
  91. }
  92. #define PDC_PAGE_ADJ_SHIFT (PAGE_SHIFT - 12) /* pdc pages are always 4k */
  93. static void __init
  94. set_pmem_entry(physmem_range_t *pmem_ptr, unsigned long start,
  95. unsigned long pages4k)
  96. {
  97. /* Rather than aligning and potentially throwing away
  98. * memory, we'll assume that any ranges are already
  99. * nicely aligned with any reasonable page size, and
  100. * panic if they are not (it's more likely that the
  101. * pdc info is bad in this case).
  102. */
  103. if (unlikely( ((start & (PAGE_SIZE - 1)) != 0)
  104. || ((pages4k & ((1UL << PDC_PAGE_ADJ_SHIFT) - 1)) != 0) )) {
  105. panic("Memory range doesn't align with page size!\n");
  106. }
  107. pmem_ptr->start_pfn = (start >> PAGE_SHIFT);
  108. pmem_ptr->pages = (pages4k >> PDC_PAGE_ADJ_SHIFT);
  109. }
  110. static void __init pagezero_memconfig(void)
  111. {
  112. unsigned long npages;
  113. /* Use the 32 bit information from page zero to create a single
  114. * entry in the pmem_ranges[] table.
  115. *
  116. * We currently don't support machines with contiguous memory
  117. * >= 4 Gb, who report that memory using 64 bit only fields
  118. * on page zero. It's not worth doing until it can be tested,
  119. * and it is not clear we can support those machines for other
  120. * reasons.
  121. *
  122. * If that support is done in the future, this is where it
  123. * should be done.
  124. */
  125. npages = (PAGE_ALIGN(PAGE0->imm_max_mem) >> PAGE_SHIFT);
  126. set_pmem_entry(pmem_ranges,0UL,npages);
  127. npmem_ranges = 1;
  128. }
  129. #ifdef CONFIG_64BIT
  130. /* All of the PDC PAT specific code is 64-bit only */
  131. /*
  132. ** The module object is filled via PDC_PAT_CELL[Return Cell Module].
  133. ** If a module is found, register module will get the IODC bytes via
  134. ** pdc_iodc_read() using the PA view of conf_base_addr for the hpa parameter.
  135. **
  136. ** The IO view can be used by PDC_PAT_CELL[Return Cell Module]
  137. ** only for SBAs and LBAs. This view will cause an invalid
  138. ** argument error for all other cell module types.
  139. **
  140. */
  141. static int __init
  142. pat_query_module(ulong pcell_loc, ulong mod_index)
  143. {
  144. pdc_pat_cell_mod_maddr_block_t *pa_pdc_cell;
  145. unsigned long bytecnt;
  146. unsigned long temp; /* 64-bit scratch value */
  147. long status; /* PDC return value status */
  148. struct parisc_device *dev;
  149. pa_pdc_cell = kmalloc(sizeof (*pa_pdc_cell), GFP_KERNEL);
  150. if (!pa_pdc_cell)
  151. panic("couldn't allocate memory for PDC_PAT_CELL!");
  152. /* return cell module (PA or Processor view) */
  153. status = pdc_pat_cell_module(&bytecnt, pcell_loc, mod_index,
  154. PA_VIEW, pa_pdc_cell);
  155. if (status != PDC_OK) {
  156. /* no more cell modules or error */
  157. kfree(pa_pdc_cell);
  158. return status;
  159. }
  160. temp = pa_pdc_cell->cba;
  161. dev = alloc_pa_dev(PAT_GET_CBA(temp), &(pa_pdc_cell->mod_path));
  162. if (!dev) {
  163. kfree(pa_pdc_cell);
  164. return PDC_OK;
  165. }
  166. /* alloc_pa_dev sets dev->hpa */
  167. /*
  168. ** save parameters in the parisc_device
  169. ** (The idea being the device driver will call pdc_pat_cell_module()
  170. ** and store the results in its own data structure.)
  171. */
  172. dev->pcell_loc = pcell_loc;
  173. dev->mod_index = mod_index;
  174. /* save generic info returned from the call */
  175. /* REVISIT: who is the consumer of this? not sure yet... */
  176. dev->mod_info = pa_pdc_cell->mod_info; /* pass to PAT_GET_ENTITY() */
  177. dev->pmod_loc = pa_pdc_cell->mod_location;
  178. register_parisc_device(dev); /* advertise device */
  179. #ifdef DEBUG_PAT
  180. pdc_pat_cell_mod_maddr_block_t io_pdc_cell;
  181. /* dump what we see so far... */
  182. switch (PAT_GET_ENTITY(dev->mod_info)) {
  183. unsigned long i;
  184. case PAT_ENTITY_PROC:
  185. printk(KERN_DEBUG "PAT_ENTITY_PROC: id_eid 0x%lx\n",
  186. pa_pdc_cell->mod[0]);
  187. break;
  188. case PAT_ENTITY_MEM:
  189. printk(KERN_DEBUG
  190. "PAT_ENTITY_MEM: amount 0x%lx min_gni_base 0x%lx min_gni_len 0x%lx\n",
  191. pa_pdc_cell->mod[0], pa_pdc_cell->mod[1],
  192. pa_pdc_cell->mod[2]);
  193. break;
  194. case PAT_ENTITY_CA:
  195. printk(KERN_DEBUG "PAT_ENTITY_CA: %ld\n", pcell_loc);
  196. break;
  197. case PAT_ENTITY_PBC:
  198. printk(KERN_DEBUG "PAT_ENTITY_PBC: ");
  199. goto print_ranges;
  200. case PAT_ENTITY_SBA:
  201. printk(KERN_DEBUG "PAT_ENTITY_SBA: ");
  202. goto print_ranges;
  203. case PAT_ENTITY_LBA:
  204. printk(KERN_DEBUG "PAT_ENTITY_LBA: ");
  205. print_ranges:
  206. pdc_pat_cell_module(&bytecnt, pcell_loc, mod_index,
  207. IO_VIEW, &io_pdc_cell);
  208. printk(KERN_DEBUG "ranges %ld\n", pa_pdc_cell->mod[1]);
  209. for (i = 0; i < pa_pdc_cell->mod[1]; i++) {
  210. printk(KERN_DEBUG
  211. " PA_VIEW %ld: 0x%016lx 0x%016lx 0x%016lx\n",
  212. i, pa_pdc_cell->mod[2 + i * 3], /* type */
  213. pa_pdc_cell->mod[3 + i * 3], /* start */
  214. pa_pdc_cell->mod[4 + i * 3]); /* finish (ie end) */
  215. printk(KERN_DEBUG
  216. " IO_VIEW %ld: 0x%016lx 0x%016lx 0x%016lx\n",
  217. i, io_pdc_cell->mod[2 + i * 3], /* type */
  218. io_pdc_cell->mod[3 + i * 3], /* start */
  219. io_pdc_cell->mod[4 + i * 3]); /* finish (ie end) */
  220. }
  221. printk(KERN_DEBUG "\n");
  222. break;
  223. }
  224. #endif /* DEBUG_PAT */
  225. kfree(pa_pdc_cell);
  226. return PDC_OK;
  227. }
  228. /* pat pdc can return information about a variety of different
  229. * types of memory (e.g. firmware,i/o, etc) but we only care about
  230. * the usable physical ram right now. Since the firmware specific
  231. * information is allocated on the stack, we'll be generous, in
  232. * case there is a lot of other information we don't care about.
  233. */
  234. #define PAT_MAX_RANGES (4 * MAX_PHYSMEM_RANGES)
  235. static void __init pat_memconfig(void)
  236. {
  237. unsigned long actual_len;
  238. struct pdc_pat_pd_addr_map_entry mem_table[PAT_MAX_RANGES+1];
  239. struct pdc_pat_pd_addr_map_entry *mtbl_ptr;
  240. physmem_range_t *pmem_ptr;
  241. long status;
  242. int entries;
  243. unsigned long length;
  244. int i;
  245. length = (PAT_MAX_RANGES + 1) * sizeof(struct pdc_pat_pd_addr_map_entry);
  246. status = pdc_pat_pd_get_addr_map(&actual_len, mem_table, length, 0L);
  247. if ((status != PDC_OK)
  248. || ((actual_len % sizeof(struct pdc_pat_pd_addr_map_entry)) != 0)) {
  249. /* The above pdc call shouldn't fail, but, just in
  250. * case, just use the PAGE0 info.
  251. */
  252. printk("\n\n\n");
  253. printk(KERN_WARNING "WARNING! Could not get full memory configuration. "
  254. "All memory may not be used!\n\n\n");
  255. pagezero_memconfig();
  256. return;
  257. }
  258. entries = actual_len / sizeof(struct pdc_pat_pd_addr_map_entry);
  259. if (entries > PAT_MAX_RANGES) {
  260. printk(KERN_WARNING "This Machine has more memory ranges than we support!\n");
  261. printk(KERN_WARNING "Some memory may not be used!\n");
  262. }
  263. /* Copy information into the firmware independent pmem_ranges
  264. * array, skipping types we don't care about. Notice we said
  265. * "may" above. We'll use all the entries that were returned.
  266. */
  267. npmem_ranges = 0;
  268. mtbl_ptr = mem_table;
  269. pmem_ptr = pmem_ranges; /* Global firmware independent table */
  270. for (i = 0; i < entries; i++,mtbl_ptr++) {
  271. if ( (mtbl_ptr->entry_type != PAT_MEMORY_DESCRIPTOR)
  272. || (mtbl_ptr->memory_type != PAT_MEMTYPE_MEMORY)
  273. || (mtbl_ptr->pages == 0)
  274. || ( (mtbl_ptr->memory_usage != PAT_MEMUSE_GENERAL)
  275. && (mtbl_ptr->memory_usage != PAT_MEMUSE_GI)
  276. && (mtbl_ptr->memory_usage != PAT_MEMUSE_GNI) ) ) {
  277. continue;
  278. }
  279. if (npmem_ranges == MAX_PHYSMEM_RANGES) {
  280. printk(KERN_WARNING "This Machine has more memory ranges than we support!\n");
  281. printk(KERN_WARNING "Some memory will not be used!\n");
  282. break;
  283. }
  284. set_pmem_entry(pmem_ptr++,mtbl_ptr->paddr,mtbl_ptr->pages);
  285. npmem_ranges++;
  286. }
  287. }
  288. static int __init pat_inventory(void)
  289. {
  290. int status;
  291. ulong mod_index = 0;
  292. struct pdc_pat_cell_num cell_info;
  293. /*
  294. ** Note: Prelude (and it's successors: Lclass, A400/500) only
  295. ** implement PDC_PAT_CELL sub-options 0 and 2.
  296. */
  297. status = pdc_pat_cell_get_number(&cell_info);
  298. if (status != PDC_OK) {
  299. return 0;
  300. }
  301. #ifdef DEBUG_PAT
  302. printk(KERN_DEBUG "CELL_GET_NUMBER: 0x%lx 0x%lx\n", cell_info.cell_num,
  303. cell_info.cell_loc);
  304. #endif
  305. while (PDC_OK == pat_query_module(cell_info.cell_loc, mod_index)) {
  306. mod_index++;
  307. }
  308. return mod_index;
  309. }
  310. /* We only look for extended memory ranges on a 64 bit capable box */
  311. static void __init sprockets_memconfig(void)
  312. {
  313. struct pdc_memory_table_raddr r_addr;
  314. struct pdc_memory_table mem_table[MAX_PHYSMEM_RANGES];
  315. struct pdc_memory_table *mtbl_ptr;
  316. physmem_range_t *pmem_ptr;
  317. long status;
  318. int entries;
  319. int i;
  320. status = pdc_mem_mem_table(&r_addr,mem_table,
  321. (unsigned long)MAX_PHYSMEM_RANGES);
  322. if (status != PDC_OK) {
  323. /* The above pdc call only works on boxes with sprockets
  324. * firmware (newer B,C,J class). Other non PAT PDC machines
  325. * do support more than 3.75 Gb of memory, but we don't
  326. * support them yet.
  327. */
  328. pagezero_memconfig();
  329. return;
  330. }
  331. if (r_addr.entries_total > MAX_PHYSMEM_RANGES) {
  332. printk(KERN_WARNING "This Machine has more memory ranges than we support!\n");
  333. printk(KERN_WARNING "Some memory will not be used!\n");
  334. }
  335. entries = (int)r_addr.entries_returned;
  336. npmem_ranges = 0;
  337. mtbl_ptr = mem_table;
  338. pmem_ptr = pmem_ranges; /* Global firmware independent table */
  339. for (i = 0; i < entries; i++,mtbl_ptr++) {
  340. set_pmem_entry(pmem_ptr++,mtbl_ptr->paddr,mtbl_ptr->pages);
  341. npmem_ranges++;
  342. }
  343. }
  344. #else /* !CONFIG_64BIT */
  345. #define pat_inventory() do { } while (0)
  346. #define pat_memconfig() do { } while (0)
  347. #define sprockets_memconfig() pagezero_memconfig()
  348. #endif /* !CONFIG_64BIT */
  349. #ifndef CONFIG_PA20
  350. /* Code to support Snake machines (7[2350], 7[235]5, 715/Scorpio) */
  351. static struct parisc_device * __init
  352. legacy_create_device(struct pdc_memory_map *r_addr,
  353. struct pdc_module_path *module_path)
  354. {
  355. struct parisc_device *dev;
  356. int status = pdc_mem_map_hpa(r_addr, module_path);
  357. if (status != PDC_OK)
  358. return NULL;
  359. dev = alloc_pa_dev(r_addr->hpa, &module_path->path);
  360. if (dev == NULL)
  361. return NULL;
  362. register_parisc_device(dev);
  363. return dev;
  364. }
  365. /**
  366. * snake_inventory
  367. *
  368. * Before PDC_SYSTEM_MAP was invented, the PDC_MEM_MAP call was used.
  369. * To use it, we initialise the mod_path.bc to 0xff and try all values of
  370. * mod to get the HPA for the top-level devices. Bus adapters may have
  371. * sub-devices which are discovered by setting bc[5] to 0 and bc[4] to the
  372. * module, then trying all possible functions.
  373. */
  374. static void __init snake_inventory(void)
  375. {
  376. int mod;
  377. for (mod = 0; mod < 16; mod++) {
  378. struct parisc_device *dev;
  379. struct pdc_module_path module_path;
  380. struct pdc_memory_map r_addr;
  381. unsigned int func;
  382. memset(module_path.path.bc, 0xff, 6);
  383. module_path.path.mod = mod;
  384. dev = legacy_create_device(&r_addr, &module_path);
  385. if ((!dev) || (dev->id.hw_type != HPHW_BA))
  386. continue;
  387. memset(module_path.path.bc, 0xff, 4);
  388. module_path.path.bc[4] = mod;
  389. for (func = 0; func < 16; func++) {
  390. module_path.path.bc[5] = 0;
  391. module_path.path.mod = func;
  392. legacy_create_device(&r_addr, &module_path);
  393. }
  394. }
  395. }
  396. #else /* CONFIG_PA20 */
  397. #define snake_inventory() do { } while (0)
  398. #endif /* CONFIG_PA20 */
  399. /* Common 32/64 bit based code goes here */
  400. /**
  401. * add_system_map_addresses - Add additional addresses to the parisc device.
  402. * @dev: The parisc device.
  403. * @num_addrs: Then number of addresses to add;
  404. * @module_instance: The system_map module instance.
  405. *
  406. * This function adds any additional addresses reported by the system_map
  407. * firmware to the parisc device.
  408. */
  409. static void __init
  410. add_system_map_addresses(struct parisc_device *dev, int num_addrs,
  411. int module_instance)
  412. {
  413. int i;
  414. long status;
  415. struct pdc_system_map_addr_info addr_result;
  416. dev->addr = kmalloc(num_addrs * sizeof(unsigned long), GFP_KERNEL);
  417. if(!dev->addr) {
  418. printk(KERN_ERR "%s %s(): memory allocation failure\n",
  419. __FILE__, __func__);
  420. return;
  421. }
  422. for(i = 1; i <= num_addrs; ++i) {
  423. status = pdc_system_map_find_addrs(&addr_result,
  424. module_instance, i);
  425. if(PDC_OK == status) {
  426. dev->addr[dev->num_addrs] = (unsigned long)addr_result.mod_addr;
  427. dev->num_addrs++;
  428. } else {
  429. printk(KERN_WARNING
  430. "Bad PDC_FIND_ADDRESS status return (%ld) for index %d\n",
  431. status, i);
  432. }
  433. }
  434. }
  435. /**
  436. * system_map_inventory - Retrieve firmware devices via SYSTEM_MAP.
  437. *
  438. * This function attempts to retrieve and register all the devices firmware
  439. * knows about via the SYSTEM_MAP PDC call.
  440. */
  441. static void __init system_map_inventory(void)
  442. {
  443. int i;
  444. long status = PDC_OK;
  445. for (i = 0; i < 256; i++) {
  446. struct parisc_device *dev;
  447. struct pdc_system_map_mod_info module_result;
  448. struct pdc_module_path module_path;
  449. status = pdc_system_map_find_mods(&module_result,
  450. &module_path, i);
  451. if ((status == PDC_BAD_PROC) || (status == PDC_NE_MOD))
  452. break;
  453. if (status != PDC_OK)
  454. continue;
  455. dev = alloc_pa_dev(module_result.mod_addr, &module_path.path);
  456. if (!dev)
  457. continue;
  458. register_parisc_device(dev);
  459. /* if available, get the additional addresses for a module */
  460. if (!module_result.add_addrs)
  461. continue;
  462. add_system_map_addresses(dev, module_result.add_addrs, i);
  463. }
  464. walk_central_bus();
  465. return;
  466. }
  467. void __init do_memory_inventory(void)
  468. {
  469. switch (pdc_type) {
  470. case PDC_TYPE_PAT:
  471. pat_memconfig();
  472. break;
  473. case PDC_TYPE_SYSTEM_MAP:
  474. sprockets_memconfig();
  475. break;
  476. case PDC_TYPE_SNAKE:
  477. pagezero_memconfig();
  478. return;
  479. default:
  480. panic("Unknown PDC type!\n");
  481. }
  482. if (npmem_ranges == 0 || pmem_ranges[0].start_pfn != 0) {
  483. printk(KERN_WARNING "Bad memory configuration returned!\n");
  484. printk(KERN_WARNING "Some memory may not be used!\n");
  485. pagezero_memconfig();
  486. }
  487. }
  488. void __init do_device_inventory(void)
  489. {
  490. printk(KERN_INFO "Searching for devices...\n");
  491. init_parisc_bus();
  492. switch (pdc_type) {
  493. case PDC_TYPE_PAT:
  494. pat_inventory();
  495. break;
  496. case PDC_TYPE_SYSTEM_MAP:
  497. system_map_inventory();
  498. break;
  499. case PDC_TYPE_SNAKE:
  500. snake_inventory();
  501. break;
  502. default:
  503. panic("Unknown PDC type!\n");
  504. }
  505. printk(KERN_INFO "Found devices:\n");
  506. print_parisc_devices();
  507. }