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