cardbus.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * cardbus.c -- 16-bit PCMCIA core support
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * The initial developer of the original code is David A. Hinds
  9. * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  10. * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  11. *
  12. * (C) 1999 David A. Hinds
  13. */
  14. /*
  15. * Cardbus handling has been re-written to be more of a PCI bridge thing,
  16. * and the PCI code basically does all the resource handling.
  17. *
  18. * Linus, Jan 2000
  19. */
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/pci.h>
  23. #include <pcmcia/ss.h>
  24. static void cardbus_config_irq_and_cls(struct pci_bus *bus, int irq)
  25. {
  26. struct pci_dev *dev;
  27. list_for_each_entry(dev, &bus->devices, bus_list) {
  28. u8 irq_pin;
  29. /*
  30. * Since there is only one interrupt available to
  31. * CardBus devices, all devices downstream of this
  32. * device must be using this IRQ.
  33. */
  34. pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &irq_pin);
  35. if (irq_pin) {
  36. dev->irq = irq;
  37. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
  38. }
  39. /*
  40. * Some controllers transfer very slowly with 0 CLS.
  41. * Configure it. This may fail as CLS configuration
  42. * is mandatory only for MWI.
  43. */
  44. pci_set_cacheline_size(dev);
  45. if (dev->subordinate)
  46. cardbus_config_irq_and_cls(dev->subordinate, irq);
  47. }
  48. }
  49. /**
  50. * cb_alloc() - add CardBus device
  51. * @s: the pcmcia_socket where the CardBus device is located
  52. *
  53. * cb_alloc() allocates the kernel data structures for a Cardbus device
  54. * and handles the lowest level PCI device setup issues.
  55. */
  56. int __ref cb_alloc(struct pcmcia_socket *s)
  57. {
  58. struct pci_bus *bus = s->cb_dev->subordinate;
  59. struct pci_dev *dev;
  60. unsigned int max, pass;
  61. pci_lock_rescan_remove();
  62. s->functions = pci_scan_slot(bus, PCI_DEVFN(0, 0));
  63. pci_fixup_cardbus(bus);
  64. max = bus->busn_res.start;
  65. for (pass = 0; pass < 2; pass++)
  66. list_for_each_entry(dev, &bus->devices, bus_list)
  67. if (pci_is_bridge(dev))
  68. max = pci_scan_bridge(bus, dev, max, pass);
  69. /*
  70. * Size all resources below the CardBus controller.
  71. */
  72. pci_bus_size_bridges(bus);
  73. pci_bus_assign_resources(bus);
  74. cardbus_config_irq_and_cls(bus, s->pci_irq);
  75. /* socket specific tune function */
  76. if (s->tune_bridge)
  77. s->tune_bridge(s, bus);
  78. pci_bus_add_devices(bus);
  79. pci_unlock_rescan_remove();
  80. return 0;
  81. }
  82. /**
  83. * cb_free() - remove CardBus device
  84. * @s: the pcmcia_socket where the CardBus device was located
  85. *
  86. * cb_free() handles the lowest level PCI device cleanup.
  87. */
  88. void cb_free(struct pcmcia_socket *s)
  89. {
  90. struct pci_dev *bridge, *dev, *tmp;
  91. struct pci_bus *bus;
  92. bridge = s->cb_dev;
  93. if (!bridge)
  94. return;
  95. bus = bridge->subordinate;
  96. if (!bus)
  97. return;
  98. pci_lock_rescan_remove();
  99. list_for_each_entry_safe(dev, tmp, &bus->devices, bus_list)
  100. pci_stop_and_remove_bus_device(dev);
  101. pci_unlock_rescan_remove();
  102. }