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, |
---|
53 | void* buffer, |
---|
54 | unsigned int count ) |
---|
55 | { |
---|
56 | // block_device configuration |
---|
57 | iowrite32( &ioc_address[BLOCK_DEVICE_BUFFER], (unsigned int) buffer ); |
---|
58 | iowrite32( &ioc_address[BLOCK_DEVICE_COUNT], count ); |
---|
59 | iowrite32( &ioc_address[BLOCK_DEVICE_LBA], lba ); |
---|
60 | iowrite32( &ioc_address[BLOCK_DEVICE_IRQ_ENABLE], 0 ); |
---|
61 | |
---|
62 | // trigger transfer |
---|
63 | iowrite32( &ioc_address[BLOCK_DEVICE_OP], ( unsigned int ) |
---|
64 | BLOCK_DEVICE_READ ); |
---|
65 | |
---|
66 | #if (RESET_HARD_CC == 0) || USE_IOB |
---|
67 | // inval buffer in L1 cache |
---|
68 | reset_L1_inval( buffer , count * 512 ); |
---|
69 | #endif |
---|
70 | |
---|
71 | #if USE_IOB |
---|
72 | // inval buffer in L2 cache |
---|
73 | reset_L2_inval( buffer , count * 512 ); |
---|
74 | #endif |
---|
75 | |
---|
76 | unsigned int status = 0; |
---|
77 | while ( 1 ) |
---|
78 | { |
---|
79 | status = ioread32(&ioc_address[BLOCK_DEVICE_STATUS]); |
---|
80 | if ( status == BLOCK_DEVICE_READ_SUCCESS ) |
---|
81 | { |
---|
82 | break; |
---|
83 | } |
---|
84 | if ( status == BLOCK_DEVICE_READ_ERROR ) |
---|
85 | { |
---|
86 | reset_puts("ERROR during read on the BLK device\n"); |
---|
87 | return 1; |
---|
88 | } |
---|
89 | } |
---|
90 | |
---|
91 | return 0; |
---|
92 | } |
---|
93 | |
---|
94 | /* |
---|
95 | * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|
96 | */ |
---|