inventory.c 16 KB

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