vio.h 4.8 KB

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