men-chameleon-bus.rst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. =================
  2. MEN Chameleon Bus
  3. =================
  4. .. Table of Contents
  5. =================
  6. 1 Introduction
  7. 1.1 Scope of this Document
  8. 1.2 Limitations of the current implementation
  9. 2 Architecture
  10. 2.1 MEN Chameleon Bus
  11. 2.2 Carrier Devices
  12. 2.3 Parser
  13. 3 Resource handling
  14. 3.1 Memory Resources
  15. 3.2 IRQs
  16. 4 Writing an MCB driver
  17. 4.1 The driver structure
  18. 4.2 Probing and attaching
  19. 4.3 Initializing the driver
  20. 4.4 Using DMA
  21. Introduction
  22. ============
  23. This document describes the architecture and implementation of the MEN
  24. Chameleon Bus (called MCB throughout this document).
  25. Scope of this Document
  26. ----------------------
  27. This document is intended to be a short overview of the current
  28. implementation and does by no means describe the complete possibilities of MCB
  29. based devices.
  30. Limitations of the current implementation
  31. -----------------------------------------
  32. The current implementation is limited to PCI and PCIe based carrier devices
  33. that only use a single memory resource and share the PCI legacy IRQ. Not
  34. implemented are:
  35. - Multi-resource MCB devices like the VME Controller or M-Module carrier.
  36. - MCB devices that need another MCB device, like SRAM for a DMA Controller's
  37. buffer descriptors or a video controller's video memory.
  38. - A per-carrier IRQ domain for carrier devices that have one (or more) IRQs
  39. per MCB device like PCIe based carriers with MSI or MSI-X support.
  40. Architecture
  41. ============
  42. MCB is divided into 3 functional blocks:
  43. - The MEN Chameleon Bus itself,
  44. - drivers for MCB Carrier Devices and
  45. - the parser for the Chameleon table.
  46. MEN Chameleon Bus
  47. -----------------
  48. The MEN Chameleon Bus is an artificial bus system that attaches to a so
  49. called Chameleon FPGA device found on some hardware produced my MEN Mikro
  50. Elektronik GmbH. These devices are multi-function devices implemented in a
  51. single FPGA and usually attached via some sort of PCI or PCIe link. Each
  52. FPGA contains a header section describing the content of the FPGA. The
  53. header lists the device id, PCI BAR, offset from the beginning of the PCI
  54. BAR, size in the FPGA, interrupt number and some other properties currently
  55. not handled by the MCB implementation.
  56. Carrier Devices
  57. ---------------
  58. A carrier device is just an abstraction for the real world physical bus the
  59. Chameleon FPGA is attached to. Some IP Core drivers may need to interact with
  60. properties of the carrier device (like querying the IRQ number of a PCI
  61. device). To provide abstraction from the real hardware bus, an MCB carrier
  62. device provides callback methods to translate the driver's MCB function calls
  63. to hardware related function calls. For example a carrier device may
  64. implement the get_irq() method which can be translated into a hardware bus
  65. query for the IRQ number the device should use.
  66. Parser
  67. ------
  68. The parser reads the first 512 bytes of a Chameleon device and parses the
  69. Chameleon table. Currently the parser only supports the Chameleon v2 variant
  70. of the Chameleon table but can easily be adopted to support an older or
  71. possible future variant. While parsing the table's entries new MCB devices
  72. are allocated and their resources are assigned according to the resource
  73. assignment in the Chameleon table. After resource assignment is finished, the
  74. MCB devices are registered at the MCB and thus at the driver core of the
  75. Linux kernel.
  76. Resource handling
  77. =================
  78. The current implementation assigns exactly one memory and one IRQ resource
  79. per MCB device. But this is likely going to change in the future.
  80. Memory Resources
  81. ----------------
  82. Each MCB device has exactly one memory resource, which can be requested from
  83. the MCB bus. This memory resource is the physical address of the MCB device
  84. inside the carrier and is intended to be passed to ioremap() and friends. It
  85. is already requested from the kernel by calling request_mem_region().
  86. IRQs
  87. ----
  88. Each MCB device has exactly one IRQ resource, which can be requested from the
  89. MCB bus. If a carrier device driver implements the ->get_irq() callback
  90. method, the IRQ number assigned by the carrier device will be returned,
  91. otherwise the IRQ number inside the Chameleon table will be returned. This
  92. number is suitable to be passed to request_irq().
  93. Writing an MCB driver
  94. =====================
  95. The driver structure
  96. --------------------
  97. Each MCB driver has a structure to identify the device driver as well as
  98. device ids which identify the IP Core inside the FPGA. The driver structure
  99. also contains callback methods which get executed on driver probe and
  100. removal from the system::
  101. static const struct mcb_device_id foo_ids[] = {
  102. { .device = 0x123 },
  103. { }
  104. };
  105. MODULE_DEVICE_TABLE(mcb, foo_ids);
  106. static struct mcb_driver foo_driver = {
  107. driver = {
  108. .name = "foo-bar",
  109. .owner = THIS_MODULE,
  110. },
  111. .probe = foo_probe,
  112. .remove = foo_remove,
  113. .id_table = foo_ids,
  114. };
  115. Probing and attaching
  116. ---------------------
  117. When a driver is loaded and the MCB devices it services are found, the MCB
  118. core will call the driver's probe callback method. When the driver is removed
  119. from the system, the MCB core will call the driver's remove callback method::
  120. static init foo_probe(struct mcb_device *mdev, const struct mcb_device_id *id);
  121. static void foo_remove(struct mcb_device *mdev);
  122. Initializing the driver
  123. -----------------------
  124. When the kernel is booted or your foo driver module is inserted, you have to
  125. perform driver initialization. Usually it is enough to register your driver
  126. module at the MCB core::
  127. static int __init foo_init(void)
  128. {
  129. return mcb_register_driver(&foo_driver);
  130. }
  131. module_init(foo_init);
  132. static void __exit foo_exit(void)
  133. {
  134. mcb_unregister_driver(&foo_driver);
  135. }
  136. module_exit(foo_exit);
  137. The module_mcb_driver() macro can be used to reduce the above code::
  138. module_mcb_driver(foo_driver);
  139. Using DMA
  140. ---------
  141. To make use of the kernel's DMA-API's function, you will need to use the
  142. carrier device's 'struct device'. Fortunately 'struct mcb_device' embeds a
  143. pointer (->dma_dev) to the carrier's device for DMA purposes::
  144. ret = dma_set_mask_and_coherent(&mdev->dma_dev, DMA_BIT_MASK(dma_bits));
  145. if (rc)
  146. /* Handle errors */