1 | /** |
---|
2 | * \file reset_bdv.c |
---|
3 | * \date December 14, 2014 |
---|
4 | * \author Cesar Fuguet |
---|
5 | */ |
---|
6 | #include <reset_bdv.h> |
---|
7 | #include <reset_tty.h> |
---|
8 | #include <reset_inval.h> |
---|
9 | #include <io.h> |
---|
10 | #include <defs.h> |
---|
11 | |
---|
12 | #ifndef SEG_IOC_BASE |
---|
13 | # error "SEG_IOC_BASE constant must be defined in the hard_config.h file" |
---|
14 | #endif |
---|
15 | |
---|
16 | static int* const ioc_address = (int* const)SEG_IOC_BASE; |
---|
17 | |
---|
18 | enum block_device_registers { |
---|
19 | BLOCK_DEVICE_BUFFER, |
---|
20 | BLOCK_DEVICE_LBA, |
---|
21 | BLOCK_DEVICE_COUNT, |
---|
22 | BLOCK_DEVICE_OP, |
---|
23 | BLOCK_DEVICE_STATUS, |
---|
24 | BLOCK_DEVICE_IRQ_ENABLE, |
---|
25 | BLOCK_DEVICE_SIZE, |
---|
26 | BLOCK_DEVICE_BLOCK_SIZE, |
---|
27 | }; |
---|
28 | |
---|
29 | enum block_device_operations { |
---|
30 | BLOCK_DEVICE_NOOP, |
---|
31 | BLOCK_DEVICE_READ, |
---|
32 | BLOCK_DEVICE_WRITE, |
---|
33 | }; |
---|
34 | |
---|
35 | enum block_device_status { |
---|
36 | BLOCK_DEVICE_IDLE, |
---|
37 | BLOCK_DEVICE_BUSY, |
---|
38 | BLOCK_DEVICE_READ_SUCCESS, |
---|
39 | BLOCK_DEVICE_WRITE_SUCCESS, |
---|
40 | BLOCK_DEVICE_READ_ERROR, |
---|
41 | BLOCK_DEVICE_WRITE_ERROR, |
---|
42 | BLOCK_DEVICE_ERROR, |
---|
43 | }; |
---|
44 | |
---|
45 | //////////////////// |
---|
46 | int reset_bdv_init() |
---|
47 | { |
---|
48 | return 0; |
---|
49 | } |
---|
50 | |
---|
51 | //////////////////////////////////// |
---|
52 | int reset_bdv_read( unsigned int lba, void* buffer, unsigned int count ) |
---|
53 | { |
---|
54 | // block_device configuration |
---|
55 | iowrite32( &ioc_address[BLOCK_DEVICE_BUFFER], (unsigned int)buffer ); |
---|
56 | iowrite32( &ioc_address[BLOCK_DEVICE_COUNT], count ); |
---|
57 | iowrite32( &ioc_address[BLOCK_DEVICE_LBA], lba ); |
---|
58 | iowrite32( &ioc_address[BLOCK_DEVICE_IRQ_ENABLE], 0 ); |
---|
59 | |
---|
60 | // trigger transfer |
---|
61 | iowrite32( &ioc_address[BLOCK_DEVICE_OP], |
---|
62 | (unsigned int)BLOCK_DEVICE_READ ); |
---|
63 | |
---|
64 | #if (RESET_HARD_CC == 0) || USE_IOB |
---|
65 | // inval buffer in L1 cache |
---|
66 | reset_L1_inval( buffer , count * 512 ); |
---|
67 | #endif |
---|
68 | |
---|
69 | #if USE_IOB |
---|
70 | // inval buffer in L2 cache |
---|
71 | reset_L2_inval( buffer , count * 512 ); |
---|
72 | #endif |
---|
73 | |
---|
74 | unsigned int status = 0; |
---|
75 | while ( 1 ) |
---|
76 | { |
---|
77 | status = ioread32(&ioc_address[BLOCK_DEVICE_STATUS]); |
---|
78 | if ( status == BLOCK_DEVICE_READ_SUCCESS ) |
---|
79 | { |
---|
80 | break; |
---|
81 | } |
---|
82 | if ( status == BLOCK_DEVICE_READ_ERROR ) |
---|
83 | { |
---|
84 | reset_puts("ERROR during read on the BLK device\n"); |
---|
85 | return 1; |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | return 0; |
---|
90 | } |
---|
91 | |
---|
92 | /* |
---|
93 | * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|
94 | */ |
---|