1 #ifndef _HW_SPAPR_VIO_H 2 #define _HW_SPAPR_VIO_H 3 /* 4 * QEMU sPAPR VIO bus definitions 5 * 6 * Copyright (c) 2010 David Gibson, IBM Corporation <david@gibson.dropbear.id.au> 7 * Based on the s390 virtio bus definitions: 8 * Copyright (c) 2009 Alexander Graf <agraf@suse.de> 9 * 10 * This library is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Lesser General Public 12 * License as published by the Free Software Foundation; either 13 * version 2 of the License, or (at your option) any later version. 14 * 15 * This library is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; if not, see <http://www.gnu.org/licenses/>. 22 */ 23 24 #include "sysemu/dma.h" 25 26 #define TYPE_VIO_SPAPR_DEVICE "vio-spapr-device" 27 #define VIO_SPAPR_DEVICE(obj) \ 28 OBJECT_CHECK(VIOsPAPRDevice, (obj), TYPE_VIO_SPAPR_DEVICE) 29 #define VIO_SPAPR_DEVICE_CLASS(klass) \ 30 OBJECT_CLASS_CHECK(VIOsPAPRDeviceClass, (klass), TYPE_VIO_SPAPR_DEVICE) 31 #define VIO_SPAPR_DEVICE_GET_CLASS(obj) \ 32 OBJECT_GET_CLASS(VIOsPAPRDeviceClass, (obj), TYPE_VIO_SPAPR_DEVICE) 33 34 #define TYPE_SPAPR_VIO_BUS "spapr-vio-bus" 35 #define SPAPR_VIO_BUS(obj) OBJECT_CHECK(VIOsPAPRBus, (obj), TYPE_SPAPR_VIO_BUS) 36 37 #define TYPE_SPAPR_VIO_BRIDGE "spapr-vio-bridge" 38 39 typedef struct VIOsPAPR_CRQ { 40 uint64_t qladdr; 41 uint32_t qsize; 42 uint32_t qnext; 43 int(*SendFunc)(struct VIOsPAPRDevice *vdev, uint8_t *crq); 44 } VIOsPAPR_CRQ; 45 46 typedef struct VIOsPAPRDevice VIOsPAPRDevice; 47 typedef struct VIOsPAPRBus VIOsPAPRBus; 48 49 typedef struct VIOsPAPRDeviceClass { 50 DeviceClass parent_class; 51 52 const char *dt_name, *dt_type, *dt_compatible; 53 target_ulong signal_mask; 54 uint32_t rtce_window_size; 55 void (*realize)(VIOsPAPRDevice *dev, Error **errp); 56 void (*reset)(VIOsPAPRDevice *dev); 57 int (*devnode)(VIOsPAPRDevice *dev, void *fdt, int node_off); 58 } VIOsPAPRDeviceClass; 59 60 struct VIOsPAPRDevice { 61 DeviceState qdev; 62 uint32_t reg; 63 uint32_t irq; 64 uint64_t signal_state; 65 VIOsPAPR_CRQ crq; 66 AddressSpace as; 67 MemoryRegion mrroot; 68 MemoryRegion mrbypass; 69 sPAPRTCETable *tcet; 70 }; 71 72 #define DEFINE_SPAPR_PROPERTIES(type, field) \ 73 DEFINE_PROP_UINT32("reg", type, field.reg, -1) 74 75 struct VIOsPAPRBus { 76 BusState bus; 77 uint32_t next_reg; 78 int (*init)(VIOsPAPRDevice *dev); 79 int (*devnode)(VIOsPAPRDevice *dev, void *fdt, int node_off); 80 }; 81 82 extern VIOsPAPRBus *spapr_vio_bus_init(void); 83 extern VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg); 84 extern int spapr_populate_vdevice(VIOsPAPRBus *bus, void *fdt); 85 extern int spapr_populate_chosen_stdout(void *fdt, VIOsPAPRBus *bus); 86 87 extern int spapr_vio_signal(VIOsPAPRDevice *dev, target_ulong mode); 88 89 static inline qemu_irq spapr_vio_qirq(VIOsPAPRDevice *dev) 90 { 91 sPAPRMachineState *spapr = SPAPR_MACHINE(qdev_get_machine()); 92 93 return xics_get_qirq(spapr->xics, dev->irq); 94 } 95 96 static inline bool spapr_vio_dma_valid(VIOsPAPRDevice *dev, uint64_t taddr, 97 uint32_t size, DMADirection dir) 98 { 99 return dma_memory_valid(&dev->as, taddr, size, dir); 100 } 101 102 static inline int spapr_vio_dma_read(VIOsPAPRDevice *dev, uint64_t taddr, 103 void *buf, uint32_t size) 104 { 105 return (dma_memory_read(&dev->as, taddr, buf, size) != 0) ? 106 H_DEST_PARM : H_SUCCESS; 107 } 108 109 static inline int spapr_vio_dma_write(VIOsPAPRDevice *dev, uint64_t taddr, 110 const void *buf, uint32_t size) 111 { 112 return (dma_memory_write(&dev->as, taddr, buf, size) != 0) ? 113 H_DEST_PARM : H_SUCCESS; 114 } 115 116 static inline int spapr_vio_dma_set(VIOsPAPRDevice *dev, uint64_t taddr, 117 uint8_t c, uint32_t size) 118 { 119 return (dma_memory_set(&dev->as, taddr, c, size) != 0) ? 120 H_DEST_PARM : H_SUCCESS; 121 } 122 123 #define vio_stb(_dev, _addr, _val) (stb_dma(&(_dev)->as, (_addr), (_val))) 124 #define vio_sth(_dev, _addr, _val) (stw_be_dma(&(_dev)->as, (_addr), (_val))) 125 #define vio_stl(_dev, _addr, _val) (stl_be_dma(&(_dev)->as, (_addr), (_val))) 126 #define vio_stq(_dev, _addr, _val) (stq_be_dma(&(_dev)->as, (_addr), (_val))) 127 #define vio_ldq(_dev, _addr) (ldq_be_dma(&(_dev)->as, (_addr))) 128 129 int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq); 130 131 VIOsPAPRDevice *vty_lookup(sPAPRMachineState *spapr, target_ulong reg); 132 void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len); 133 void spapr_vty_create(VIOsPAPRBus *bus, CharDriverState *chardev); 134 void spapr_vlan_create(VIOsPAPRBus *bus, NICInfo *nd); 135 void spapr_vscsi_create(VIOsPAPRBus *bus); 136 137 VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus); 138 139 void spapr_vio_quiesce(void); 140 141 extern const VMStateDescription vmstate_spapr_vio; 142 143 #define VMSTATE_SPAPR_VIO(_f, _s) \ 144 VMSTATE_STRUCT(_f, _s, 0, vmstate_spapr_vio, VIOsPAPRDevice) 145 146 void spapr_vio_set_bypass(VIOsPAPRDevice *dev, bool bypass); 147 148 #endif /* _HW_SPAPR_VIO_H */ 149