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