[283] | 1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 2 | // File : bdv_driver.h |
---|
| 3 | // Date : 01/11/2013 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Maintainer: cesar fuguet |
---|
| 6 | // Copyright (c) UPMC-LIP6 |
---|
| 7 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 8 | // The bdv_driver.c and bdv_driver.h files are part ot the GIET-VM kernel. |
---|
| 9 | // This driver supports the SocLib vci_block_device component, that is |
---|
| 10 | // a single channel, block oriented, external storage contrÃŽler. |
---|
| 11 | // |
---|
[529] | 12 | // The _bdv_access() function supports both read and write access to block device, |
---|
| 13 | // and implement two operating modes: |
---|
[437] | 14 | // |
---|
[529] | 15 | // - in "synchronous" mode, it uses a polling policy on the BDV STATUS |
---|
[437] | 16 | // register to detect transfer completion, as interrupts are not activated. |
---|
| 17 | // This mode is used by the boot code to load the map.bin file into memory |
---|
| 18 | // (before MMU activation), or to load the .elf files (after MMU activation). |
---|
[529] | 19 | // - In "descheduling" mode, ir uses a descheduling + IRQ policy. |
---|
| 20 | // The ISR executed when transfer completes should restart the calling task, |
---|
| 21 | // as the calling task global index has been saved in the _bdv_gtid variable. |
---|
| 22 | // |
---|
[437] | 23 | // As the BDV component can be used by several programs running in parallel, |
---|
[529] | 24 | // the _bdv_lock variable guaranties exclusive access to the device. |
---|
[437] | 25 | // |
---|
| 26 | // The SEG_IOC_BASE address must be defined in the hard_config.h file. |
---|
| 27 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[283] | 28 | |
---|
[295] | 29 | #ifndef _GIET_BDV_DRIVER_H_ |
---|
| 30 | #define _GIET_BDV_DRIVER_H_ |
---|
[283] | 31 | |
---|
[496] | 32 | #include "kernel_locks.h" |
---|
[350] | 33 | |
---|
[295] | 34 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 35 | // BDV registers, operations and status values |
---|
[283] | 36 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 37 | |
---|
[295] | 38 | enum BDV_registers |
---|
| 39 | { |
---|
| 40 | BLOCK_DEVICE_BUFFER, |
---|
| 41 | BLOCK_DEVICE_LBA, |
---|
| 42 | BLOCK_DEVICE_COUNT, |
---|
| 43 | BLOCK_DEVICE_OP, |
---|
| 44 | BLOCK_DEVICE_STATUS, |
---|
| 45 | BLOCK_DEVICE_IRQ_ENABLE, |
---|
| 46 | BLOCK_DEVICE_SIZE, |
---|
| 47 | BLOCK_DEVICE_BLOCK_SIZE, |
---|
| 48 | BLOCK_DEVICE_BUFFER_EXT, |
---|
| 49 | }; |
---|
[283] | 50 | |
---|
[295] | 51 | enum BDV_operations |
---|
| 52 | { |
---|
| 53 | BLOCK_DEVICE_NOOP, |
---|
| 54 | BLOCK_DEVICE_READ, |
---|
| 55 | BLOCK_DEVICE_WRITE, |
---|
| 56 | }; |
---|
[283] | 57 | |
---|
[295] | 58 | enum BDV_status |
---|
| 59 | { |
---|
| 60 | BLOCK_DEVICE_IDLE, |
---|
| 61 | BLOCK_DEVICE_BUSY, |
---|
| 62 | BLOCK_DEVICE_READ_SUCCESS, |
---|
| 63 | BLOCK_DEVICE_WRITE_SUCCESS, |
---|
| 64 | BLOCK_DEVICE_READ_ERROR, |
---|
| 65 | BLOCK_DEVICE_WRITE_ERROR, |
---|
| 66 | BLOCK_DEVICE_ERROR, |
---|
| 67 | }; |
---|
[283] | 68 | |
---|
[456] | 69 | /////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 70 | // Global variables |
---|
[456] | 71 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 72 | |
---|
| 73 | extern spin_lock_t _bdv_lock; |
---|
[529] | 74 | |
---|
[456] | 75 | extern unsigned int _bdv_gtid; |
---|
| 76 | |
---|
[529] | 77 | extern unsigned int _bdv_status; |
---|
| 78 | |
---|
[295] | 79 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[437] | 80 | // Access functions |
---|
[295] | 81 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[283] | 82 | |
---|
[437] | 83 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 84 | // This function cheks block size == 512, and desactivates the interrupts. |
---|
| 85 | // Return 0 for success, > 0 if error |
---|
| 86 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[295] | 87 | extern unsigned int _bdv_init(); |
---|
| 88 | |
---|
[437] | 89 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 90 | // Transfer data to/from the block device from/to a memory buffer. |
---|
| 91 | // - use_irq : descheduling + IRQ if non zero / polling if zero |
---|
| 92 | // - to_mem : from external storage to memory when non 0. |
---|
[437] | 93 | // - lba : first block index on the block device |
---|
[529] | 94 | // - buffer : pbase address of the memory buffer (must be word aligned) |
---|
[437] | 95 | // - count : number of blocks to be transfered. |
---|
| 96 | // Returns 0 if success, > 0 if error. |
---|
| 97 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 98 | extern unsigned int _bdv_access( unsigned int use_irq, |
---|
| 99 | unsigned int to_mem, |
---|
| 100 | unsigned int lba, |
---|
| 101 | unsigned long long buffer, |
---|
| 102 | unsigned int count ); |
---|
[295] | 103 | |
---|
[437] | 104 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 105 | // This ISR save the status, acknowledge the IRQ, and activates the task |
---|
| 106 | // waiting on IO transfer. It can be an HWI or a SWI. |
---|
| 107 | // |
---|
| 108 | // TODO the _set_task_slot access should be replaced by an atomic LL/SC |
---|
| 109 | // when the CTX_RUN bool will be replaced by a bit_vector. |
---|
| 110 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[295] | 111 | extern void _bdv_isr( unsigned irq_type, |
---|
| 112 | unsigned irq_id, |
---|
| 113 | unsigned channel ); |
---|
| 114 | |
---|
[283] | 115 | |
---|
| 116 | #endif |
---|
| 117 | |
---|
| 118 | // Local Variables: |
---|
| 119 | // tab-width: 4 |
---|
| 120 | // c-basic-offset: 4 |
---|
| 121 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 122 | // indent-tabs-mode: nil |
---|
| 123 | // End: |
---|
| 124 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 125 | |
---|