xref: /qemu/include/hw/ppc/spapr_vio.h (revision ec150c7e09071bcf51bfaa8071fe23efb6df69f7)
12a6a4076SMarkus Armbruster #ifndef HW_SPAPR_VIO_H
22a6a4076SMarkus Armbruster #define HW_SPAPR_VIO_H
32a6a4076SMarkus Armbruster 
44040ab72SDavid Gibson /*
54040ab72SDavid Gibson  * QEMU sPAPR VIO bus definitions
64040ab72SDavid Gibson  *
74040ab72SDavid Gibson  * Copyright (c) 2010 David Gibson, IBM Corporation <david@gibson.dropbear.id.au>
84040ab72SDavid Gibson  * Based on the s390 virtio bus definitions:
94040ab72SDavid Gibson  * Copyright (c) 2009 Alexander Graf <agraf@suse.de>
104040ab72SDavid Gibson  *
114040ab72SDavid Gibson  * This library is free software; you can redistribute it and/or
124040ab72SDavid Gibson  * modify it under the terms of the GNU Lesser General Public
134040ab72SDavid Gibson  * License as published by the Free Software Foundation; either
144040ab72SDavid Gibson  * version 2 of the License, or (at your option) any later version.
154040ab72SDavid Gibson  *
164040ab72SDavid Gibson  * This library is distributed in the hope that it will be useful,
174040ab72SDavid Gibson  * but WITHOUT ANY WARRANTY; without even the implied warranty of
184040ab72SDavid Gibson  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
194040ab72SDavid Gibson  * Lesser General Public License for more details.
204040ab72SDavid Gibson  *
214040ab72SDavid Gibson  * You should have received a copy of the GNU Lesser General Public
224040ab72SDavid Gibson  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
234040ab72SDavid Gibson  */
244040ab72SDavid Gibson 
25*ec150c7eSMarkus Armbruster #include "hw/ppc/spapr.h"
269c17d615SPaolo Bonzini #include "sysemu/dma.h"
27ee86dfeeSDavid Gibson 
283954d33aSAnthony Liguori #define TYPE_VIO_SPAPR_DEVICE "vio-spapr-device"
293954d33aSAnthony Liguori #define VIO_SPAPR_DEVICE(obj) \
30ce2918cbSDavid Gibson      OBJECT_CHECK(SpaprVioDevice, (obj), TYPE_VIO_SPAPR_DEVICE)
313954d33aSAnthony Liguori #define VIO_SPAPR_DEVICE_CLASS(klass) \
32ce2918cbSDavid Gibson      OBJECT_CLASS_CHECK(SpaprVioDeviceClass, (klass), TYPE_VIO_SPAPR_DEVICE)
333954d33aSAnthony Liguori #define VIO_SPAPR_DEVICE_GET_CLASS(obj) \
34ce2918cbSDavid Gibson      OBJECT_GET_CLASS(SpaprVioDeviceClass, (obj), TYPE_VIO_SPAPR_DEVICE)
353954d33aSAnthony Liguori 
360d936928SAnthony Liguori #define TYPE_SPAPR_VIO_BUS "spapr-vio-bus"
37ce2918cbSDavid Gibson #define SPAPR_VIO_BUS(obj) OBJECT_CHECK(SpaprVioBus, (obj), TYPE_SPAPR_VIO_BUS)
380d936928SAnthony Liguori 
39215e2098SCao jin #define TYPE_SPAPR_VIO_BRIDGE "spapr-vio-bridge"
40b45d63b6SBen Herrenschmidt 
41ce2918cbSDavid Gibson typedef struct SpaprVioCrq {
42b45d63b6SBen Herrenschmidt     uint64_t qladdr;
43b45d63b6SBen Herrenschmidt     uint32_t qsize;
44b45d63b6SBen Herrenschmidt     uint32_t qnext;
45ce2918cbSDavid Gibson     int(*SendFunc)(struct SpaprVioDevice *vdev, uint8_t *crq);
46ce2918cbSDavid Gibson } SpaprVioCrq;
47b45d63b6SBen Herrenschmidt 
48ce2918cbSDavid Gibson typedef struct SpaprVioDevice SpaprVioDevice;
49ce2918cbSDavid Gibson typedef struct SpaprVioBus SpaprVioBus;
503954d33aSAnthony Liguori 
51ce2918cbSDavid Gibson typedef struct SpaprVioDeviceClass {
523954d33aSAnthony Liguori     DeviceClass parent_class;
533954d33aSAnthony Liguori 
543954d33aSAnthony Liguori     const char *dt_name, *dt_type, *dt_compatible;
553954d33aSAnthony Liguori     target_ulong signal_mask;
56ad0ebb91SDavid Gibson     uint32_t rtce_window_size;
57ce2918cbSDavid Gibson     void (*realize)(SpaprVioDevice *dev, Error **errp);
58ce2918cbSDavid Gibson     void (*reset)(SpaprVioDevice *dev);
59ce2918cbSDavid Gibson     int (*devnode)(SpaprVioDevice *dev, void *fdt, int node_off);
60ce2918cbSDavid Gibson } SpaprVioDeviceClass;
613954d33aSAnthony Liguori 
62ce2918cbSDavid Gibson struct SpaprVioDevice {
634040ab72SDavid Gibson     DeviceState qdev;
644040ab72SDavid Gibson     uint32_t reg;
65a307d594SAlexey Kardashevskiy     uint32_t irq;
66cbd62f86SPaolo Bonzini     uint64_t signal_state;
67ce2918cbSDavid Gibson     SpaprVioCrq crq;
6896478592SPaolo Bonzini     AddressSpace as;
69ee9a569aSAlexey Kardashevskiy     MemoryRegion mrroot;
70ee9a569aSAlexey Kardashevskiy     MemoryRegion mrbypass;
71ce2918cbSDavid Gibson     SpaprTceTable *tcet;
723954d33aSAnthony Liguori };
734040ab72SDavid Gibson 
74ad0ebb91SDavid Gibson #define DEFINE_SPAPR_PROPERTIES(type, field)           \
75ad0ebb91SDavid Gibson         DEFINE_PROP_UINT32("reg", type, field.reg, -1)
7677c7ea5eSPaolo Bonzini 
77ce2918cbSDavid Gibson struct SpaprVioBus {
784040ab72SDavid Gibson     BusState bus;
79d601fac4SDavid Gibson     uint32_t next_reg;
803954d33aSAnthony Liguori };
814040ab72SDavid Gibson 
82ce2918cbSDavid Gibson extern SpaprVioBus *spapr_vio_bus_init(void);
83ce2918cbSDavid Gibson extern SpaprVioDevice *spapr_vio_find_by_reg(SpaprVioBus *bus, uint32_t reg);
84ce2918cbSDavid Gibson void spapr_dt_vdevice(SpaprVioBus *bus, void *fdt);
85ce2918cbSDavid Gibson extern gchar *spapr_vio_stdout_path(SpaprVioBus *bus);
864040ab72SDavid Gibson 
87ce2918cbSDavid Gibson static inline qemu_irq spapr_vio_qirq(SpaprVioDevice *dev)
88a307d594SAlexey Kardashevskiy {
89ce2918cbSDavid Gibson     SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
9028e02042SDavid Gibson 
9177183755SCédric Le Goater     return spapr_qirq(spapr, dev->irq);
92a307d594SAlexey Kardashevskiy }
93a307d594SAlexey Kardashevskiy 
94ce2918cbSDavid Gibson static inline bool spapr_vio_dma_valid(SpaprVioDevice *dev, uint64_t taddr,
95ad0ebb91SDavid Gibson                                        uint32_t size, DMADirection dir)
96ad0ebb91SDavid Gibson {
97df32fd1cSPaolo Bonzini     return dma_memory_valid(&dev->as, taddr, size, dir);
98ad0ebb91SDavid Gibson }
99ee86dfeeSDavid Gibson 
100ce2918cbSDavid Gibson static inline int spapr_vio_dma_read(SpaprVioDevice *dev, uint64_t taddr,
101ad0ebb91SDavid Gibson                                      void *buf, uint32_t size)
102ad0ebb91SDavid Gibson {
103df32fd1cSPaolo Bonzini     return (dma_memory_read(&dev->as, taddr, buf, size) != 0) ?
104ad0ebb91SDavid Gibson         H_DEST_PARM : H_SUCCESS;
105ad0ebb91SDavid Gibson }
106ad0ebb91SDavid Gibson 
107ce2918cbSDavid Gibson static inline int spapr_vio_dma_write(SpaprVioDevice *dev, uint64_t taddr,
108ad0ebb91SDavid Gibson                                       const void *buf, uint32_t size)
109ad0ebb91SDavid Gibson {
110df32fd1cSPaolo Bonzini     return (dma_memory_write(&dev->as, taddr, buf, size) != 0) ?
111ad0ebb91SDavid Gibson         H_DEST_PARM : H_SUCCESS;
112ad0ebb91SDavid Gibson }
113ad0ebb91SDavid Gibson 
114ce2918cbSDavid Gibson static inline int spapr_vio_dma_set(SpaprVioDevice *dev, uint64_t taddr,
115ad0ebb91SDavid Gibson                                     uint8_t c, uint32_t size)
116ad0ebb91SDavid Gibson {
117df32fd1cSPaolo Bonzini     return (dma_memory_set(&dev->as, taddr, c, size) != 0) ?
118ad0ebb91SDavid Gibson         H_DEST_PARM : H_SUCCESS;
119ad0ebb91SDavid Gibson }
120ad0ebb91SDavid Gibson 
121df32fd1cSPaolo Bonzini #define vio_stb(_dev, _addr, _val) (stb_dma(&(_dev)->as, (_addr), (_val)))
122df32fd1cSPaolo Bonzini #define vio_sth(_dev, _addr, _val) (stw_be_dma(&(_dev)->as, (_addr), (_val)))
123df32fd1cSPaolo Bonzini #define vio_stl(_dev, _addr, _val) (stl_be_dma(&(_dev)->as, (_addr), (_val)))
124df32fd1cSPaolo Bonzini #define vio_stq(_dev, _addr, _val) (stq_be_dma(&(_dev)->as, (_addr), (_val)))
125df32fd1cSPaolo Bonzini #define vio_ldq(_dev, _addr) (ldq_be_dma(&(_dev)->as, (_addr)))
126ee86dfeeSDavid Gibson 
127ce2918cbSDavid Gibson int spapr_vio_send_crq(SpaprVioDevice *dev, uint8_t *crq);
128b45d63b6SBen Herrenschmidt 
129ce2918cbSDavid Gibson SpaprVioDevice *vty_lookup(SpaprMachineState *spapr, target_ulong reg);
130ce2918cbSDavid Gibson void vty_putchars(SpaprVioDevice *sdev, uint8_t *buf, int len);
131ce2918cbSDavid Gibson void spapr_vty_create(SpaprVioBus *bus, Chardev *chardev);
132ce2918cbSDavid Gibson void spapr_vlan_create(SpaprVioBus *bus, NICInfo *nd);
133ce2918cbSDavid Gibson void spapr_vscsi_create(SpaprVioBus *bus);
1346e270446SBen Herrenschmidt 
135ce2918cbSDavid Gibson SpaprVioDevice *spapr_vty_get_default(SpaprVioBus *bus);
13668f3a94cSDavid Gibson 
137b368a7d8SDavid Gibson extern const VMStateDescription vmstate_spapr_vio;
138b368a7d8SDavid Gibson 
139b368a7d8SDavid Gibson #define VMSTATE_SPAPR_VIO(_f, _s) \
140ce2918cbSDavid Gibson     VMSTATE_STRUCT(_f, _s, 0, vmstate_spapr_vio, SpaprVioDevice)
141b368a7d8SDavid Gibson 
142ce2918cbSDavid Gibson void spapr_vio_set_bypass(SpaprVioDevice *dev, bool bypass);
143ee9a569aSAlexey Kardashevskiy 
1442a6a4076SMarkus Armbruster #endif /* HW_SPAPR_VIO_H */
145