xref: /qemu/tests/qtest/libqos/sdhci.h (revision a2ce7dbd)
11cf4323eSThomas Huth /*
21cf4323eSThomas Huth  * libqos driver framework
31cf4323eSThomas Huth  *
41cf4323eSThomas Huth  * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
51cf4323eSThomas Huth  *
61cf4323eSThomas Huth  * This library is free software; you can redistribute it and/or
71cf4323eSThomas Huth  * modify it under the terms of the GNU Lesser General Public
8dc0ad02dSThomas Huth  * License version 2.1 as published by the Free Software Foundation.
91cf4323eSThomas Huth  *
101cf4323eSThomas Huth  * This library is distributed in the hope that it will be useful,
111cf4323eSThomas Huth  * but WITHOUT ANY WARRANTY; without even the implied warranty of
121cf4323eSThomas Huth  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
131cf4323eSThomas Huth  * Lesser General Public License for more details.
141cf4323eSThomas Huth  *
151cf4323eSThomas Huth  * You should have received a copy of the GNU Lesser General Public
161cf4323eSThomas Huth  * License along with this library; if not, see <http://www.gnu.org/licenses/>
171cf4323eSThomas Huth  */
181cf4323eSThomas Huth 
191cf4323eSThomas Huth #ifndef QGRAPH_QSDHCI_H
201cf4323eSThomas Huth #define QGRAPH_QSDHCI_H
211cf4323eSThomas Huth 
22*a2ce7dbdSPaolo Bonzini #include "qgraph.h"
231cf4323eSThomas Huth #include "pci.h"
241cf4323eSThomas Huth 
251cf4323eSThomas Huth typedef struct QSDHCI QSDHCI;
261cf4323eSThomas Huth typedef struct QSDHCI_MemoryMapped QSDHCI_MemoryMapped;
271cf4323eSThomas Huth typedef struct QSDHCI_PCI  QSDHCI_PCI;
281cf4323eSThomas Huth typedef struct QSDHCIProperties QSDHCIProperties;
291cf4323eSThomas Huth 
301cf4323eSThomas Huth /* Properties common to all QSDHCI devices */
311cf4323eSThomas Huth struct QSDHCIProperties {
321cf4323eSThomas Huth     uint8_t version;
331cf4323eSThomas Huth     uint8_t baseclock;
341cf4323eSThomas Huth     struct {
351cf4323eSThomas Huth         bool sdma;
361cf4323eSThomas Huth         uint64_t reg;
371cf4323eSThomas Huth     } capab;
381cf4323eSThomas Huth };
391cf4323eSThomas Huth 
401cf4323eSThomas Huth struct QSDHCI {
411cf4323eSThomas Huth     uint16_t (*readw)(QSDHCI *s, uint32_t reg);
421cf4323eSThomas Huth     uint64_t (*readq)(QSDHCI *s, uint32_t reg);
431cf4323eSThomas Huth     void (*writeq)(QSDHCI *s, uint32_t reg, uint64_t val);
441cf4323eSThomas Huth     QSDHCIProperties props;
451cf4323eSThomas Huth };
461cf4323eSThomas Huth 
471cf4323eSThomas Huth /* Memory Mapped implementation of QSDHCI */
481cf4323eSThomas Huth struct QSDHCI_MemoryMapped {
491cf4323eSThomas Huth     QOSGraphObject obj;
501cf4323eSThomas Huth     QTestState *qts;
511cf4323eSThomas Huth     QSDHCI sdhci;
521cf4323eSThomas Huth     uint64_t addr;
531cf4323eSThomas Huth };
541cf4323eSThomas Huth 
551cf4323eSThomas Huth /* PCI implementation of QSDHCI */
561cf4323eSThomas Huth struct QSDHCI_PCI {
571cf4323eSThomas Huth     QOSGraphObject obj;
581cf4323eSThomas Huth     QPCIDevice dev;
591cf4323eSThomas Huth     QSDHCI sdhci;
601cf4323eSThomas Huth     QPCIBar mem_bar;
611cf4323eSThomas Huth };
621cf4323eSThomas Huth 
631cf4323eSThomas Huth /**
641cf4323eSThomas Huth  * qos_init_sdhci_mm(): external constructor used by all drivers/machines
651cf4323eSThomas Huth  * that "contain" a #QSDHCI_MemoryMapped driver
661cf4323eSThomas Huth  */
671cf4323eSThomas Huth void qos_init_sdhci_mm(QSDHCI_MemoryMapped *sdhci, QTestState *qts,
681cf4323eSThomas Huth                        uint32_t addr, QSDHCIProperties *common);
691cf4323eSThomas Huth 
701cf4323eSThomas Huth #endif
71