pci-epc.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * pci-epc.h - PCI Endpoint *Controller* (EPC) header file
  3. *
  4. * Copyright (C) 2016 Texas Instruments
  5. * Author: Kishon Vijay Abraham I <kishon@ti.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 of
  9. * the License as published by the Free Software Foundation.
  10. */
  11. #ifndef __LINUX_PCI_EPC_H
  12. #define __LINUX_PCI_EPC_H
  13. #include <linux/pci-epf.h>
  14. struct pci_epc;
  15. enum pci_epc_irq_type {
  16. PCI_EPC_IRQ_UNKNOWN,
  17. PCI_EPC_IRQ_LEGACY,
  18. PCI_EPC_IRQ_MSI,
  19. };
  20. /**
  21. * struct pci_epc_ops - set of function pointers for performing EPC operations
  22. * @write_header: ops to populate configuration space header
  23. * @set_bar: ops to configure the BAR
  24. * @clear_bar: ops to reset the BAR
  25. * @map_addr: ops to map cpu address to pci address
  26. * @unmap_addr: ops to unmap cpu address and pci address
  27. * @set_msi: ops to set the requested number of MSI interrupts in the MSI
  28. * capability register
  29. * @get_msi: ops to get the number of MSI interrupts allocated by the RC from
  30. * the MSI capability register
  31. * @raise_irq: ops to raise a legacy or MSI interrupt
  32. * @start: ops to start the PCI link
  33. * @stop: ops to stop the PCI link
  34. * @owner: the module owner containing the ops
  35. */
  36. struct pci_epc_ops {
  37. int (*write_header)(struct pci_epc *pci_epc,
  38. struct pci_epf_header *hdr);
  39. int (*set_bar)(struct pci_epc *epc, enum pci_barno bar,
  40. dma_addr_t bar_phys, size_t size, int flags);
  41. void (*clear_bar)(struct pci_epc *epc, enum pci_barno bar);
  42. int (*map_addr)(struct pci_epc *epc, phys_addr_t addr,
  43. u64 pci_addr, size_t size);
  44. void (*unmap_addr)(struct pci_epc *epc, phys_addr_t addr);
  45. int (*set_msi)(struct pci_epc *epc, u8 interrupts);
  46. int (*get_msi)(struct pci_epc *epc);
  47. int (*raise_irq)(struct pci_epc *pci_epc,
  48. enum pci_epc_irq_type type, u8 interrupt_num);
  49. int (*start)(struct pci_epc *epc);
  50. void (*stop)(struct pci_epc *epc);
  51. struct module *owner;
  52. };
  53. /**
  54. * struct pci_epc_mem - address space of the endpoint controller
  55. * @phys_base: physical base address of the pci address space
  56. * @size: the size of the pci address space
  57. * @bitmap: bitmap to manage the pci address space
  58. * @pages: number of bits representing the address region
  59. * @page_size: size of each page
  60. */
  61. struct pci_epc_mem {
  62. phys_addr_t phys_base;
  63. size_t size;
  64. unsigned long *bitmap;
  65. size_t page_size;
  66. int pages;
  67. };
  68. /**
  69. * struct pci_epc - represents the PCI EPC device
  70. * @dev: PCI EPC device
  71. * @pci_epf: list of endpoint functions present in this EPC device
  72. * @ops: function pointers for performing endpoint operations
  73. * @mem: address space of the endpoint controller
  74. * @max_functions: max number of functions that can be configured in this EPC
  75. * @lock: spinlock to protect pci_epc ops
  76. */
  77. struct pci_epc {
  78. struct device dev;
  79. struct list_head pci_epf;
  80. const struct pci_epc_ops *ops;
  81. struct pci_epc_mem *mem;
  82. u8 max_functions;
  83. /* spinlock to protect against concurrent access of EP controller */
  84. spinlock_t lock;
  85. };
  86. #define to_pci_epc(device) container_of((device), struct pci_epc, dev)
  87. #define pci_epc_create(dev, ops) \
  88. __pci_epc_create((dev), (ops), THIS_MODULE)
  89. #define devm_pci_epc_create(dev, ops) \
  90. __devm_pci_epc_create((dev), (ops), THIS_MODULE)
  91. #define pci_epc_mem_init(epc, phys_addr, size) \
  92. __pci_epc_mem_init((epc), (phys_addr), (size), PAGE_SIZE)
  93. static inline void epc_set_drvdata(struct pci_epc *epc, void *data)
  94. {
  95. dev_set_drvdata(&epc->dev, data);
  96. }
  97. static inline void *epc_get_drvdata(struct pci_epc *epc)
  98. {
  99. return dev_get_drvdata(&epc->dev);
  100. }
  101. struct pci_epc *
  102. __devm_pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
  103. struct module *owner);
  104. struct pci_epc *
  105. __pci_epc_create(struct device *dev, const struct pci_epc_ops *ops,
  106. struct module *owner);
  107. void devm_pci_epc_destroy(struct device *dev, struct pci_epc *epc);
  108. void pci_epc_destroy(struct pci_epc *epc);
  109. int pci_epc_add_epf(struct pci_epc *epc, struct pci_epf *epf);
  110. void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf);
  111. void pci_epc_linkup(struct pci_epc *epc);
  112. int pci_epc_write_header(struct pci_epc *epc, struct pci_epf_header *hdr);
  113. int pci_epc_set_bar(struct pci_epc *epc, enum pci_barno bar,
  114. dma_addr_t bar_phys, size_t size, int flags);
  115. void pci_epc_clear_bar(struct pci_epc *epc, int bar);
  116. int pci_epc_map_addr(struct pci_epc *epc, phys_addr_t phys_addr,
  117. u64 pci_addr, size_t size);
  118. void pci_epc_unmap_addr(struct pci_epc *epc, phys_addr_t phys_addr);
  119. int pci_epc_set_msi(struct pci_epc *epc, u8 interrupts);
  120. int pci_epc_get_msi(struct pci_epc *epc);
  121. int pci_epc_raise_irq(struct pci_epc *epc, enum pci_epc_irq_type type,
  122. u8 interrupt_num);
  123. int pci_epc_start(struct pci_epc *epc);
  124. void pci_epc_stop(struct pci_epc *epc);
  125. struct pci_epc *pci_epc_get(char *epc_name);
  126. void pci_epc_put(struct pci_epc *epc);
  127. int __pci_epc_mem_init(struct pci_epc *epc, phys_addr_t phys_addr, size_t size,
  128. size_t page_size);
  129. void pci_epc_mem_exit(struct pci_epc *epc);
  130. void __iomem *pci_epc_mem_alloc_addr(struct pci_epc *epc,
  131. phys_addr_t *phys_addr, size_t size);
  132. void pci_epc_mem_free_addr(struct pci_epc *epc, phys_addr_t phys_addr,
  133. void __iomem *virt_addr, size_t size);
  134. #endif /* __LINUX_PCI_EPC_H */