intel_vtd.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2020 Intel Corporation
  3. * SPDX-License-Identifier: Apache-2.0
  4. */
  5. #ifndef ZEPHYR_INCLUDE_DRIVERS_INTEL_VTD_H_
  6. #define ZEPHYR_INCLUDE_DRIVERS_INTEL_VTD_H_
  7. #include <drivers/pcie/msi.h>
  8. typedef int (*vtd_alloc_entries_f)(const struct device *dev,
  9. uint8_t n_entries);
  10. typedef uint32_t (*vtd_remap_msi_f)(const struct device *dev,
  11. msi_vector_t *vector);
  12. typedef int (*vtd_remap_f)(const struct device *dev,
  13. msi_vector_t *vector);
  14. struct vtd_driver_api {
  15. vtd_alloc_entries_f allocate_entries;
  16. vtd_remap_msi_f remap_msi;
  17. vtd_remap_f remap;
  18. };
  19. /**
  20. * @brief Allocate contiguous IRTEs
  21. *
  22. * @param dev Pointer to the device structure for the driver instance
  23. * @param n_entries How many IRTE to allocate
  24. *
  25. * Note: It will try to allocate all, or it will fail.
  26. *
  27. * @return The first allocated IRTE index, or -EBUSY on failure
  28. */
  29. static inline int vtd_allocate_entries(const struct device *dev,
  30. uint8_t n_entries)
  31. {
  32. const struct vtd_driver_api *api =
  33. (const struct vtd_driver_api *)dev->api;
  34. return api->allocate_entries(dev, n_entries);
  35. }
  36. /**
  37. * @brief Generate the MSI Message Address data for the given vector
  38. *
  39. * @param dev Pointer to the device structure for the driver instance
  40. * @param vector A valid allocated MSI vector
  41. *
  42. * @return The MSI Message Address value
  43. */
  44. static inline uint32_t vtd_remap_msi(const struct device *dev,
  45. msi_vector_t *vector)
  46. {
  47. const struct vtd_driver_api *api =
  48. (const struct vtd_driver_api *)dev->api;
  49. return api->remap_msi(dev, vector);
  50. }
  51. /**
  52. * @brief Remap the given vector
  53. *
  54. * @param dev Pointer to the device structure for the driver instance
  55. * @param vector A valid allocated MSI vector
  56. *
  57. * @return 0 on success, a negative errno otherwise
  58. */
  59. static inline int vtd_remap(const struct device *dev,
  60. msi_vector_t *vector)
  61. {
  62. const struct vtd_driver_api *api =
  63. (const struct vtd_driver_api *)dev->api;
  64. return api->remap(dev, vector);
  65. }
  66. #endif /* ZEPHYR_INCLUDE_DRIVERS_INTEL_VTD_H_ */