pci_eisa.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Minimalist driver for a generic PCI-to-EISA bridge.
  4. *
  5. * (C) 2003 Marc Zyngier <maz@wild-wind.fr.eu.org>
  6. *
  7. * Ivan Kokshaysky <ink@jurassic.park.msu.ru> :
  8. * Generalisation from i82375 to PCI_CLASS_BRIDGE_EISA.
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/device.h>
  12. #include <linux/eisa.h>
  13. #include <linux/pci.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. /* There is only *one* pci_eisa device per machine, right ? */
  17. static struct eisa_root_device pci_eisa_root;
  18. static int __init pci_eisa_init(struct pci_dev *pdev)
  19. {
  20. int rc, i;
  21. struct resource *res, *bus_res = NULL;
  22. if ((rc = pci_enable_device (pdev))) {
  23. dev_err(&pdev->dev, "Could not enable device\n");
  24. return rc;
  25. }
  26. /*
  27. * The Intel 82375 PCI-EISA bridge is a subtractive-decode PCI
  28. * device, so the resources available on EISA are the same as those
  29. * available on the 82375 bus. This works the same as a PCI-PCI
  30. * bridge in subtractive-decode mode (see pci_read_bridge_bases()).
  31. * We assume other PCI-EISA bridges are similar.
  32. *
  33. * eisa_root_register() can only deal with a single io port resource,
  34. * so we use the first valid io port resource.
  35. */
  36. pci_bus_for_each_resource(pdev->bus, res, i)
  37. if (res && (res->flags & IORESOURCE_IO)) {
  38. bus_res = res;
  39. break;
  40. }
  41. if (!bus_res) {
  42. dev_err(&pdev->dev, "No resources available\n");
  43. return -1;
  44. }
  45. pci_eisa_root.dev = &pdev->dev;
  46. pci_eisa_root.res = bus_res;
  47. pci_eisa_root.bus_base_addr = bus_res->start;
  48. pci_eisa_root.slots = EISA_MAX_SLOTS;
  49. pci_eisa_root.dma_mask = pdev->dma_mask;
  50. dev_set_drvdata(pci_eisa_root.dev, &pci_eisa_root);
  51. if (eisa_root_register (&pci_eisa_root)) {
  52. dev_err(&pdev->dev, "Could not register EISA root\n");
  53. return -1;
  54. }
  55. return 0;
  56. }
  57. /*
  58. * We have to call pci_eisa_init_early() before pnpacpi_init()/isapnp_init().
  59. * Otherwise pnp resource will get enabled early and could prevent eisa
  60. * to be initialized.
  61. * Also need to make sure pci_eisa_init_early() is called after
  62. * x86/pci_subsys_init().
  63. * So need to use subsys_initcall_sync with it.
  64. */
  65. static int __init pci_eisa_init_early(void)
  66. {
  67. struct pci_dev *dev = NULL;
  68. int ret;
  69. for_each_pci_dev(dev)
  70. if ((dev->class >> 8) == PCI_CLASS_BRIDGE_EISA) {
  71. ret = pci_eisa_init(dev);
  72. if (ret)
  73. return ret;
  74. }
  75. return 0;
  76. }
  77. subsys_initcall_sync(pci_eisa_init_early);