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