David Gibson | 4040ab7 | 2011-04-01 15:15:21 +1100 | [diff] [blame] | 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 | |
David Gibson | ee86dfe | 2011-04-01 15:15:28 +1100 | [diff] [blame] | 24 | #define SPAPR_VIO_TCE_PAGE_SHIFT 12 |
| 25 | #define SPAPR_VIO_TCE_PAGE_SIZE (1ULL << SPAPR_VIO_TCE_PAGE_SHIFT) |
| 26 | #define SPAPR_VIO_TCE_PAGE_MASK (SPAPR_VIO_TCE_PAGE_SIZE - 1) |
| 27 | |
| 28 | enum VIOsPAPR_TCEAccess { |
| 29 | SPAPR_TCE_FAULT = 0, |
| 30 | SPAPR_TCE_RO = 1, |
| 31 | SPAPR_TCE_WO = 2, |
| 32 | SPAPR_TCE_RW = 3, |
| 33 | }; |
| 34 | |
David Gibson | b4a7852 | 2011-04-19 11:54:52 +1000 | [diff] [blame] | 35 | #define SPAPR_VTY_BASE_ADDRESS 0x30000000 |
| 36 | |
Anthony Liguori | 3954d33 | 2011-12-15 16:31:06 -0600 | [diff] [blame] | 37 | #define TYPE_VIO_SPAPR_DEVICE "vio-spapr-device" |
| 38 | #define VIO_SPAPR_DEVICE(obj) \ |
| 39 | OBJECT_CHECK(VIOsPAPRDevice, (obj), TYPE_VIO_SPAPR_DEVICE) |
| 40 | #define VIO_SPAPR_DEVICE_CLASS(klass) \ |
| 41 | OBJECT_CLASS_CHECK(VIOsPAPRDeviceClass, (klass), TYPE_VIO_SPAPR_DEVICE) |
| 42 | #define VIO_SPAPR_DEVICE_GET_CLASS(obj) \ |
| 43 | OBJECT_GET_CLASS(VIOsPAPRDeviceClass, (obj), TYPE_VIO_SPAPR_DEVICE) |
| 44 | |
Ben Herrenschmidt | b45d63b | 2011-04-01 15:15:30 +1100 | [diff] [blame] | 45 | struct VIOsPAPRDevice; |
| 46 | |
David Gibson | ee86dfe | 2011-04-01 15:15:28 +1100 | [diff] [blame] | 47 | typedef struct VIOsPAPR_RTCE { |
| 48 | uint64_t tce; |
| 49 | } VIOsPAPR_RTCE; |
| 50 | |
Ben Herrenschmidt | b45d63b | 2011-04-01 15:15:30 +1100 | [diff] [blame] | 51 | typedef struct VIOsPAPR_CRQ { |
| 52 | uint64_t qladdr; |
| 53 | uint32_t qsize; |
| 54 | uint32_t qnext; |
| 55 | int(*SendFunc)(struct VIOsPAPRDevice *vdev, uint8_t *crq); |
| 56 | } VIOsPAPR_CRQ; |
| 57 | |
Anthony Liguori | 3954d33 | 2011-12-15 16:31:06 -0600 | [diff] [blame] | 58 | typedef struct VIOsPAPRDevice VIOsPAPRDevice; |
| 59 | typedef struct VIOsPAPRBus VIOsPAPRBus; |
| 60 | |
| 61 | typedef struct VIOsPAPRDeviceClass { |
| 62 | DeviceClass parent_class; |
| 63 | |
| 64 | const char *dt_name, *dt_type, *dt_compatible; |
| 65 | target_ulong signal_mask; |
| 66 | int (*init)(VIOsPAPRDevice *dev); |
| 67 | void (*hcalls)(VIOsPAPRBus *bus); |
| 68 | int (*devnode)(VIOsPAPRDevice *dev, void *fdt, int node_off); |
| 69 | } VIOsPAPRDeviceClass; |
| 70 | |
| 71 | struct VIOsPAPRDevice { |
David Gibson | 4040ab7 | 2011-04-01 15:15:21 +1100 | [diff] [blame] | 72 | DeviceState qdev; |
| 73 | uint32_t reg; |
Ben Herrenschmidt | 08942ac | 2011-04-01 15:15:32 +1100 | [diff] [blame] | 74 | uint32_t flags; |
| 75 | #define VIO_PAPR_FLAG_DMA_BYPASS 0x1 |
David Gibson | 00dc738 | 2011-04-01 15:15:26 +1100 | [diff] [blame] | 76 | qemu_irq qirq; |
| 77 | uint32_t vio_irq_num; |
| 78 | target_ulong signal_state; |
David Gibson | ee86dfe | 2011-04-01 15:15:28 +1100 | [diff] [blame] | 79 | uint32_t rtce_window_size; |
| 80 | VIOsPAPR_RTCE *rtce_table; |
David Gibson | 0f5cb29 | 2011-09-29 21:39:12 +0000 | [diff] [blame] | 81 | int kvmtce_fd; |
Ben Herrenschmidt | b45d63b | 2011-04-01 15:15:30 +1100 | [diff] [blame] | 82 | VIOsPAPR_CRQ crq; |
Anthony Liguori | 3954d33 | 2011-12-15 16:31:06 -0600 | [diff] [blame] | 83 | }; |
David Gibson | 4040ab7 | 2011-04-01 15:15:21 +1100 | [diff] [blame] | 84 | |
Paolo Bonzini | 77c7ea5 | 2011-05-26 11:52:45 +0200 | [diff] [blame] | 85 | #define DEFINE_SPAPR_PROPERTIES(type, field, default_reg, default_dma_window) \ |
| 86 | DEFINE_PROP_UINT32("reg", type, field.reg, default_reg), \ |
| 87 | DEFINE_PROP_UINT32("dma-window", type, field.rtce_window_size, \ |
| 88 | default_dma_window) |
| 89 | |
Anthony Liguori | 3954d33 | 2011-12-15 16:31:06 -0600 | [diff] [blame] | 90 | struct VIOsPAPRBus { |
David Gibson | 4040ab7 | 2011-04-01 15:15:21 +1100 | [diff] [blame] | 91 | BusState bus; |
David Gibson | 4040ab7 | 2011-04-01 15:15:21 +1100 | [diff] [blame] | 92 | const char *dt_name, *dt_type, *dt_compatible; |
David Gibson | 00dc738 | 2011-04-01 15:15:26 +1100 | [diff] [blame] | 93 | target_ulong signal_mask; |
David Gibson | 4040ab7 | 2011-04-01 15:15:21 +1100 | [diff] [blame] | 94 | int (*init)(VIOsPAPRDevice *dev); |
David Gibson | 4040ab7 | 2011-04-01 15:15:21 +1100 | [diff] [blame] | 95 | int (*devnode)(VIOsPAPRDevice *dev, void *fdt, int node_off); |
Anthony Liguori | 3954d33 | 2011-12-15 16:31:06 -0600 | [diff] [blame] | 96 | }; |
David Gibson | 4040ab7 | 2011-04-01 15:15:21 +1100 | [diff] [blame] | 97 | |
| 98 | extern VIOsPAPRBus *spapr_vio_bus_init(void); |
| 99 | extern VIOsPAPRDevice *spapr_vio_find_by_reg(VIOsPAPRBus *bus, uint32_t reg); |
David Gibson | 4040ab7 | 2011-04-01 15:15:21 +1100 | [diff] [blame] | 100 | extern int spapr_populate_vdevice(VIOsPAPRBus *bus, void *fdt); |
David Gibson | 68f3a94 | 2011-12-13 15:24:34 +1100 | [diff] [blame] | 101 | extern int spapr_populate_chosen_stdout(void *fdt, VIOsPAPRBus *bus); |
David Gibson | 4040ab7 | 2011-04-01 15:15:21 +1100 | [diff] [blame] | 102 | |
David Gibson | 00dc738 | 2011-04-01 15:15:26 +1100 | [diff] [blame] | 103 | extern int spapr_vio_signal(VIOsPAPRDevice *dev, target_ulong mode); |
| 104 | |
David Gibson | ee86dfe | 2011-04-01 15:15:28 +1100 | [diff] [blame] | 105 | int spapr_vio_check_tces(VIOsPAPRDevice *dev, target_ulong ioba, |
| 106 | target_ulong len, |
| 107 | enum VIOsPAPR_TCEAccess access); |
| 108 | |
| 109 | int spapr_tce_dma_read(VIOsPAPRDevice *dev, uint64_t taddr, |
| 110 | void *buf, uint32_t size); |
| 111 | int spapr_tce_dma_write(VIOsPAPRDevice *dev, uint64_t taddr, |
| 112 | const void *buf, uint32_t size); |
| 113 | int spapr_tce_dma_zero(VIOsPAPRDevice *dev, uint64_t taddr, uint32_t size); |
| 114 | void stb_tce(VIOsPAPRDevice *dev, uint64_t taddr, uint8_t val); |
| 115 | void sth_tce(VIOsPAPRDevice *dev, uint64_t taddr, uint16_t val); |
| 116 | void stw_tce(VIOsPAPRDevice *dev, uint64_t taddr, uint32_t val); |
| 117 | void stq_tce(VIOsPAPRDevice *dev, uint64_t taddr, uint64_t val); |
| 118 | uint64_t ldq_tce(VIOsPAPRDevice *dev, uint64_t taddr); |
| 119 | |
Ben Herrenschmidt | b45d63b | 2011-04-01 15:15:30 +1100 | [diff] [blame] | 120 | int spapr_vio_send_crq(VIOsPAPRDevice *dev, uint8_t *crq); |
| 121 | |
David Gibson | 4040ab7 | 2011-04-01 15:15:21 +1100 | [diff] [blame] | 122 | void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len); |
Paolo Bonzini | 277f9ac | 2011-05-26 11:52:44 +0200 | [diff] [blame] | 123 | void spapr_vty_create(VIOsPAPRBus *bus, uint32_t reg, CharDriverState *chardev); |
| 124 | void spapr_vlan_create(VIOsPAPRBus *bus, uint32_t reg, NICInfo *nd); |
| 125 | void spapr_vscsi_create(VIOsPAPRBus *bus, uint32_t reg); |
Ben Herrenschmidt | 6e27044 | 2011-04-01 15:15:31 +1100 | [diff] [blame] | 126 | |
David Gibson | 68f3a94 | 2011-12-13 15:24:34 +1100 | [diff] [blame] | 127 | VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus); |
| 128 | |
Ben Herrenschmidt | 08942ac | 2011-04-01 15:15:32 +1100 | [diff] [blame] | 129 | int spapr_tce_set_bypass(uint32_t unit, uint32_t enable); |
| 130 | void spapr_vio_quiesce(void); |
| 131 | |
David Gibson | 4040ab7 | 2011-04-01 15:15:21 +1100 | [diff] [blame] | 132 | #endif /* _HW_SPAPR_VIO_H */ |