sdhci-pci.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * SDHCI device on PCI
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. * See the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "qemu/osdep.h"
  18. #include "qapi/error.h"
  19. #include "qemu/module.h"
  20. #include "hw/qdev-properties.h"
  21. #include "hw/sd/sdhci.h"
  22. #include "sdhci-internal.h"
  23. static Property sdhci_pci_properties[] = {
  24. DEFINE_SDHCI_COMMON_PROPERTIES(SDHCIState),
  25. DEFINE_PROP_END_OF_LIST(),
  26. };
  27. static void sdhci_pci_realize(PCIDevice *dev, Error **errp)
  28. {
  29. SDHCIState *s = PCI_SDHCI(dev);
  30. Error *local_err = NULL;
  31. sdhci_initfn(s);
  32. sdhci_common_realize(s, &local_err);
  33. if (local_err) {
  34. error_propagate(errp, local_err);
  35. return;
  36. }
  37. dev->config[PCI_CLASS_PROG] = 0x01; /* Standard Host supported DMA */
  38. dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */
  39. s->irq = pci_allocate_irq(dev);
  40. s->dma_as = pci_get_address_space(dev);
  41. pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->iomem);
  42. }
  43. static void sdhci_pci_exit(PCIDevice *dev)
  44. {
  45. SDHCIState *s = PCI_SDHCI(dev);
  46. sdhci_common_unrealize(s, &error_abort);
  47. sdhci_uninitfn(s);
  48. }
  49. static void sdhci_pci_class_init(ObjectClass *klass, void *data)
  50. {
  51. DeviceClass *dc = DEVICE_CLASS(klass);
  52. PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
  53. k->realize = sdhci_pci_realize;
  54. k->exit = sdhci_pci_exit;
  55. k->vendor_id = PCI_VENDOR_ID_REDHAT;
  56. k->device_id = PCI_DEVICE_ID_REDHAT_SDHCI;
  57. k->class_id = PCI_CLASS_SYSTEM_SDHCI;
  58. dc->props = sdhci_pci_properties;
  59. sdhci_common_class_init(klass, data);
  60. }
  61. static const TypeInfo sdhci_pci_info = {
  62. .name = TYPE_PCI_SDHCI,
  63. .parent = TYPE_PCI_DEVICE,
  64. .instance_size = sizeof(SDHCIState),
  65. .class_init = sdhci_pci_class_init,
  66. .interfaces = (InterfaceInfo[]) {
  67. { INTERFACE_CONVENTIONAL_PCI_DEVICE },
  68. { },
  69. },
  70. };
  71. static void sdhci_pci_register_type(void)
  72. {
  73. type_register_static(&sdhci_pci_info);
  74. }
  75. type_init(sdhci_pci_register_type)