[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 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[709] | 80 | // Low level access function |
---|
[295] | 81 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[283] | 82 | |
---|
[709] | 83 | unsigned int _bdv_get_register( unsigned int index ); |
---|
| 84 | |
---|
| 85 | void _bdv_set_register( unsigned int index, |
---|
| 86 | unsigned int value ); |
---|
| 87 | |
---|
[437] | 88 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 89 | // This function cheks block size == 512, and desactivates the interrupts. |
---|
| 90 | // Return 0 for success, > 0 if error |
---|
| 91 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[295] | 92 | extern unsigned int _bdv_init(); |
---|
| 93 | |
---|
[437] | 94 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 95 | // Transfer data to/from the block device from/to a memory buffer. |
---|
| 96 | // - use_irq : descheduling + IRQ if non zero / polling if zero |
---|
| 97 | // - to_mem : from external storage to memory when non 0. |
---|
[437] | 98 | // - lba : first block index on the block device |
---|
[529] | 99 | // - buffer : pbase address of the memory buffer (must be word aligned) |
---|
[437] | 100 | // - count : number of blocks to be transfered. |
---|
| 101 | // Returns 0 if success, > 0 if error. |
---|
| 102 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[529] | 103 | extern unsigned int _bdv_access( unsigned int use_irq, |
---|
| 104 | unsigned int to_mem, |
---|
| 105 | unsigned int lba, |
---|
| 106 | unsigned long long buffer, |
---|
| 107 | unsigned int count ); |
---|
[295] | 108 | |
---|
[437] | 109 | /////////////////////////////////////////////////////////////////////////////////// |
---|
| 110 | // This ISR save the status, acknowledge the IRQ, and activates the task |
---|
| 111 | // waiting on IO transfer. It can be an HWI or a SWI. |
---|
| 112 | // |
---|
| 113 | // TODO the _set_task_slot access should be replaced by an atomic LL/SC |
---|
| 114 | // when the CTX_RUN bool will be replaced by a bit_vector. |
---|
| 115 | /////////////////////////////////////////////////////////////////////////////////// |
---|
[295] | 116 | extern void _bdv_isr( unsigned irq_type, |
---|
| 117 | unsigned irq_id, |
---|
| 118 | unsigned channel ); |
---|
| 119 | |
---|
[283] | 120 | |
---|
| 121 | #endif |
---|
| 122 | |
---|
| 123 | // Local Variables: |
---|
| 124 | // tab-width: 4 |
---|
| 125 | // c-basic-offset: 4 |
---|
| 126 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 127 | // indent-tabs-mode: nil |
---|
| 128 | // End: |
---|
| 129 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 130 | |
---|