xref: /qemu/include/hw/ppc/spapr_vio.h (revision db1015e92e04835c9eb50c29625fe566d1202dbd)
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 
25ec150c7eSMarkus Armbruster #include "hw/ppc/spapr.h"
269c17d615SPaolo Bonzini #include "sysemu/dma.h"
277678b74aSDavid Gibson #include "hw/irq.h"
28*db1015e9SEduardo Habkost #include "qom/object.h"
29ee86dfeeSDavid Gibson 
303954d33aSAnthony Liguori #define TYPE_VIO_SPAPR_DEVICE "vio-spapr-device"
31*db1015e9SEduardo Habkost typedef struct SpaprVioDevice SpaprVioDevice;
32*db1015e9SEduardo Habkost typedef struct SpaprVioDeviceClass SpaprVioDeviceClass;
333954d33aSAnthony Liguori #define VIO_SPAPR_DEVICE(obj) \
34ce2918cbSDavid Gibson      OBJECT_CHECK(SpaprVioDevice, (obj), TYPE_VIO_SPAPR_DEVICE)
353954d33aSAnthony Liguori #define VIO_SPAPR_DEVICE_CLASS(klass) \
36ce2918cbSDavid Gibson      OBJECT_CLASS_CHECK(SpaprVioDeviceClass, (klass), TYPE_VIO_SPAPR_DEVICE)
373954d33aSAnthony Liguori #define VIO_SPAPR_DEVICE_GET_CLASS(obj) \
38ce2918cbSDavid Gibson      OBJECT_GET_CLASS(SpaprVioDeviceClass, (obj), TYPE_VIO_SPAPR_DEVICE)
393954d33aSAnthony Liguori 
400d936928SAnthony Liguori #define TYPE_SPAPR_VIO_BUS "spapr-vio-bus"
41*db1015e9SEduardo Habkost typedef struct SpaprVioBus SpaprVioBus;
42ce2918cbSDavid Gibson #define SPAPR_VIO_BUS(obj) OBJECT_CHECK(SpaprVioBus, (obj), TYPE_SPAPR_VIO_BUS)
430d936928SAnthony Liguori 
44215e2098SCao jin #define TYPE_SPAPR_VIO_BRIDGE "spapr-vio-bridge"
45b45d63b6SBen Herrenschmidt 
46ce2918cbSDavid Gibson typedef struct SpaprVioCrq {
47b45d63b6SBen Herrenschmidt     uint64_t qladdr;
48b45d63b6SBen Herrenschmidt     uint32_t qsize;
49b45d63b6SBen Herrenschmidt     uint32_t qnext;
50ce2918cbSDavid Gibson     int(*SendFunc)(struct SpaprVioDevice *vdev, uint8_t *crq);
51ce2918cbSDavid Gibson } SpaprVioCrq;
52b45d63b6SBen Herrenschmidt 
533954d33aSAnthony Liguori 
54*db1015e9SEduardo Habkost struct SpaprVioDeviceClass {
553954d33aSAnthony Liguori     DeviceClass parent_class;
563954d33aSAnthony Liguori 
573954d33aSAnthony Liguori     const char *dt_name, *dt_type, *dt_compatible;
583954d33aSAnthony Liguori     target_ulong signal_mask;
59ad0ebb91SDavid Gibson     uint32_t rtce_window_size;
60ce2918cbSDavid Gibson     void (*realize)(SpaprVioDevice *dev, Error **errp);
61ce2918cbSDavid Gibson     void (*reset)(SpaprVioDevice *dev);
62ce2918cbSDavid Gibson     int (*devnode)(SpaprVioDevice *dev, void *fdt, int node_off);
63864674faSStefan Berger     const char *(*get_dt_compatible)(SpaprVioDevice *dev);
64*db1015e9SEduardo Habkost };
653954d33aSAnthony Liguori 
66ce2918cbSDavid Gibson struct SpaprVioDevice {
674040ab72SDavid Gibson     DeviceState qdev;
684040ab72SDavid Gibson     uint32_t reg;
69a307d594SAlexey Kardashevskiy     uint32_t irq;
70cbd62f86SPaolo Bonzini     uint64_t signal_state;
71ce2918cbSDavid Gibson     SpaprVioCrq crq;
7296478592SPaolo Bonzini     AddressSpace as;
73ee9a569aSAlexey Kardashevskiy     MemoryRegion mrroot;
74ee9a569aSAlexey Kardashevskiy     MemoryRegion mrbypass;
75ce2918cbSDavid Gibson     SpaprTceTable *tcet;
763954d33aSAnthony Liguori };
774040ab72SDavid Gibson 
78ad0ebb91SDavid Gibson #define DEFINE_SPAPR_PROPERTIES(type, field)           \
79ad0ebb91SDavid Gibson         DEFINE_PROP_UINT32("reg", type, field.reg, -1)
8077c7ea5eSPaolo Bonzini 
81ce2918cbSDavid Gibson struct SpaprVioBus {
824040ab72SDavid Gibson     BusState bus;
83d601fac4SDavid Gibson     uint32_t next_reg;
843954d33aSAnthony Liguori };
854040ab72SDavid Gibson 
86aeb7a330SGreg Kurz SpaprVioBus *spapr_vio_bus_init(void);
87aeb7a330SGreg Kurz SpaprVioDevice *spapr_vio_find_by_reg(SpaprVioBus *bus, uint32_t reg);
88ce2918cbSDavid Gibson void spapr_dt_vdevice(SpaprVioBus *bus, void *fdt);
89aeb7a330SGreg Kurz gchar *spapr_vio_stdout_path(SpaprVioBus *bus);
904040ab72SDavid Gibson 
917678b74aSDavid Gibson static inline void spapr_vio_irq_pulse(SpaprVioDevice *dev)
92a307d594SAlexey Kardashevskiy {
93ce2918cbSDavid Gibson     SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
9428e02042SDavid Gibson 
957678b74aSDavid Gibson     qemu_irq_pulse(spapr_qirq(spapr, dev->irq));
96a307d594SAlexey Kardashevskiy }
97a307d594SAlexey Kardashevskiy 
98ce2918cbSDavid Gibson static inline bool spapr_vio_dma_valid(SpaprVioDevice *dev, uint64_t taddr,
99ad0ebb91SDavid Gibson                                        uint32_t size, DMADirection dir)
100ad0ebb91SDavid Gibson {
101df32fd1cSPaolo Bonzini     return dma_memory_valid(&dev->as, taddr, size, dir);
102ad0ebb91SDavid Gibson }
103ee86dfeeSDavid Gibson 
104ce2918cbSDavid Gibson static inline int spapr_vio_dma_read(SpaprVioDevice *dev, uint64_t taddr,
105ad0ebb91SDavid Gibson                                      void *buf, uint32_t size)
106ad0ebb91SDavid Gibson {
107df32fd1cSPaolo Bonzini     return (dma_memory_read(&dev->as, taddr, buf, size) != 0) ?
108ad0ebb91SDavid Gibson         H_DEST_PARM : H_SUCCESS;
109ad0ebb91SDavid Gibson }
110ad0ebb91SDavid Gibson 
111ce2918cbSDavid Gibson static inline int spapr_vio_dma_write(SpaprVioDevice *dev, uint64_t taddr,
112ad0ebb91SDavid Gibson                                       const void *buf, uint32_t size)
113ad0ebb91SDavid Gibson {
114df32fd1cSPaolo Bonzini     return (dma_memory_write(&dev->as, taddr, buf, size) != 0) ?
115ad0ebb91SDavid Gibson         H_DEST_PARM : H_SUCCESS;
116ad0ebb91SDavid Gibson }
117ad0ebb91SDavid Gibson 
118ce2918cbSDavid Gibson static inline int spapr_vio_dma_set(SpaprVioDevice *dev, uint64_t taddr,
119ad0ebb91SDavid Gibson                                     uint8_t c, uint32_t size)
120ad0ebb91SDavid Gibson {
121df32fd1cSPaolo Bonzini     return (dma_memory_set(&dev->as, taddr, c, size) != 0) ?
122ad0ebb91SDavid Gibson         H_DEST_PARM : H_SUCCESS;
123ad0ebb91SDavid Gibson }
124ad0ebb91SDavid Gibson 
125df32fd1cSPaolo Bonzini #define vio_stb(_dev, _addr, _val) (stb_dma(&(_dev)->as, (_addr), (_val)))
126df32fd1cSPaolo Bonzini #define vio_sth(_dev, _addr, _val) (stw_be_dma(&(_dev)->as, (_addr), (_val)))
127df32fd1cSPaolo Bonzini #define vio_stl(_dev, _addr, _val) (stl_be_dma(&(_dev)->as, (_addr), (_val)))
128df32fd1cSPaolo Bonzini #define vio_stq(_dev, _addr, _val) (stq_be_dma(&(_dev)->as, (_addr), (_val)))
129df32fd1cSPaolo Bonzini #define vio_ldq(_dev, _addr) (ldq_be_dma(&(_dev)->as, (_addr)))
130ee86dfeeSDavid Gibson 
131ce2918cbSDavid Gibson int spapr_vio_send_crq(SpaprVioDevice *dev, uint8_t *crq);
132b45d63b6SBen Herrenschmidt 
133ce2918cbSDavid Gibson SpaprVioDevice *vty_lookup(SpaprMachineState *spapr, target_ulong reg);
134ce2918cbSDavid Gibson void vty_putchars(SpaprVioDevice *sdev, uint8_t *buf, int len);
135ce2918cbSDavid Gibson void spapr_vty_create(SpaprVioBus *bus, Chardev *chardev);
136ce2918cbSDavid Gibson void spapr_vlan_create(SpaprVioBus *bus, NICInfo *nd);
137ce2918cbSDavid Gibson void spapr_vscsi_create(SpaprVioBus *bus);
1386e270446SBen Herrenschmidt 
139ce2918cbSDavid Gibson SpaprVioDevice *spapr_vty_get_default(SpaprVioBus *bus);
14068f3a94cSDavid Gibson 
141b368a7d8SDavid Gibson extern const VMStateDescription vmstate_spapr_vio;
142b368a7d8SDavid Gibson 
143b368a7d8SDavid Gibson #define VMSTATE_SPAPR_VIO(_f, _s) \
144ce2918cbSDavid Gibson     VMSTATE_STRUCT(_f, _s, 0, vmstate_spapr_vio, SpaprVioDevice)
145b368a7d8SDavid Gibson 
146ce2918cbSDavid Gibson void spapr_vio_set_bypass(SpaprVioDevice *dev, bool bypass);
147ee9a569aSAlexey Kardashevskiy 
1482a6a4076SMarkus Armbruster #endif /* HW_SPAPR_VIO_H */
149