drivers.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. /*
  2. * drivers.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
  10. * Copyright (c) 2001 Matthew Wilcox for Hewlett Packard
  11. * Copyright (c) 2001 Helge Deller <deller@gmx.de>
  12. * Copyright (c) 2001,2002 Ryan Bradetich
  13. * Copyright (c) 2004-2005 Thibaut VARENE <varenet@parisc-linux.org>
  14. *
  15. * The file handles registering devices and drivers, then matching them.
  16. * It's the closest we get to a dating agency.
  17. *
  18. * If you're thinking about modifying this file, here are some gotchas to
  19. * bear in mind:
  20. * - 715/Mirage device paths have a dummy device between Lasi and its children
  21. * - The EISA adapter may show up as a sibling or child of Wax
  22. * - Dino has an optionally functional serial port. If firmware enables it,
  23. * it shows up as a child of Dino. If firmware disables it, the buswalk
  24. * finds it and it shows up as a child of Cujo
  25. * - Dino has both parisc and pci devices as children
  26. * - parisc devices are discovered in a random order, including children
  27. * before parents in some cases.
  28. */
  29. #include <linux/slab.h>
  30. #include <linux/types.h>
  31. #include <linux/kernel.h>
  32. #include <linux/pci.h>
  33. #include <linux/spinlock.h>
  34. #include <linux/string.h>
  35. #include <asm/hardware.h>
  36. #include <asm/io.h>
  37. #include <asm/pdc.h>
  38. #include <asm/parisc-device.h>
  39. /* See comments in include/asm-parisc/pci.h */
  40. struct hppa_dma_ops *hppa_dma_ops;
  41. EXPORT_SYMBOL(hppa_dma_ops);
  42. static struct device root = {
  43. .bus_id = "parisc",
  44. };
  45. #define for_each_padev(padev) \
  46. for (padev = next_dev(&root); padev != NULL; \
  47. padev = next_dev(&padev->dev))
  48. #define check_dev(padev) \
  49. (padev->id.hw_type != HPHW_FAULTY) ? padev : next_dev(&padev->dev)
  50. /**
  51. * next_dev - enumerates registered devices
  52. * @dev: the previous device returned from next_dev
  53. *
  54. * next_dev does a depth-first search of the tree, returning parents
  55. * before children. Returns NULL when there are no more devices.
  56. */
  57. static struct parisc_device *next_dev(struct device *dev)
  58. {
  59. if (!list_empty(&dev->children)) {
  60. dev = list_to_dev(dev->children.next);
  61. return check_dev(to_parisc_device(dev));
  62. }
  63. while (dev != &root) {
  64. if (dev->node.next != &dev->parent->children) {
  65. dev = list_to_dev(dev->node.next);
  66. return to_parisc_device(dev);
  67. }
  68. dev = dev->parent;
  69. }
  70. return NULL;
  71. }
  72. /**
  73. * match_device - Report whether this driver can handle this device
  74. * @driver: the PA-RISC driver to try
  75. * @dev: the PA-RISC device to try
  76. */
  77. static int match_device(struct parisc_driver *driver, struct parisc_device *dev)
  78. {
  79. const struct parisc_device_id *ids;
  80. for (ids = driver->id_table; ids->sversion; ids++) {
  81. if ((ids->sversion != SVERSION_ANY_ID) &&
  82. (ids->sversion != dev->id.sversion))
  83. continue;
  84. if ((ids->hw_type != HWTYPE_ANY_ID) &&
  85. (ids->hw_type != dev->id.hw_type))
  86. continue;
  87. if ((ids->hversion != HVERSION_ANY_ID) &&
  88. (ids->hversion != dev->id.hversion))
  89. continue;
  90. return 1;
  91. }
  92. return 0;
  93. }
  94. static void claim_device(struct parisc_driver *driver, struct parisc_device *dev)
  95. {
  96. dev->driver = driver;
  97. request_mem_region(dev->hpa, 0x1000, driver->name);
  98. }
  99. static int parisc_driver_probe(struct device *dev)
  100. {
  101. int rc;
  102. struct parisc_device *pa_dev = to_parisc_device(dev);
  103. struct parisc_driver *pa_drv = to_parisc_driver(dev->driver);
  104. rc = pa_drv->probe(pa_dev);
  105. if(!rc)
  106. claim_device(pa_drv, pa_dev);
  107. return rc;
  108. }
  109. static int parisc_driver_remove(struct device *dev)
  110. {
  111. struct parisc_device *pa_dev = to_parisc_device(dev);
  112. struct parisc_driver *pa_drv = to_parisc_driver(dev->driver);
  113. if (pa_drv->remove)
  114. pa_drv->remove(pa_dev);
  115. release_mem_region(pa_dev->hpa, 0x1000);
  116. return 0;
  117. }
  118. /**
  119. * register_parisc_driver - Register this driver if it can handle a device
  120. * @driver: the PA-RISC driver to try
  121. */
  122. int register_parisc_driver(struct parisc_driver *driver)
  123. {
  124. /* FIXME: we need this because apparently the sti
  125. * driver can be registered twice */
  126. if(driver->drv.name) {
  127. printk(KERN_WARNING
  128. "BUG: skipping previously registered driver %s\n",
  129. driver->name);
  130. return 1;
  131. }
  132. if (!driver->probe) {
  133. printk(KERN_WARNING
  134. "BUG: driver %s has no probe routine\n",
  135. driver->name);
  136. return 1;
  137. }
  138. driver->drv.bus = &parisc_bus_type;
  139. /* We install our own probe and remove routines */
  140. WARN_ON(driver->drv.probe != NULL);
  141. WARN_ON(driver->drv.remove != NULL);
  142. driver->drv.probe = parisc_driver_probe;
  143. driver->drv.remove = parisc_driver_remove;
  144. driver->drv.name = driver->name;
  145. return driver_register(&driver->drv);
  146. }
  147. EXPORT_SYMBOL(register_parisc_driver);
  148. /**
  149. * count_parisc_driver - count # of devices this driver would match
  150. * @driver: the PA-RISC driver to try
  151. *
  152. * Use by IOMMU support to "guess" the right size IOPdir.
  153. * Formula is something like memsize/(num_iommu * entry_size).
  154. */
  155. int count_parisc_driver(struct parisc_driver *driver)
  156. {
  157. struct parisc_device *device;
  158. int cnt = 0;
  159. for_each_padev(device) {
  160. if (match_device(driver, device))
  161. cnt++;
  162. }
  163. return cnt;
  164. }
  165. /**
  166. * unregister_parisc_driver - Unregister this driver from the list of drivers
  167. * @driver: the PA-RISC driver to unregister
  168. */
  169. int unregister_parisc_driver(struct parisc_driver *driver)
  170. {
  171. driver_unregister(&driver->drv);
  172. return 0;
  173. }
  174. EXPORT_SYMBOL(unregister_parisc_driver);
  175. static struct parisc_device *find_device_by_addr(unsigned long hpa)
  176. {
  177. struct parisc_device *dev;
  178. for_each_padev(dev) {
  179. if (dev->hpa == hpa)
  180. return dev;
  181. }
  182. return NULL;
  183. }
  184. /**
  185. * find_pa_parent_type - Find a parent of a specific type
  186. * @dev: The device to start searching from
  187. * @type: The device type to search for.
  188. *
  189. * Walks up the device tree looking for a device of the specified type.
  190. * If it finds it, it returns it. If not, it returns NULL.
  191. */
  192. const struct parisc_device *
  193. find_pa_parent_type(const struct parisc_device *padev, int type)
  194. {
  195. const struct device *dev = &padev->dev;
  196. while (dev != &root) {
  197. struct parisc_device *candidate = to_parisc_device(dev);
  198. if (candidate->id.hw_type == type)
  199. return candidate;
  200. dev = dev->parent;
  201. }
  202. return NULL;
  203. }
  204. #ifdef CONFIG_PCI
  205. static inline int is_pci_dev(struct device *dev)
  206. {
  207. return dev->bus == &pci_bus_type;
  208. }
  209. #else
  210. static inline int is_pci_dev(struct device *dev)
  211. {
  212. return 0;
  213. }
  214. #endif
  215. /*
  216. * get_node_path fills in @path with the firmware path to the device.
  217. * Note that if @node is a parisc device, we don't fill in the 'mod' field.
  218. * This is because both callers pass the parent and fill in the mod
  219. * themselves. If @node is a PCI device, we do fill it in, even though this
  220. * is inconsistent.
  221. */
  222. static void get_node_path(struct device *dev, struct hardware_path *path)
  223. {
  224. int i = 5;
  225. memset(&path->bc, -1, 6);
  226. if (is_pci_dev(dev)) {
  227. unsigned int devfn = to_pci_dev(dev)->devfn;
  228. path->mod = PCI_FUNC(devfn);
  229. path->bc[i--] = PCI_SLOT(devfn);
  230. dev = dev->parent;
  231. }
  232. while (dev != &root) {
  233. if (is_pci_dev(dev)) {
  234. unsigned int devfn = to_pci_dev(dev)->devfn;
  235. path->bc[i--] = PCI_SLOT(devfn) | (PCI_FUNC(devfn)<< 5);
  236. } else if (dev->bus == &parisc_bus_type) {
  237. path->bc[i--] = to_parisc_device(dev)->hw_path;
  238. }
  239. dev = dev->parent;
  240. }
  241. }
  242. static char *print_hwpath(struct hardware_path *path, char *output)
  243. {
  244. int i;
  245. for (i = 0; i < 6; i++) {
  246. if (path->bc[i] == -1)
  247. continue;
  248. output += sprintf(output, "%u/", (unsigned char) path->bc[i]);
  249. }
  250. output += sprintf(output, "%u", (unsigned char) path->mod);
  251. return output;
  252. }
  253. /**
  254. * print_pa_hwpath - Returns hardware path for PA devices
  255. * dev: The device to return the path for
  256. * output: Pointer to a previously-allocated array to place the path in.
  257. *
  258. * This function fills in the output array with a human-readable path
  259. * to a PA device. This string is compatible with that used by PDC, and
  260. * may be printed on the outside of the box.
  261. */
  262. char *print_pa_hwpath(struct parisc_device *dev, char *output)
  263. {
  264. struct hardware_path path;
  265. get_node_path(dev->dev.parent, &path);
  266. path.mod = dev->hw_path;
  267. return print_hwpath(&path, output);
  268. }
  269. EXPORT_SYMBOL(print_pa_hwpath);
  270. #if defined(CONFIG_PCI) || defined(CONFIG_ISA)
  271. /**
  272. * get_pci_node_path - Determines the hardware path for a PCI device
  273. * @pdev: The device to return the path for
  274. * @path: Pointer to a previously-allocated array to place the path in.
  275. *
  276. * This function fills in the hardware_path structure with the route to
  277. * the specified PCI device. This structure is suitable for passing to
  278. * PDC calls.
  279. */
  280. void get_pci_node_path(struct pci_dev *pdev, struct hardware_path *path)
  281. {
  282. get_node_path(&pdev->dev, path);
  283. }
  284. EXPORT_SYMBOL(get_pci_node_path);
  285. /**
  286. * print_pci_hwpath - Returns hardware path for PCI devices
  287. * dev: The device to return the path for
  288. * output: Pointer to a previously-allocated array to place the path in.
  289. *
  290. * This function fills in the output array with a human-readable path
  291. * to a PCI device. This string is compatible with that used by PDC, and
  292. * may be printed on the outside of the box.
  293. */
  294. char *print_pci_hwpath(struct pci_dev *dev, char *output)
  295. {
  296. struct hardware_path path;
  297. get_pci_node_path(dev, &path);
  298. return print_hwpath(&path, output);
  299. }
  300. EXPORT_SYMBOL(print_pci_hwpath);
  301. #endif /* defined(CONFIG_PCI) || defined(CONFIG_ISA) */
  302. static void setup_bus_id(struct parisc_device *padev)
  303. {
  304. struct hardware_path path;
  305. char *output = padev->dev.bus_id;
  306. int i;
  307. get_node_path(padev->dev.parent, &path);
  308. for (i = 0; i < 6; i++) {
  309. if (path.bc[i] == -1)
  310. continue;
  311. output += sprintf(output, "%u:", (unsigned char) path.bc[i]);
  312. }
  313. sprintf(output, "%u", (unsigned char) padev->hw_path);
  314. }
  315. struct parisc_device * create_tree_node(char id, struct device *parent)
  316. {
  317. struct parisc_device *dev = kmalloc(sizeof(*dev), GFP_KERNEL);
  318. if (!dev)
  319. return NULL;
  320. memset(dev, 0, sizeof(*dev));
  321. dev->hw_path = id;
  322. dev->id.hw_type = HPHW_FAULTY;
  323. dev->dev.parent = parent;
  324. setup_bus_id(dev);
  325. dev->dev.bus = &parisc_bus_type;
  326. dev->dma_mask = 0xffffffffUL; /* PARISC devices are 32-bit */
  327. /* make the generic dma mask a pointer to the parisc one */
  328. dev->dev.dma_mask = &dev->dma_mask;
  329. dev->dev.coherent_dma_mask = dev->dma_mask;
  330. device_register(&dev->dev);
  331. return dev;
  332. }
  333. /**
  334. * alloc_tree_node - returns a device entry in the iotree
  335. * @parent: the parent node in the tree
  336. * @id: the element of the module path for this entry
  337. *
  338. * Checks all the children of @parent for a matching @id. If none
  339. * found, it allocates a new device and returns it.
  340. */
  341. static struct parisc_device * alloc_tree_node(struct device *parent, char id)
  342. {
  343. struct device *dev;
  344. list_for_each_entry(dev, &parent->children, node) {
  345. struct parisc_device *padev = to_parisc_device(dev);
  346. if (padev->hw_path == id)
  347. return padev;
  348. }
  349. return create_tree_node(id, parent);
  350. }
  351. static struct parisc_device *create_parisc_device(struct hardware_path *modpath)
  352. {
  353. int i;
  354. struct device *parent = &root;
  355. for (i = 0; i < 6; i++) {
  356. if (modpath->bc[i] == -1)
  357. continue;
  358. parent = &alloc_tree_node(parent, modpath->bc[i])->dev;
  359. }
  360. return alloc_tree_node(parent, modpath->mod);
  361. }
  362. struct parisc_device *
  363. alloc_pa_dev(unsigned long hpa, struct hardware_path *mod_path)
  364. {
  365. int status;
  366. unsigned long bytecnt;
  367. u8 iodc_data[32];
  368. struct parisc_device *dev;
  369. const char *name;
  370. /* Check to make sure this device has not already been added - Ryan */
  371. if (find_device_by_addr(hpa) != NULL)
  372. return NULL;
  373. status = pdc_iodc_read(&bytecnt, hpa, 0, &iodc_data, 32);
  374. if (status != PDC_OK)
  375. return NULL;
  376. dev = create_parisc_device(mod_path);
  377. if (dev->id.hw_type != HPHW_FAULTY) {
  378. char p[64];
  379. print_pa_hwpath(dev, p);
  380. printk("Two devices have hardware path %s. Please file a bug with HP.\n"
  381. "In the meantime, you could try rearranging your cards.\n", p);
  382. return NULL;
  383. }
  384. dev->id.hw_type = iodc_data[3] & 0x1f;
  385. dev->id.hversion = (iodc_data[0] << 4) | ((iodc_data[1] & 0xf0) >> 4);
  386. dev->id.hversion_rev = iodc_data[1] & 0x0f;
  387. dev->id.sversion = ((iodc_data[4] & 0x0f) << 16) |
  388. (iodc_data[5] << 8) | iodc_data[6];
  389. dev->hpa = hpa;
  390. name = parisc_hardware_description(&dev->id);
  391. if (name) {
  392. strlcpy(dev->name, name, sizeof(dev->name));
  393. }
  394. return dev;
  395. }
  396. static int parisc_generic_match(struct device *dev, struct device_driver *drv)
  397. {
  398. return match_device(to_parisc_driver(drv), to_parisc_device(dev));
  399. }
  400. #define pa_dev_attr(name, field, format_string) \
  401. static ssize_t name##_show(struct device *dev, struct device_attribute *attr, char *buf) \
  402. { \
  403. struct parisc_device *padev = to_parisc_device(dev); \
  404. return sprintf(buf, format_string, padev->field); \
  405. }
  406. #define pa_dev_attr_id(field, format) pa_dev_attr(field, id.field, format)
  407. pa_dev_attr(irq, irq, "%u\n");
  408. pa_dev_attr_id(hw_type, "0x%02x\n");
  409. pa_dev_attr(rev, id.hversion_rev, "0x%x\n");
  410. pa_dev_attr_id(hversion, "0x%03x\n");
  411. pa_dev_attr_id(sversion, "0x%05x\n");
  412. static struct device_attribute parisc_device_attrs[] = {
  413. __ATTR_RO(irq),
  414. __ATTR_RO(hw_type),
  415. __ATTR_RO(rev),
  416. __ATTR_RO(hversion),
  417. __ATTR_RO(sversion),
  418. __ATTR_NULL,
  419. };
  420. struct bus_type parisc_bus_type = {
  421. .name = "parisc",
  422. .match = parisc_generic_match,
  423. .dev_attrs = parisc_device_attrs,
  424. };
  425. /**
  426. * register_parisc_device - Locate a driver to manage this device.
  427. * @dev: The parisc device.
  428. *
  429. * Search the driver list for a driver that is willing to manage
  430. * this device.
  431. */
  432. int register_parisc_device(struct parisc_device *dev)
  433. {
  434. if (!dev)
  435. return 0;
  436. if (dev->driver)
  437. return 1;
  438. return 0;
  439. }
  440. /**
  441. * match_pci_device - Matches a pci device against a given hardware path
  442. * entry.
  443. * @dev: the generic device (known to be contained by a pci_dev).
  444. * @index: the current BC index
  445. * @modpath: the hardware path.
  446. * @return: true if the device matches the hardware path.
  447. */
  448. static int match_pci_device(struct device *dev, int index,
  449. struct hardware_path *modpath)
  450. {
  451. struct pci_dev *pdev = to_pci_dev(dev);
  452. int id;
  453. if (index == 5) {
  454. /* we are at the end of the path, and on the actual device */
  455. unsigned int devfn = pdev->devfn;
  456. return ((modpath->bc[5] == PCI_SLOT(devfn)) &&
  457. (modpath->mod == PCI_FUNC(devfn)));
  458. }
  459. id = PCI_SLOT(pdev->devfn) | (PCI_FUNC(pdev->devfn) << 5);
  460. return (modpath->bc[index] == id);
  461. }
  462. /**
  463. * match_parisc_device - Matches a parisc device against a given hardware
  464. * path entry.
  465. * @dev: the generic device (known to be contained by a parisc_device).
  466. * @index: the current BC index
  467. * @modpath: the hardware path.
  468. * @return: true if the device matches the hardware path.
  469. */
  470. static int match_parisc_device(struct device *dev, int index,
  471. struct hardware_path *modpath)
  472. {
  473. struct parisc_device *curr = to_parisc_device(dev);
  474. char id = (index == 6) ? modpath->mod : modpath->bc[index];
  475. return (curr->hw_path == id);
  476. }
  477. /**
  478. * parse_tree_node - returns a device entry in the iotree
  479. * @parent: the parent node in the tree
  480. * @index: the current BC index
  481. * @modpath: the hardware_path struct to match a device against
  482. * @return: The corresponding device if found, NULL otherwise.
  483. *
  484. * Checks all the children of @parent for a matching @id. If none
  485. * found, it returns NULL.
  486. */
  487. static struct device *
  488. parse_tree_node(struct device *parent, int index, struct hardware_path *modpath)
  489. {
  490. struct device *device;
  491. list_for_each_entry(device, &parent->children, node) {
  492. if (device->bus == &parisc_bus_type) {
  493. if (match_parisc_device(device, index, modpath))
  494. return device;
  495. } else if (is_pci_dev(device)) {
  496. if (match_pci_device(device, index, modpath))
  497. return device;
  498. } else if (device->bus == NULL) {
  499. /* we are on a bus bridge */
  500. struct device *new = parse_tree_node(device, index, modpath);
  501. if (new)
  502. return new;
  503. }
  504. }
  505. return NULL;
  506. }
  507. /**
  508. * hwpath_to_device - Finds the generic device corresponding to a given hardware path.
  509. * @modpath: the hardware path.
  510. * @return: The target device, NULL if not found.
  511. */
  512. struct device *hwpath_to_device(struct hardware_path *modpath)
  513. {
  514. int i;
  515. struct device *parent = &root;
  516. for (i = 0; i < 6; i++) {
  517. if (modpath->bc[i] == -1)
  518. continue;
  519. parent = parse_tree_node(parent, i, modpath);
  520. if (!parent)
  521. return NULL;
  522. }
  523. if (is_pci_dev(parent)) /* pci devices already parse MOD */
  524. return parent;
  525. else
  526. return parse_tree_node(parent, 6, modpath);
  527. }
  528. EXPORT_SYMBOL(hwpath_to_device);
  529. /**
  530. * device_to_hwpath - Populates the hwpath corresponding to the given device.
  531. * @param dev the target device
  532. * @param path pointer to a previously allocated hwpath struct to be filled in
  533. */
  534. void device_to_hwpath(struct device *dev, struct hardware_path *path)
  535. {
  536. struct parisc_device *padev;
  537. if (dev->bus == &parisc_bus_type) {
  538. padev = to_parisc_device(dev);
  539. get_node_path(dev->parent, path);
  540. path->mod = padev->hw_path;
  541. } else if (is_pci_dev(dev)) {
  542. get_node_path(dev, path);
  543. }
  544. }
  545. EXPORT_SYMBOL(device_to_hwpath);
  546. #define BC_PORT_MASK 0x8
  547. #define BC_LOWER_PORT 0x8
  548. #define BUS_CONVERTER(dev) \
  549. ((dev->id.hw_type == HPHW_IOA) || (dev->id.hw_type == HPHW_BCPORT))
  550. #define IS_LOWER_PORT(dev) \
  551. ((gsc_readl(dev->hpa + offsetof(struct bc_module, io_status)) \
  552. & BC_PORT_MASK) == BC_LOWER_PORT)
  553. #define MAX_NATIVE_DEVICES 64
  554. #define NATIVE_DEVICE_OFFSET 0x1000
  555. #define FLEX_MASK F_EXTEND(0xfffc0000)
  556. #define IO_IO_LOW offsetof(struct bc_module, io_io_low)
  557. #define IO_IO_HIGH offsetof(struct bc_module, io_io_high)
  558. #define READ_IO_IO_LOW(dev) (unsigned long)(signed int)gsc_readl(dev->hpa + IO_IO_LOW)
  559. #define READ_IO_IO_HIGH(dev) (unsigned long)(signed int)gsc_readl(dev->hpa + IO_IO_HIGH)
  560. static void walk_native_bus(unsigned long io_io_low, unsigned long io_io_high,
  561. struct device *parent);
  562. void walk_lower_bus(struct parisc_device *dev)
  563. {
  564. unsigned long io_io_low, io_io_high;
  565. if(!BUS_CONVERTER(dev) || IS_LOWER_PORT(dev))
  566. return;
  567. if(dev->id.hw_type == HPHW_IOA) {
  568. io_io_low = (unsigned long)(signed int)(READ_IO_IO_LOW(dev) << 16);
  569. io_io_high = io_io_low + MAX_NATIVE_DEVICES * NATIVE_DEVICE_OFFSET;
  570. } else {
  571. io_io_low = (READ_IO_IO_LOW(dev) + ~FLEX_MASK) & FLEX_MASK;
  572. io_io_high = (READ_IO_IO_HIGH(dev)+ ~FLEX_MASK) & FLEX_MASK;
  573. }
  574. walk_native_bus(io_io_low, io_io_high, &dev->dev);
  575. }
  576. /**
  577. * walk_native_bus -- Probe a bus for devices
  578. * @io_io_low: Base address of this bus.
  579. * @io_io_high: Last address of this bus.
  580. * @parent: The parent bus device.
  581. *
  582. * A native bus (eg Runway or GSC) may have up to 64 devices on it,
  583. * spaced at intervals of 0x1000 bytes. PDC may not inform us of these
  584. * devices, so we have to probe for them. Unfortunately, we may find
  585. * devices which are not physically connected (such as extra serial &
  586. * keyboard ports). This problem is not yet solved.
  587. */
  588. static void walk_native_bus(unsigned long io_io_low, unsigned long io_io_high,
  589. struct device *parent)
  590. {
  591. int i, devices_found = 0;
  592. unsigned long hpa = io_io_low;
  593. struct hardware_path path;
  594. get_node_path(parent, &path);
  595. do {
  596. for(i = 0; i < MAX_NATIVE_DEVICES; i++, hpa += NATIVE_DEVICE_OFFSET) {
  597. struct parisc_device *dev;
  598. /* Was the device already added by Firmware? */
  599. dev = find_device_by_addr(hpa);
  600. if (!dev) {
  601. path.mod = i;
  602. dev = alloc_pa_dev(hpa, &path);
  603. if (!dev)
  604. continue;
  605. register_parisc_device(dev);
  606. devices_found++;
  607. }
  608. walk_lower_bus(dev);
  609. }
  610. } while(!devices_found && hpa < io_io_high);
  611. }
  612. #define CENTRAL_BUS_ADDR F_EXTEND(0xfff80000)
  613. /**
  614. * walk_central_bus - Find devices attached to the central bus
  615. *
  616. * PDC doesn't tell us about all devices in the system. This routine
  617. * finds devices connected to the central bus.
  618. */
  619. void walk_central_bus(void)
  620. {
  621. walk_native_bus(CENTRAL_BUS_ADDR,
  622. CENTRAL_BUS_ADDR + (MAX_NATIVE_DEVICES * NATIVE_DEVICE_OFFSET),
  623. &root);
  624. }
  625. static void print_parisc_device(struct parisc_device *dev)
  626. {
  627. char hw_path[64];
  628. static int count;
  629. print_pa_hwpath(dev, hw_path);
  630. printk(KERN_INFO "%d. %s at 0x%lx [%s] { %d, 0x%x, 0x%.3x, 0x%.5x }",
  631. ++count, dev->name, dev->hpa, hw_path, dev->id.hw_type,
  632. dev->id.hversion_rev, dev->id.hversion, dev->id.sversion);
  633. if (dev->num_addrs) {
  634. int k;
  635. printk(", additional addresses: ");
  636. for (k = 0; k < dev->num_addrs; k++)
  637. printk("0x%lx ", dev->addr[k]);
  638. }
  639. printk("\n");
  640. }
  641. /**
  642. * init_parisc_bus - Some preparation to be done before inventory
  643. */
  644. void init_parisc_bus(void)
  645. {
  646. bus_register(&parisc_bus_type);
  647. device_register(&root);
  648. get_device(&root);
  649. }
  650. /**
  651. * print_parisc_devices - Print out a list of devices found in this system
  652. */
  653. void print_parisc_devices(void)
  654. {
  655. struct parisc_device *dev;
  656. for_each_padev(dev) {
  657. print_parisc_device(dev);
  658. }
  659. }