1b30934cbSJiri Slaby 2b30934cbSJiri SlabyEDU device 3b30934cbSJiri Slaby========== 4b30934cbSJiri Slaby 5*4df3f195SPeter Maydell.. 6b30934cbSJiri Slaby Copyright (c) 2014-2015 Jiri Slaby 7b30934cbSJiri Slaby 8b30934cbSJiri Slaby This document is licensed under the GPLv2 (or later). 9b30934cbSJiri Slaby 10b30934cbSJiri SlabyThis is an educational device for writing (kernel) drivers. Its original 11b30934cbSJiri Slabyintention was to support the Linux kernel lectures taught at the Masaryk 12b30934cbSJiri SlabyUniversity. Students are given this virtual device and are expected to write a 13b30934cbSJiri Slabydriver with I/Os, IRQs, DMAs and such. 14b30934cbSJiri Slaby 15b30934cbSJiri SlabyThe devices behaves very similar to the PCI bridge present in the COMBO6 cards 16b30934cbSJiri Slabydeveloped under the Liberouter wings. Both PCI device ID and PCI space is 17b30934cbSJiri Slabyinherited from that device. 18b30934cbSJiri Slaby 19*4df3f195SPeter MaydellCommand line switches 20*4df3f195SPeter Maydell--------------------- 21b30934cbSJiri Slaby 22*4df3f195SPeter Maydell``-device edu[,dma_mask=mask]`` 23*4df3f195SPeter Maydell ``dma_mask`` makes the virtual device work with DMA addresses with the given 24b30934cbSJiri Slaby mask. For educational purposes, the device supports only 28 bits (256 MiB) 25b30934cbSJiri Slaby by default. Students shall set dma_mask for the device in the OS driver 26b30934cbSJiri Slaby properly. 27b30934cbSJiri Slaby 28b30934cbSJiri SlabyPCI specs 29b30934cbSJiri Slaby--------- 30b30934cbSJiri Slaby 31*4df3f195SPeter MaydellPCI ID: 32*4df3f195SPeter Maydell ``1234:11e8`` 33b30934cbSJiri Slaby 34b30934cbSJiri SlabyPCI Region 0: 35b30934cbSJiri Slaby I/O memory, 1 MB in size. Users are supposed to communicate with the card 36b30934cbSJiri Slaby through this memory. 37b30934cbSJiri Slaby 38b30934cbSJiri SlabyMMIO area spec 39b30934cbSJiri Slaby-------------- 40b30934cbSJiri Slaby 41*4df3f195SPeter MaydellOnly ``size == 4`` accesses are allowed for addresses ``< 0x80``. 42*4df3f195SPeter Maydell``size == 4`` or ``size == 8`` for the rest. 43b30934cbSJiri Slaby 44*4df3f195SPeter Maydell0x00 (RO) : identification 45*4df3f195SPeter Maydell Value is in the form ``0xRRrr00edu`` where: 46*4df3f195SPeter Maydell - ``RR`` -- major version 47*4df3f195SPeter Maydell - ``rr`` -- minor version 48b30934cbSJiri Slaby 49b30934cbSJiri Slaby0x04 (RW) : card liveness check 50*4df3f195SPeter Maydell It is a simple value inversion (``~`` C operator). 51b30934cbSJiri Slaby 52b30934cbSJiri Slaby0x08 (RW) : factorial computation 53b30934cbSJiri Slaby The stored value is taken and factorial of it is put back here. 54b30934cbSJiri Slaby This happens only after factorial bit in the status register (0x20 55b30934cbSJiri Slaby below) is cleared. 56b30934cbSJiri Slaby 57*4df3f195SPeter Maydell0x20 (RW) : status register 58*4df3f195SPeter Maydell Bitwise OR of: 59*4df3f195SPeter Maydell 60*4df3f195SPeter Maydell 0x01 61*4df3f195SPeter Maydell computing factorial (RO) 62*4df3f195SPeter Maydell 0x80 63*4df3f195SPeter Maydell raise interrupt after finishing factorial computation 64b30934cbSJiri Slaby 65b30934cbSJiri Slaby0x24 (RO) : interrupt status register 66b30934cbSJiri Slaby It contains values which raised the interrupt (see interrupt raise 67b30934cbSJiri Slaby register below). 68b30934cbSJiri Slaby 69b30934cbSJiri Slaby0x60 (WO) : interrupt raise register 70b30934cbSJiri Slaby Raise an interrupt. The value will be put to the interrupt status 71b30934cbSJiri Slaby register (using bitwise OR). 72b30934cbSJiri Slaby 73b30934cbSJiri Slaby0x64 (WO) : interrupt acknowledge register 74b30934cbSJiri Slaby Clear an interrupt. The value will be cleared from the interrupt 75b30934cbSJiri Slaby status register. This needs to be done from the ISR to stop 76b30934cbSJiri Slaby generating interrupts. 77b30934cbSJiri Slaby 78b30934cbSJiri Slaby0x80 (RW) : DMA source address 79b30934cbSJiri Slaby Where to perform the DMA from. 80b30934cbSJiri Slaby 81b30934cbSJiri Slaby0x88 (RW) : DMA destination address 82b30934cbSJiri Slaby Where to perform the DMA to. 83b30934cbSJiri Slaby 84b30934cbSJiri Slaby0x90 (RW) : DMA transfer count 85b30934cbSJiri Slaby The size of the area to perform the DMA on. 86b30934cbSJiri Slaby 87*4df3f195SPeter Maydell0x98 (RW) : DMA command register 88*4df3f195SPeter Maydell Bitwise OR of: 89*4df3f195SPeter Maydell 90*4df3f195SPeter Maydell 0x01 91*4df3f195SPeter Maydell start transfer 92*4df3f195SPeter Maydell 0x02 93*4df3f195SPeter Maydell direction (0: from RAM to EDU, 1: from EDU to RAM) 94*4df3f195SPeter Maydell 0x04 95*4df3f195SPeter Maydell raise interrupt 0x100 after finishing the DMA 96b30934cbSJiri Slaby 97b30934cbSJiri SlabyIRQ controller 98b30934cbSJiri Slaby-------------- 99*4df3f195SPeter Maydell 100b30934cbSJiri SlabyAn IRQ is generated when written to the interrupt raise register. The value 101b30934cbSJiri Slabyappears in interrupt status register when the interrupt is raised and has to 102b30934cbSJiri Slabybe written to the interrupt acknowledge register to lower it. 103b30934cbSJiri Slaby 104eabb5782SPeter XuThe device supports both INTx and MSI interrupt. By default, INTx is 105eabb5782SPeter Xuused. Even if the driver disabled INTx and only uses MSI, it still 106eabb5782SPeter Xuneeds to update the acknowledge register at the end of the IRQ handler 107eabb5782SPeter Xuroutine. 108eabb5782SPeter Xu 109b30934cbSJiri SlabyDMA controller 110b30934cbSJiri Slaby-------------- 111*4df3f195SPeter Maydell 112b30934cbSJiri SlabyOne has to specify, source, destination, size, and start the transfer. One 113b30934cbSJiri Slaby4096 bytes long buffer at offset 0x40000 is available in the EDU device. I.e. 114b30934cbSJiri Slabyone can perform DMA to/from this space when programmed properly. 115b30934cbSJiri Slaby 116b30934cbSJiri SlabyExample of transferring a 100 byte block to and from the buffer using a given 117*4df3f195SPeter MaydellPCI address ``addr``: 118*4df3f195SPeter Maydell 119*4df3f195SPeter Maydell:: 120*4df3f195SPeter Maydell 121b30934cbSJiri Slaby addr -> DMA source address 122b30934cbSJiri Slaby 0x40000 -> DMA destination address 123b30934cbSJiri Slaby 100 -> DMA transfer count 124b30934cbSJiri Slaby 1 -> DMA command register 125b30934cbSJiri Slaby while (DMA command register & 1) 126b30934cbSJiri Slaby ; 127b30934cbSJiri Slaby 128*4df3f195SPeter Maydell:: 129*4df3f195SPeter Maydell 130b30934cbSJiri Slaby 0x40000 -> DMA source address 131b30934cbSJiri Slaby addr+100 -> DMA destination address 132b30934cbSJiri Slaby 100 -> DMA transfer count 133b30934cbSJiri Slaby 3 -> DMA command register 134b30934cbSJiri Slaby while (DMA command register & 1) 135b30934cbSJiri Slaby ; 136