Back to home page

OSCL-LXR

 
 

    


0001 =================
0002 MEN Chameleon Bus
0003 =================
0004 
0005 .. Table of Contents
0006    =================
0007    1 Introduction
0008        1.1 Scope of this Document
0009        1.2 Limitations of the current implementation
0010    2 Architecture
0011        2.1 MEN Chameleon Bus
0012        2.2 Carrier Devices
0013        2.3 Parser
0014    3 Resource handling
0015        3.1 Memory Resources
0016        3.2 IRQs
0017    4 Writing an MCB driver
0018        4.1 The driver structure
0019        4.2 Probing and attaching
0020        4.3 Initializing the driver
0021        4.4 Using DMA
0022 
0023 
0024 Introduction
0025 ============
0026 
0027 This document describes the architecture and implementation of the MEN
0028 Chameleon Bus (called MCB throughout this document).
0029 
0030 Scope of this Document
0031 ----------------------
0032 
0033 This document is intended to be a short overview of the current
0034 implementation and does by no means describe the complete possibilities of MCB
0035 based devices.
0036 
0037 Limitations of the current implementation
0038 -----------------------------------------
0039 
0040 The current implementation is limited to PCI and PCIe based carrier devices
0041 that only use a single memory resource and share the PCI legacy IRQ.  Not
0042 implemented are:
0043 
0044 - Multi-resource MCB devices like the VME Controller or M-Module carrier.
0045 - MCB devices that need another MCB device, like SRAM for a DMA Controller's
0046   buffer descriptors or a video controller's video memory.
0047 - A per-carrier IRQ domain for carrier devices that have one (or more) IRQs
0048   per MCB device like PCIe based carriers with MSI or MSI-X support.
0049 
0050 Architecture
0051 ============
0052 
0053 MCB is divided into 3 functional blocks:
0054 
0055 - The MEN Chameleon Bus itself,
0056 - drivers for MCB Carrier Devices and
0057 - the parser for the Chameleon table.
0058 
0059 MEN Chameleon Bus
0060 -----------------
0061 
0062 The MEN Chameleon Bus is an artificial bus system that attaches to a so
0063 called Chameleon FPGA device found on some hardware produced my MEN Mikro
0064 Elektronik GmbH. These devices are multi-function devices implemented in a
0065 single FPGA and usually attached via some sort of PCI or PCIe link. Each
0066 FPGA contains a header section describing the content of the FPGA. The
0067 header lists the device id, PCI BAR, offset from the beginning of the PCI
0068 BAR, size in the FPGA, interrupt number and some other properties currently
0069 not handled by the MCB implementation.
0070 
0071 Carrier Devices
0072 ---------------
0073 
0074 A carrier device is just an abstraction for the real world physical bus the
0075 Chameleon FPGA is attached to. Some IP Core drivers may need to interact with
0076 properties of the carrier device (like querying the IRQ number of a PCI
0077 device). To provide abstraction from the real hardware bus, an MCB carrier
0078 device provides callback methods to translate the driver's MCB function calls
0079 to hardware related function calls. For example a carrier device may
0080 implement the get_irq() method which can be translated into a hardware bus
0081 query for the IRQ number the device should use.
0082 
0083 Parser
0084 ------
0085 
0086 The parser reads the first 512 bytes of a Chameleon device and parses the
0087 Chameleon table. Currently the parser only supports the Chameleon v2 variant
0088 of the Chameleon table but can easily be adopted to support an older or
0089 possible future variant. While parsing the table's entries new MCB devices
0090 are allocated and their resources are assigned according to the resource
0091 assignment in the Chameleon table. After resource assignment is finished, the
0092 MCB devices are registered at the MCB and thus at the driver core of the
0093 Linux kernel.
0094 
0095 Resource handling
0096 =================
0097 
0098 The current implementation assigns exactly one memory and one IRQ resource
0099 per MCB device. But this is likely going to change in the future.
0100 
0101 Memory Resources
0102 ----------------
0103 
0104 Each MCB device has exactly one memory resource, which can be requested from
0105 the MCB bus. This memory resource is the physical address of the MCB device
0106 inside the carrier and is intended to be passed to ioremap() and friends. It
0107 is already requested from the kernel by calling request_mem_region().
0108 
0109 IRQs
0110 ----
0111 
0112 Each MCB device has exactly one IRQ resource, which can be requested from the
0113 MCB bus. If a carrier device driver implements the ->get_irq() callback
0114 method, the IRQ number assigned by the carrier device will be returned,
0115 otherwise the IRQ number inside the Chameleon table will be returned. This
0116 number is suitable to be passed to request_irq().
0117 
0118 Writing an MCB driver
0119 =====================
0120 
0121 The driver structure
0122 --------------------
0123 
0124 Each MCB driver has a structure to identify the device driver as well as
0125 device ids which identify the IP Core inside the FPGA. The driver structure
0126 also contains callback methods which get executed on driver probe and
0127 removal from the system::
0128 
0129         static const struct mcb_device_id foo_ids[] = {
0130                 { .device = 0x123 },
0131                 { }
0132         };
0133         MODULE_DEVICE_TABLE(mcb, foo_ids);
0134 
0135         static struct mcb_driver foo_driver = {
0136         driver = {
0137                 .name = "foo-bar",
0138                 .owner = THIS_MODULE,
0139         },
0140                 .probe = foo_probe,
0141                 .remove = foo_remove,
0142                 .id_table = foo_ids,
0143         };
0144 
0145 Probing and attaching
0146 ---------------------
0147 
0148 When a driver is loaded and the MCB devices it services are found, the MCB
0149 core will call the driver's probe callback method. When the driver is removed
0150 from the system, the MCB core will call the driver's remove callback method::
0151 
0152         static init foo_probe(struct mcb_device *mdev, const struct mcb_device_id *id);
0153         static void foo_remove(struct mcb_device *mdev);
0154 
0155 Initializing the driver
0156 -----------------------
0157 
0158 When the kernel is booted or your foo driver module is inserted, you have to
0159 perform driver initialization. Usually it is enough to register your driver
0160 module at the MCB core::
0161 
0162         static int __init foo_init(void)
0163         {
0164                 return mcb_register_driver(&foo_driver);
0165         }
0166         module_init(foo_init);
0167 
0168         static void __exit foo_exit(void)
0169         {
0170                 mcb_unregister_driver(&foo_driver);
0171         }
0172         module_exit(foo_exit);
0173 
0174 The module_mcb_driver() macro can be used to reduce the above code::
0175 
0176         module_mcb_driver(foo_driver);
0177 
0178 Using DMA
0179 ---------
0180 
0181 To make use of the kernel's DMA-API's function, you will need to use the
0182 carrier device's 'struct device'. Fortunately 'struct mcb_device' embeds a
0183 pointer (->dma_dev) to the carrier's device for DMA purposes::
0184 
0185         ret = dma_set_mask_and_coherent(&mdev->dma_dev, DMA_BIT_MASK(dma_bits));
0186         if (rc)
0187                 /* Handle errors */