xref: /qemu/hw/sd/sdhci-pci.c (revision 70ce076fa6dff60585c229a4b641b13e64bf03cf)
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 
18 #include "qemu/osdep.h"
19 #include "qapi/error.h"
20 #include "qemu/module.h"
21 #include "hw/qdev-properties.h"
22 #include "hw/sd/sdhci.h"
23 #include "sdhci-internal.h"
24 
25 static const Property sdhci_pci_properties[] = {
26     DEFINE_SDHCI_COMMON_PROPERTIES(SDHCIState),
27 };
28 
29 static void sdhci_pci_realize(PCIDevice *dev, Error **errp)
30 {
31     ERRP_GUARD();
32     SDHCIState *s = PCI_SDHCI(dev);
33 
34     sdhci_initfn(s);
35     sdhci_common_realize(s, errp);
36     if (*errp) {
37         return;
38     }
39 
40     dev->config[PCI_CLASS_PROG] = 0x01; /* Standard Host supported DMA */
41     dev->config[PCI_INTERRUPT_PIN] = 0x01; /* interrupt pin A */
42     s->irq = pci_allocate_irq(dev);
43     s->dma_as = pci_get_address_space(dev);
44     pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->iomem);
45 }
46 
47 static void sdhci_pci_exit(PCIDevice *dev)
48 {
49     SDHCIState *s = PCI_SDHCI(dev);
50 
51     sdhci_common_unrealize(s);
52     sdhci_uninitfn(s);
53 }
54 
55 static void sdhci_pci_class_init(ObjectClass *klass, void *data)
56 {
57     DeviceClass *dc = DEVICE_CLASS(klass);
58     PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
59 
60     k->realize = sdhci_pci_realize;
61     k->exit = sdhci_pci_exit;
62     k->vendor_id = PCI_VENDOR_ID_REDHAT;
63     k->device_id = PCI_DEVICE_ID_REDHAT_SDHCI;
64     k->class_id = PCI_CLASS_SYSTEM_SDHCI;
65     device_class_set_props(dc, sdhci_pci_properties);
66 
67     sdhci_common_class_init(klass, data);
68 }
69 
70 static const TypeInfo sdhci_pci_types[] = {
71     {
72         .name           = TYPE_PCI_SDHCI,
73         .parent         = TYPE_PCI_DEVICE,
74         .instance_size  = sizeof(SDHCIState),
75         .class_init     = sdhci_pci_class_init,
76         .interfaces     = (InterfaceInfo[]) {
77             { INTERFACE_CONVENTIONAL_PCI_DEVICE },
78             { },
79         },
80     },
81 };
82 
83 DEFINE_TYPES(sdhci_pci_types)
84