vio.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * IBM PowerPC Virtual I/O Infrastructure Support.
  4. *
  5. * Copyright (c) 2003 IBM Corp.
  6. * Dave Engebretsen [email protected]
  7. * Santiago Leon [email protected]
  8. */
  9. #ifndef _ASM_POWERPC_VIO_H
  10. #define _ASM_POWERPC_VIO_H
  11. #ifdef __KERNEL__
  12. #include <linux/errno.h>
  13. #include <linux/device.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/mod_devicetable.h>
  16. #include <linux/scatterlist.h>
  17. #include <asm/hvcall.h>
  18. /*
  19. * Architecture-specific constants for drivers to
  20. * extract attributes of the device using vio_get_attribute()
  21. */
  22. #define VETH_MAC_ADDR "local-mac-address"
  23. #define VETH_MCAST_FILTER_SIZE "ibm,mac-address-filters"
  24. /* End architecture-specific constants */
  25. #define h_vio_signal(ua, mode) \
  26. plpar_hcall_norets(H_VIO_SIGNAL, ua, mode)
  27. #define VIO_IRQ_DISABLE 0UL
  28. #define VIO_IRQ_ENABLE 1UL
  29. /*
  30. * VIO CMO minimum entitlement for all devices and spare entitlement
  31. */
  32. #define VIO_CMO_MIN_ENT 1562624
  33. extern struct bus_type vio_bus_type;
  34. struct iommu_table;
  35. /*
  36. * Platform Facilities Option (PFO)-specific data
  37. */
  38. /* Starting unit address for PFO devices on the VIO BUS */
  39. #define VIO_BASE_PFO_UA 0x50000000
  40. /**
  41. * vio_pfo_op - PFO operation parameters
  42. *
  43. * @flags: h_call subfunctions and modifiers
  44. * @in: Input data block logical real address
  45. * @inlen: If non-negative, the length of the input data block. If negative,
  46. * the length of the input data descriptor list in bytes.
  47. * @out: Output data block logical real address
  48. * @outlen: If non-negative, the length of the input data block. If negative,
  49. * the length of the input data descriptor list in bytes.
  50. * @csbcpb: Logical real address of the 4k naturally-aligned storage block
  51. * containing the CSB & optional FC field specific CPB
  52. * @timeout: # of milliseconds to retry h_call, 0 for no timeout.
  53. * @hcall_err: pointer to return the h_call return value, else NULL
  54. */
  55. struct vio_pfo_op {
  56. u64 flags;
  57. s64 in;
  58. s64 inlen;
  59. s64 out;
  60. s64 outlen;
  61. u64 csbcpb;
  62. void *done;
  63. unsigned long handle;
  64. unsigned int timeout;
  65. long hcall_err;
  66. };
  67. /* End PFO specific data */
  68. enum vio_dev_family {
  69. VDEVICE, /* The OF node is a child of /vdevice */
  70. PFO, /* The OF node is a child of /ibm,platform-facilities */
  71. };
  72. /**
  73. * vio_dev - This structure is used to describe virtual I/O devices.
  74. *
  75. * @desired: set from return of driver's get_desired_dma() function
  76. * @entitled: bytes of IO data that has been reserved for this device.
  77. * @allocated: bytes of IO data currently in use by the device.
  78. * @allocs_failed: number of DMA failures due to insufficient entitlement.
  79. */
  80. struct vio_dev {
  81. const char *name;
  82. const char *type;
  83. uint32_t unit_address;
  84. uint32_t resource_id;
  85. unsigned int irq;
  86. struct {
  87. size_t desired;
  88. size_t entitled;
  89. size_t allocated;
  90. atomic_t allocs_failed;
  91. } cmo;
  92. enum vio_dev_family family;
  93. struct device dev;
  94. };
  95. struct vio_driver {
  96. const char *name;
  97. const struct vio_device_id *id_table;
  98. int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
  99. void (*remove)(struct vio_dev *dev);
  100. void (*shutdown)(struct vio_dev *dev);
  101. /* A driver must have a get_desired_dma() function to
  102. * be loaded in a CMO environment if it uses DMA.
  103. */
  104. unsigned long (*get_desired_dma)(struct vio_dev *dev);
  105. const struct dev_pm_ops *pm;
  106. struct device_driver driver;
  107. };
  108. extern int __vio_register_driver(struct vio_driver *drv, struct module *owner,
  109. const char *mod_name);
  110. /*
  111. * vio_register_driver must be a macro so that KBUILD_MODNAME can be expanded
  112. */
  113. #define vio_register_driver(driver) \
  114. __vio_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
  115. extern void vio_unregister_driver(struct vio_driver *drv);
  116. extern int vio_cmo_entitlement_update(size_t);
  117. extern void vio_cmo_set_dev_desired(struct vio_dev *viodev, size_t desired);
  118. extern void vio_unregister_device(struct vio_dev *dev);
  119. extern int vio_h_cop_sync(struct vio_dev *vdev, struct vio_pfo_op *op);
  120. struct device_node;
  121. extern struct vio_dev *vio_register_device_node(
  122. struct device_node *node_vdev);
  123. extern const void *vio_get_attribute(struct vio_dev *vdev, char *which,
  124. int *length);
  125. #ifdef CONFIG_PPC_PSERIES
  126. extern struct vio_dev *vio_find_node(struct device_node *vnode);
  127. extern int vio_enable_interrupts(struct vio_dev *dev);
  128. extern int vio_disable_interrupts(struct vio_dev *dev);
  129. #else
  130. static inline int vio_enable_interrupts(struct vio_dev *dev)
  131. {
  132. return 0;
  133. }
  134. #endif
  135. static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
  136. {
  137. return container_of(drv, struct vio_driver, driver);
  138. }
  139. static inline struct vio_dev *to_vio_dev(struct device *dev)
  140. {
  141. return container_of(dev, struct vio_dev, dev);
  142. }
  143. #endif /* __KERNEL__ */
  144. #endif /* _ASM_POWERPC_VIO_H */