xref: /openbmc/qemu/hw/sd/sdhci-pci.c (revision b69c3c21a5d11075d42100d5cfe0a736593fae6b)
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 
30ce864603SThomas Huth static void sdhci_pci_realize(PCIDevice *dev, Error **errp)
31ce864603SThomas Huth {
32ce864603SThomas Huth     SDHCIState *s = PCI_SDHCI(dev);
33ce864603SThomas Huth     Error *local_err = NULL;
34ce864603SThomas Huth 
35ce864603SThomas Huth     sdhci_initfn(s);
36ce864603SThomas Huth     sdhci_common_realize(s, &local_err);
37ce864603SThomas Huth     if (local_err) {
38ce864603SThomas Huth         error_propagate(errp, local_err);
39ce864603SThomas Huth         return;
40ce864603SThomas Huth     }
41ce864603SThomas Huth 
42ce864603SThomas Huth     dev->config[PCI_CLASS_PROG] = 0x01; /* Standard Host supported DMA */
43ce864603SThomas Huth     dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */
44ce864603SThomas Huth     s->irq = pci_allocate_irq(dev);
45ce864603SThomas Huth     s->dma_as = pci_get_address_space(dev);
46ce864603SThomas Huth     pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->iomem);
47ce864603SThomas Huth }
48ce864603SThomas Huth 
49ce864603SThomas Huth static void sdhci_pci_exit(PCIDevice *dev)
50ce864603SThomas Huth {
51ce864603SThomas Huth     SDHCIState *s = PCI_SDHCI(dev);
52ce864603SThomas Huth 
53*b69c3c21SMarkus Armbruster     sdhci_common_unrealize(s);
54ce864603SThomas Huth     sdhci_uninitfn(s);
55ce864603SThomas Huth }
56ce864603SThomas Huth 
57ce864603SThomas Huth static void sdhci_pci_class_init(ObjectClass *klass, void *data)
58ce864603SThomas Huth {
59ce864603SThomas Huth     DeviceClass *dc = DEVICE_CLASS(klass);
60ce864603SThomas Huth     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
61ce864603SThomas Huth 
62ce864603SThomas Huth     k->realize = sdhci_pci_realize;
63ce864603SThomas Huth     k->exit = sdhci_pci_exit;
64ce864603SThomas Huth     k->vendor_id = PCI_VENDOR_ID_REDHAT;
65ce864603SThomas Huth     k->device_id = PCI_DEVICE_ID_REDHAT_SDHCI;
66ce864603SThomas Huth     k->class_id = PCI_CLASS_SYSTEM_SDHCI;
674f67d30bSMarc-André Lureau     device_class_set_props(dc, sdhci_pci_properties);
68ce864603SThomas Huth 
69ce864603SThomas Huth     sdhci_common_class_init(klass, data);
70ce864603SThomas Huth }
71ce864603SThomas Huth 
72ce864603SThomas Huth static const TypeInfo sdhci_pci_info = {
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     },
81ce864603SThomas Huth };
82ce864603SThomas Huth 
83ce864603SThomas Huth static void sdhci_pci_register_type(void)
84ce864603SThomas Huth {
85ce864603SThomas Huth     type_register_static(&sdhci_pci_info);
86ce864603SThomas Huth }
87ce864603SThomas Huth 
88ce864603SThomas Huth type_init(sdhci_pci_register_type)
89