source: trunk/softs/tsar_boot/drivers/reset_ioc_bdv.c @ 1010

Last change on this file since 1010 was 992, checked in by alain, 9 years ago

Introduce a new driver for SD Card using the 4bits wide SD bus.
THere is now 5 supported block device peripherals, and the driver names
have been re-organised: reset_ioc_xxx with xxx in (bdv, hba, rdk, spi, sdc)

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