xref: /qemu/tests/qtest/libqos/sdhci.h (revision 1cf4323e)
1*1cf4323eSThomas Huth /*
2*1cf4323eSThomas Huth  * libqos driver framework
3*1cf4323eSThomas Huth  *
4*1cf4323eSThomas Huth  * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
5*1cf4323eSThomas Huth  *
6*1cf4323eSThomas Huth  * This library is free software; you can redistribute it and/or
7*1cf4323eSThomas Huth  * modify it under the terms of the GNU Lesser General Public
8*1cf4323eSThomas Huth  * License version 2 as published by the Free Software Foundation.
9*1cf4323eSThomas Huth  *
10*1cf4323eSThomas Huth  * This library is distributed in the hope that it will be useful,
11*1cf4323eSThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*1cf4323eSThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*1cf4323eSThomas Huth  * Lesser General Public License for more details.
14*1cf4323eSThomas Huth  *
15*1cf4323eSThomas Huth  * You should have received a copy of the GNU Lesser General Public
16*1cf4323eSThomas Huth  * License along with this library; if not, see <http://www.gnu.org/licenses/>
17*1cf4323eSThomas Huth  */
18*1cf4323eSThomas Huth 
19*1cf4323eSThomas Huth #ifndef QGRAPH_QSDHCI_H
20*1cf4323eSThomas Huth #define QGRAPH_QSDHCI_H
21*1cf4323eSThomas Huth 
22*1cf4323eSThomas Huth #include "libqos/qgraph.h"
23*1cf4323eSThomas Huth #include "pci.h"
24*1cf4323eSThomas Huth 
25*1cf4323eSThomas Huth typedef struct QSDHCI QSDHCI;
26*1cf4323eSThomas Huth typedef struct QSDHCI_MemoryMapped QSDHCI_MemoryMapped;
27*1cf4323eSThomas Huth typedef struct QSDHCI_PCI  QSDHCI_PCI;
28*1cf4323eSThomas Huth typedef struct QSDHCIProperties QSDHCIProperties;
29*1cf4323eSThomas Huth 
30*1cf4323eSThomas Huth /* Properties common to all QSDHCI devices */
31*1cf4323eSThomas Huth struct QSDHCIProperties {
32*1cf4323eSThomas Huth     uint8_t version;
33*1cf4323eSThomas Huth     uint8_t baseclock;
34*1cf4323eSThomas Huth     struct {
35*1cf4323eSThomas Huth         bool sdma;
36*1cf4323eSThomas Huth         uint64_t reg;
37*1cf4323eSThomas Huth     } capab;
38*1cf4323eSThomas Huth };
39*1cf4323eSThomas Huth 
40*1cf4323eSThomas Huth struct QSDHCI {
41*1cf4323eSThomas Huth     uint16_t (*readw)(QSDHCI *s, uint32_t reg);
42*1cf4323eSThomas Huth     uint64_t (*readq)(QSDHCI *s, uint32_t reg);
43*1cf4323eSThomas Huth     void (*writeq)(QSDHCI *s, uint32_t reg, uint64_t val);
44*1cf4323eSThomas Huth     QSDHCIProperties props;
45*1cf4323eSThomas Huth };
46*1cf4323eSThomas Huth 
47*1cf4323eSThomas Huth /* Memory Mapped implementation of QSDHCI */
48*1cf4323eSThomas Huth struct QSDHCI_MemoryMapped {
49*1cf4323eSThomas Huth     QOSGraphObject obj;
50*1cf4323eSThomas Huth     QTestState *qts;
51*1cf4323eSThomas Huth     QSDHCI sdhci;
52*1cf4323eSThomas Huth     uint64_t addr;
53*1cf4323eSThomas Huth };
54*1cf4323eSThomas Huth 
55*1cf4323eSThomas Huth /* PCI implementation of QSDHCI */
56*1cf4323eSThomas Huth struct QSDHCI_PCI {
57*1cf4323eSThomas Huth     QOSGraphObject obj;
58*1cf4323eSThomas Huth     QPCIDevice dev;
59*1cf4323eSThomas Huth     QSDHCI sdhci;
60*1cf4323eSThomas Huth     QPCIBar mem_bar;
61*1cf4323eSThomas Huth };
62*1cf4323eSThomas Huth 
63*1cf4323eSThomas Huth /**
64*1cf4323eSThomas Huth  * qos_init_sdhci_mm(): external constructor used by all drivers/machines
65*1cf4323eSThomas Huth  * that "contain" a #QSDHCI_MemoryMapped driver
66*1cf4323eSThomas Huth  */
67*1cf4323eSThomas Huth void qos_init_sdhci_mm(QSDHCI_MemoryMapped *sdhci, QTestState *qts,
68*1cf4323eSThomas Huth                        uint32_t addr, QSDHCIProperties *common);
69*1cf4323eSThomas Huth 
70*1cf4323eSThomas Huth #endif
71