spapr_vio.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.1 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. #include "hw/ppc/spapr.h"
  24. #include "system/dma.h"
  25. #include "hw/irq.h"
  26. #include "qom/object.h"
  27. #define TYPE_VIO_SPAPR_DEVICE "vio-spapr-device"
  28. OBJECT_DECLARE_TYPE(SpaprVioDevice, SpaprVioDeviceClass,
  29. VIO_SPAPR_DEVICE)
  30. #define TYPE_SPAPR_VIO_BUS "spapr-vio-bus"
  31. OBJECT_DECLARE_SIMPLE_TYPE(SpaprVioBus, SPAPR_VIO_BUS)
  32. #define TYPE_SPAPR_VIO_BRIDGE "spapr-vio-bridge"
  33. typedef struct SpaprVioCrq {
  34. uint64_t qladdr;
  35. uint32_t qsize;
  36. uint32_t qnext;
  37. int(*SendFunc)(struct SpaprVioDevice *vdev, uint8_t *crq);
  38. } SpaprVioCrq;
  39. struct SpaprVioDeviceClass {
  40. DeviceClass parent_class;
  41. const char *dt_name, *dt_type, *dt_compatible;
  42. target_ulong signal_mask;
  43. uint32_t rtce_window_size;
  44. void (*realize)(SpaprVioDevice *dev, Error **errp);
  45. void (*reset)(SpaprVioDevice *dev);
  46. int (*devnode)(SpaprVioDevice *dev, void *fdt, int node_off);
  47. const char *(*get_dt_compatible)(SpaprVioDevice *dev);
  48. };
  49. struct SpaprVioDevice {
  50. DeviceState qdev;
  51. uint32_t reg;
  52. uint32_t irq;
  53. uint64_t signal_state;
  54. SpaprVioCrq crq;
  55. AddressSpace as;
  56. MemoryRegion mrroot;
  57. MemoryRegion mrbypass;
  58. SpaprTceTable *tcet;
  59. };
  60. #define DEFINE_SPAPR_PROPERTIES(type, field) \
  61. DEFINE_PROP_UINT32("reg", type, field.reg, -1)
  62. struct SpaprVioBus {
  63. BusState bus;
  64. uint32_t next_reg;
  65. };
  66. SpaprVioBus *spapr_vio_bus_init(void);
  67. SpaprVioDevice *spapr_vio_find_by_reg(SpaprVioBus *bus, uint32_t reg);
  68. void spapr_dt_vdevice(SpaprVioBus *bus, void *fdt);
  69. gchar *spapr_vio_stdout_path(SpaprVioBus *bus);
  70. static inline void spapr_vio_irq_pulse(SpaprVioDevice *dev)
  71. {
  72. SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
  73. qemu_irq_pulse(spapr_qirq(spapr, dev->irq));
  74. }
  75. static inline bool spapr_vio_dma_valid(SpaprVioDevice *dev, uint64_t taddr,
  76. uint32_t size, DMADirection dir)
  77. {
  78. return dma_memory_valid(&dev->as, taddr, size, dir, MEMTXATTRS_UNSPECIFIED);
  79. }
  80. static inline int spapr_vio_dma_read(SpaprVioDevice *dev, uint64_t taddr,
  81. void *buf, uint32_t size)
  82. {
  83. return (dma_memory_read(&dev->as, taddr,
  84. buf, size, MEMTXATTRS_UNSPECIFIED) != 0) ?
  85. H_DEST_PARM : H_SUCCESS;
  86. }
  87. static inline int spapr_vio_dma_write(SpaprVioDevice *dev, uint64_t taddr,
  88. const void *buf, uint32_t size)
  89. {
  90. return (dma_memory_write(&dev->as, taddr,
  91. buf, size, MEMTXATTRS_UNSPECIFIED) != 0) ?
  92. H_DEST_PARM : H_SUCCESS;
  93. }
  94. static inline int spapr_vio_dma_set(SpaprVioDevice *dev, uint64_t taddr,
  95. uint8_t c, uint32_t size)
  96. {
  97. return (dma_memory_set(&dev->as, taddr,
  98. c, size, MEMTXATTRS_UNSPECIFIED) != 0) ?
  99. H_DEST_PARM : H_SUCCESS;
  100. }
  101. #define vio_stb(_dev, _addr, _val) \
  102. (stb_dma(&(_dev)->as, (_addr), (_val), MEMTXATTRS_UNSPECIFIED))
  103. #define vio_sth(_dev, _addr, _val) \
  104. (stw_be_dma(&(_dev)->as, (_addr), (_val), MEMTXATTRS_UNSPECIFIED))
  105. #define vio_stl(_dev, _addr, _val) \
  106. (stl_be_dma(&(_dev)->as, (_addr), (_val), MEMTXATTRS_UNSPECIFIED))
  107. #define vio_stq(_dev, _addr, _val) \
  108. (stq_be_dma(&(_dev)->as, (_addr), (_val), MEMTXATTRS_UNSPECIFIED))
  109. #define vio_ldq(_dev, _addr) \
  110. ({ \
  111. uint64_t _val; \
  112. ldq_be_dma(&(_dev)->as, (_addr), &_val, MEMTXATTRS_UNSPECIFIED); \
  113. _val; \
  114. })
  115. int spapr_vio_send_crq(SpaprVioDevice *dev, uint8_t *crq);
  116. SpaprVioDevice *vty_lookup(SpaprMachineState *spapr, target_ulong reg);
  117. void vty_putchars(SpaprVioDevice *sdev, uint8_t *buf, int len);
  118. void spapr_vty_create(SpaprVioBus *bus, Chardev *chardev);
  119. void spapr_vlan_create(SpaprVioBus *bus, NICInfo *nd);
  120. void spapr_vscsi_create(SpaprVioBus *bus);
  121. SpaprVioDevice *spapr_vty_get_default(SpaprVioBus *bus);
  122. extern const VMStateDescription vmstate_spapr_vio;
  123. #define VMSTATE_SPAPR_VIO(_f, _s) \
  124. VMSTATE_STRUCT(_f, _s, 0, vmstate_spapr_vio, SpaprVioDevice)
  125. void spapr_vio_set_bypass(SpaprVioDevice *dev, bool bypass);
  126. #endif /* HW_SPAPR_VIO_H */