xref: /qemu/include/hw/ppc/spapr_vio.h (revision 30b5707c269cac1ad80b72f777e52c8e08b2ff19)
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"
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,
32*30b5707cSEduardo Habkost                     VIO_SPAPR_DEVICE)
333954d33aSAnthony Liguori 
340d936928SAnthony Liguori #define TYPE_SPAPR_VIO_BUS "spapr-vio-bus"
35db1015e9SEduardo Habkost typedef struct SpaprVioBus SpaprVioBus;
368110fa1dSEduardo Habkost DECLARE_INSTANCE_CHECKER(SpaprVioBus, SPAPR_VIO_BUS,
378110fa1dSEduardo Habkost                          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 
483954d33aSAnthony Liguori 
49db1015e9SEduardo Habkost struct SpaprVioDeviceClass {
503954d33aSAnthony Liguori     DeviceClass parent_class;
513954d33aSAnthony Liguori 
523954d33aSAnthony Liguori     const char *dt_name, *dt_type, *dt_compatible;
533954d33aSAnthony Liguori     target_ulong signal_mask;
54ad0ebb91SDavid Gibson     uint32_t rtce_window_size;
55ce2918cbSDavid Gibson     void (*realize)(SpaprVioDevice *dev, Error **errp);
56ce2918cbSDavid Gibson     void (*reset)(SpaprVioDevice *dev);
57ce2918cbSDavid Gibson     int (*devnode)(SpaprVioDevice *dev, void *fdt, int node_off);
58864674faSStefan Berger     const char *(*get_dt_compatible)(SpaprVioDevice *dev);
59db1015e9SEduardo Habkost };
603954d33aSAnthony Liguori 
61ce2918cbSDavid Gibson struct SpaprVioDevice {
624040ab72SDavid Gibson     DeviceState qdev;
634040ab72SDavid Gibson     uint32_t reg;
64a307d594SAlexey Kardashevskiy     uint32_t irq;
65cbd62f86SPaolo Bonzini     uint64_t signal_state;
66ce2918cbSDavid Gibson     SpaprVioCrq crq;
6796478592SPaolo Bonzini     AddressSpace as;
68ee9a569aSAlexey Kardashevskiy     MemoryRegion mrroot;
69ee9a569aSAlexey Kardashevskiy     MemoryRegion mrbypass;
70ce2918cbSDavid Gibson     SpaprTceTable *tcet;
713954d33aSAnthony Liguori };
724040ab72SDavid Gibson 
73ad0ebb91SDavid Gibson #define DEFINE_SPAPR_PROPERTIES(type, field)           \
74ad0ebb91SDavid Gibson         DEFINE_PROP_UINT32("reg", type, field.reg, -1)
7577c7ea5eSPaolo Bonzini 
76ce2918cbSDavid Gibson struct SpaprVioBus {
774040ab72SDavid Gibson     BusState bus;
78d601fac4SDavid Gibson     uint32_t next_reg;
793954d33aSAnthony Liguori };
804040ab72SDavid Gibson 
81aeb7a330SGreg Kurz SpaprVioBus *spapr_vio_bus_init(void);
82aeb7a330SGreg Kurz SpaprVioDevice *spapr_vio_find_by_reg(SpaprVioBus *bus, uint32_t reg);
83ce2918cbSDavid Gibson void spapr_dt_vdevice(SpaprVioBus *bus, void *fdt);
84aeb7a330SGreg Kurz gchar *spapr_vio_stdout_path(SpaprVioBus *bus);
854040ab72SDavid Gibson 
867678b74aSDavid Gibson static inline void spapr_vio_irq_pulse(SpaprVioDevice *dev)
87a307d594SAlexey Kardashevskiy {
88ce2918cbSDavid Gibson     SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
8928e02042SDavid Gibson 
907678b74aSDavid Gibson     qemu_irq_pulse(spapr_qirq(spapr, dev->irq));
91a307d594SAlexey Kardashevskiy }
92a307d594SAlexey Kardashevskiy 
93ce2918cbSDavid Gibson static inline bool spapr_vio_dma_valid(SpaprVioDevice *dev, uint64_t taddr,
94ad0ebb91SDavid Gibson                                        uint32_t size, DMADirection dir)
95ad0ebb91SDavid Gibson {
96df32fd1cSPaolo Bonzini     return dma_memory_valid(&dev->as, taddr, size, dir);
97ad0ebb91SDavid Gibson }
98ee86dfeeSDavid Gibson 
99ce2918cbSDavid Gibson static inline int spapr_vio_dma_read(SpaprVioDevice *dev, uint64_t taddr,
100ad0ebb91SDavid Gibson                                      void *buf, uint32_t size)
101ad0ebb91SDavid Gibson {
102df32fd1cSPaolo Bonzini     return (dma_memory_read(&dev->as, taddr, buf, size) != 0) ?
103ad0ebb91SDavid Gibson         H_DEST_PARM : H_SUCCESS;
104ad0ebb91SDavid Gibson }
105ad0ebb91SDavid Gibson 
106ce2918cbSDavid Gibson static inline int spapr_vio_dma_write(SpaprVioDevice *dev, uint64_t taddr,
107ad0ebb91SDavid Gibson                                       const void *buf, uint32_t size)
108ad0ebb91SDavid Gibson {
109df32fd1cSPaolo Bonzini     return (dma_memory_write(&dev->as, taddr, buf, size) != 0) ?
110ad0ebb91SDavid Gibson         H_DEST_PARM : H_SUCCESS;
111ad0ebb91SDavid Gibson }
112ad0ebb91SDavid Gibson 
113ce2918cbSDavid Gibson static inline int spapr_vio_dma_set(SpaprVioDevice *dev, uint64_t taddr,
114ad0ebb91SDavid Gibson                                     uint8_t c, uint32_t size)
115ad0ebb91SDavid Gibson {
116df32fd1cSPaolo Bonzini     return (dma_memory_set(&dev->as, taddr, c, size) != 0) ?
117ad0ebb91SDavid Gibson         H_DEST_PARM : H_SUCCESS;
118ad0ebb91SDavid Gibson }
119ad0ebb91SDavid Gibson 
120df32fd1cSPaolo Bonzini #define vio_stb(_dev, _addr, _val) (stb_dma(&(_dev)->as, (_addr), (_val)))
121df32fd1cSPaolo Bonzini #define vio_sth(_dev, _addr, _val) (stw_be_dma(&(_dev)->as, (_addr), (_val)))
122df32fd1cSPaolo Bonzini #define vio_stl(_dev, _addr, _val) (stl_be_dma(&(_dev)->as, (_addr), (_val)))
123df32fd1cSPaolo Bonzini #define vio_stq(_dev, _addr, _val) (stq_be_dma(&(_dev)->as, (_addr), (_val)))
124df32fd1cSPaolo Bonzini #define vio_ldq(_dev, _addr) (ldq_be_dma(&(_dev)->as, (_addr)))
125ee86dfeeSDavid Gibson 
126ce2918cbSDavid Gibson int spapr_vio_send_crq(SpaprVioDevice *dev, uint8_t *crq);
127b45d63b6SBen Herrenschmidt 
128ce2918cbSDavid Gibson SpaprVioDevice *vty_lookup(SpaprMachineState *spapr, target_ulong reg);
129ce2918cbSDavid Gibson void vty_putchars(SpaprVioDevice *sdev, uint8_t *buf, int len);
130ce2918cbSDavid Gibson void spapr_vty_create(SpaprVioBus *bus, Chardev *chardev);
131ce2918cbSDavid Gibson void spapr_vlan_create(SpaprVioBus *bus, NICInfo *nd);
132ce2918cbSDavid Gibson void spapr_vscsi_create(SpaprVioBus *bus);
1336e270446SBen Herrenschmidt 
134ce2918cbSDavid Gibson SpaprVioDevice *spapr_vty_get_default(SpaprVioBus *bus);
13568f3a94cSDavid Gibson 
136b368a7d8SDavid Gibson extern const VMStateDescription vmstate_spapr_vio;
137b368a7d8SDavid Gibson 
138b368a7d8SDavid Gibson #define VMSTATE_SPAPR_VIO(_f, _s) \
139ce2918cbSDavid Gibson     VMSTATE_STRUCT(_f, _s, 0, vmstate_spapr_vio, SpaprVioDevice)
140b368a7d8SDavid Gibson 
141ce2918cbSDavid Gibson void spapr_vio_set_bypass(SpaprVioDevice *dev, bool bypass);
142ee9a569aSAlexey Kardashevskiy 
1432a6a4076SMarkus Armbruster #endif /* HW_SPAPR_VIO_H */
144