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
1461f3c91aSChetan Pant * version 2.1 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
25ec150c7eSMarkus Armbruster #include "hw/ppc/spapr.h"
26*32cad1ffSPhilippe Mathieu-Daudé #include "system/dma.h"
277678b74aSDavid Gibson #include "hw/irq.h"
28db1015e9SEduardo Habkost #include "qom/object.h"
29ee86dfeeSDavid Gibson
303954d33aSAnthony Liguori #define TYPE_VIO_SPAPR_DEVICE "vio-spapr-device"
31c821774aSEduardo Habkost OBJECT_DECLARE_TYPE(SpaprVioDevice, SpaprVioDeviceClass,
3230b5707cSEduardo Habkost VIO_SPAPR_DEVICE)
333954d33aSAnthony Liguori
340d936928SAnthony Liguori #define TYPE_SPAPR_VIO_BUS "spapr-vio-bus"
358063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(SpaprVioBus, SPAPR_VIO_BUS)
360d936928SAnthony Liguori
37215e2098SCao jin #define TYPE_SPAPR_VIO_BRIDGE "spapr-vio-bridge"
38b45d63b6SBen Herrenschmidt
39ce2918cbSDavid Gibson typedef struct SpaprVioCrq {
40b45d63b6SBen Herrenschmidt uint64_t qladdr;
41b45d63b6SBen Herrenschmidt uint32_t qsize;
42b45d63b6SBen Herrenschmidt uint32_t qnext;
43ce2918cbSDavid Gibson int(*SendFunc)(struct SpaprVioDevice *vdev, uint8_t *crq);
44ce2918cbSDavid Gibson } SpaprVioCrq;
45b45d63b6SBen Herrenschmidt
463954d33aSAnthony Liguori
47db1015e9SEduardo Habkost struct SpaprVioDeviceClass {
483954d33aSAnthony Liguori DeviceClass parent_class;
493954d33aSAnthony Liguori
503954d33aSAnthony Liguori const char *dt_name, *dt_type, *dt_compatible;
513954d33aSAnthony Liguori target_ulong signal_mask;
52ad0ebb91SDavid Gibson uint32_t rtce_window_size;
53ce2918cbSDavid Gibson void (*realize)(SpaprVioDevice *dev, Error **errp);
54ce2918cbSDavid Gibson void (*reset)(SpaprVioDevice *dev);
55ce2918cbSDavid Gibson int (*devnode)(SpaprVioDevice *dev, void *fdt, int node_off);
56864674faSStefan Berger const char *(*get_dt_compatible)(SpaprVioDevice *dev);
57db1015e9SEduardo Habkost };
583954d33aSAnthony Liguori
59ce2918cbSDavid Gibson struct SpaprVioDevice {
604040ab72SDavid Gibson DeviceState qdev;
614040ab72SDavid Gibson uint32_t reg;
62a307d594SAlexey Kardashevskiy uint32_t irq;
63cbd62f86SPaolo Bonzini uint64_t signal_state;
64ce2918cbSDavid Gibson SpaprVioCrq crq;
6596478592SPaolo Bonzini AddressSpace as;
66ee9a569aSAlexey Kardashevskiy MemoryRegion mrroot;
67ee9a569aSAlexey Kardashevskiy MemoryRegion mrbypass;
68ce2918cbSDavid Gibson SpaprTceTable *tcet;
693954d33aSAnthony Liguori };
704040ab72SDavid Gibson
71ad0ebb91SDavid Gibson #define DEFINE_SPAPR_PROPERTIES(type, field) \
72ad0ebb91SDavid Gibson DEFINE_PROP_UINT32("reg", type, field.reg, -1)
7377c7ea5eSPaolo Bonzini
74ce2918cbSDavid Gibson struct SpaprVioBus {
754040ab72SDavid Gibson BusState bus;
76d601fac4SDavid Gibson uint32_t next_reg;
773954d33aSAnthony Liguori };
784040ab72SDavid Gibson
79aeb7a330SGreg Kurz SpaprVioBus *spapr_vio_bus_init(void);
80aeb7a330SGreg Kurz SpaprVioDevice *spapr_vio_find_by_reg(SpaprVioBus *bus, uint32_t reg);
81ce2918cbSDavid Gibson void spapr_dt_vdevice(SpaprVioBus *bus, void *fdt);
82aeb7a330SGreg Kurz gchar *spapr_vio_stdout_path(SpaprVioBus *bus);
834040ab72SDavid Gibson
spapr_vio_irq_pulse(SpaprVioDevice * dev)847678b74aSDavid Gibson static inline void spapr_vio_irq_pulse(SpaprVioDevice *dev)
85a307d594SAlexey Kardashevskiy {
86ce2918cbSDavid Gibson SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
8728e02042SDavid Gibson
887678b74aSDavid Gibson qemu_irq_pulse(spapr_qirq(spapr, dev->irq));
89a307d594SAlexey Kardashevskiy }
90a307d594SAlexey Kardashevskiy
spapr_vio_dma_valid(SpaprVioDevice * dev,uint64_t taddr,uint32_t size,DMADirection dir)91ce2918cbSDavid Gibson static inline bool spapr_vio_dma_valid(SpaprVioDevice *dev, uint64_t taddr,
92ad0ebb91SDavid Gibson uint32_t size, DMADirection dir)
93ad0ebb91SDavid Gibson {
947ccb391cSPhilippe Mathieu-Daudé return dma_memory_valid(&dev->as, taddr, size, dir, MEMTXATTRS_UNSPECIFIED);
95ad0ebb91SDavid Gibson }
96ee86dfeeSDavid Gibson
spapr_vio_dma_read(SpaprVioDevice * dev,uint64_t taddr,void * buf,uint32_t size)97ce2918cbSDavid Gibson static inline int spapr_vio_dma_read(SpaprVioDevice *dev, uint64_t taddr,
98ad0ebb91SDavid Gibson void *buf, uint32_t size)
99ad0ebb91SDavid Gibson {
100ba06fe8aSPhilippe Mathieu-Daudé return (dma_memory_read(&dev->as, taddr,
101ba06fe8aSPhilippe Mathieu-Daudé buf, size, MEMTXATTRS_UNSPECIFIED) != 0) ?
102ad0ebb91SDavid Gibson H_DEST_PARM : H_SUCCESS;
103ad0ebb91SDavid Gibson }
104ad0ebb91SDavid Gibson
spapr_vio_dma_write(SpaprVioDevice * dev,uint64_t taddr,const void * buf,uint32_t size)105ce2918cbSDavid Gibson static inline int spapr_vio_dma_write(SpaprVioDevice *dev, uint64_t taddr,
106ad0ebb91SDavid Gibson const void *buf, uint32_t size)
107ad0ebb91SDavid Gibson {
108ba06fe8aSPhilippe Mathieu-Daudé return (dma_memory_write(&dev->as, taddr,
109ba06fe8aSPhilippe Mathieu-Daudé buf, size, MEMTXATTRS_UNSPECIFIED) != 0) ?
110ad0ebb91SDavid Gibson H_DEST_PARM : H_SUCCESS;
111ad0ebb91SDavid Gibson }
112ad0ebb91SDavid Gibson
spapr_vio_dma_set(SpaprVioDevice * dev,uint64_t taddr,uint8_t c,uint32_t size)113ce2918cbSDavid Gibson static inline int spapr_vio_dma_set(SpaprVioDevice *dev, uint64_t taddr,
114ad0ebb91SDavid Gibson uint8_t c, uint32_t size)
115ad0ebb91SDavid Gibson {
1167a36e42dSPhilippe Mathieu-Daudé return (dma_memory_set(&dev->as, taddr,
1177a36e42dSPhilippe Mathieu-Daudé c, size, MEMTXATTRS_UNSPECIFIED) != 0) ?
118ad0ebb91SDavid Gibson H_DEST_PARM : H_SUCCESS;
119ad0ebb91SDavid Gibson }
120ad0ebb91SDavid Gibson
1212280c27aSPhilippe Mathieu-Daudé #define vio_stb(_dev, _addr, _val) \
1222280c27aSPhilippe Mathieu-Daudé (stb_dma(&(_dev)->as, (_addr), (_val), MEMTXATTRS_UNSPECIFIED))
1232280c27aSPhilippe Mathieu-Daudé #define vio_sth(_dev, _addr, _val) \
1242280c27aSPhilippe Mathieu-Daudé (stw_be_dma(&(_dev)->as, (_addr), (_val), MEMTXATTRS_UNSPECIFIED))
1252280c27aSPhilippe Mathieu-Daudé #define vio_stl(_dev, _addr, _val) \
1262280c27aSPhilippe Mathieu-Daudé (stl_be_dma(&(_dev)->as, (_addr), (_val), MEMTXATTRS_UNSPECIFIED))
1272280c27aSPhilippe Mathieu-Daudé #define vio_stq(_dev, _addr, _val) \
1282280c27aSPhilippe Mathieu-Daudé (stq_be_dma(&(_dev)->as, (_addr), (_val), MEMTXATTRS_UNSPECIFIED))
12934cdea1dSPhilippe Mathieu-Daudé #define vio_ldq(_dev, _addr) \
130cd1db8dfSPhilippe Mathieu-Daudé ({ \
131cd1db8dfSPhilippe Mathieu-Daudé uint64_t _val; \
132cd1db8dfSPhilippe Mathieu-Daudé ldq_be_dma(&(_dev)->as, (_addr), &_val, MEMTXATTRS_UNSPECIFIED); \
133cd1db8dfSPhilippe Mathieu-Daudé _val; \
134cd1db8dfSPhilippe Mathieu-Daudé })
135ee86dfeeSDavid Gibson
136ce2918cbSDavid Gibson int spapr_vio_send_crq(SpaprVioDevice *dev, uint8_t *crq);
137b45d63b6SBen Herrenschmidt
138ce2918cbSDavid Gibson SpaprVioDevice *vty_lookup(SpaprMachineState *spapr, target_ulong reg);
139ce2918cbSDavid Gibson void vty_putchars(SpaprVioDevice *sdev, uint8_t *buf, int len);
140ce2918cbSDavid Gibson void spapr_vty_create(SpaprVioBus *bus, Chardev *chardev);
141ce2918cbSDavid Gibson void spapr_vlan_create(SpaprVioBus *bus, NICInfo *nd);
142ce2918cbSDavid Gibson void spapr_vscsi_create(SpaprVioBus *bus);
1436e270446SBen Herrenschmidt
144ce2918cbSDavid Gibson SpaprVioDevice *spapr_vty_get_default(SpaprVioBus *bus);
14568f3a94cSDavid Gibson
146b368a7d8SDavid Gibson extern const VMStateDescription vmstate_spapr_vio;
147b368a7d8SDavid Gibson
148b368a7d8SDavid Gibson #define VMSTATE_SPAPR_VIO(_f, _s) \
149ce2918cbSDavid Gibson VMSTATE_STRUCT(_f, _s, 0, vmstate_spapr_vio, SpaprVioDevice)
150b368a7d8SDavid Gibson
151ce2918cbSDavid Gibson void spapr_vio_set_bypass(SpaprVioDevice *dev, bool bypass);
152ee9a569aSAlexey Kardashevskiy
1532a6a4076SMarkus Armbruster #endif /* HW_SPAPR_VIO_H */
154