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