source: trunk/softs/tsar_boot/src/boot_ioc.c @ 302

Last change on this file since 302 was 302, checked in by cfuguet, 12 years ago

Introducing IRQ_PER_PROC constant in the tsar boot loader
(pre-loader).
This constant is used to know how many XICU irq outputs
are connected to each processor.

i.e.

IRQ_PER_PROC = 3
NPROCS=2

xicu.irq_out[0] -> proc0 xicu.irq_out[3] -> proc1
xicu.irq_out[1] -> proc0 xicu.irq_out[4] -> proc1
xicu.irq_out[2] -> proc0 xicu.irq_out[5] -> proc1

This change the way the mailboxes for each processor
are calculated in the reset.S file.

File size: 5.5 KB
Line 
1#include <boot_ioc.h>
2#include <defs.h>
3
4#ifndef SOCLIB_IOC
5
6#ifndef SYSCLK_FREQ
7#warning "Using default value for SYSCLK_FREQ = 50000000"
8#define SYSCLK_FREQ 50000000U
9#endif
10
11static struct sdcard_dev  _sdcard_device;
12static struct spi_dev   * _spi_device   = ( struct spi_dev * )IOC_BASE;
13#endif
14
15
16int boot_ioc_init()
17{
18#ifndef SOCLIB_IOC
19    unsigned char sdcard_rsp;
20
21    boot_puts("Initializing block device\n\r");
22
23    /**
24     * Initializing the SPI controller
25     */
26    spi_dev_config (
27      _spi_device   ,
28      200000        , /**< SPI_clk: 200 Khz */
29      SYSCLK_FREQ   , /**< Sys_clk          */
30      8             , /**< Charlen: 8       */
31      SPI_TX_NEGEDGE,
32      SPI_RX_POSEDGE
33    ); 
34
35    /**
36     * Initializing the SD Card
37     */
38    if ( (sdcard_rsp = sdcard_dev_open(&_sdcard_device, _spi_device, 0)) )
39        return sdcard_rsp;
40
41    if ( (sdcard_rsp = sdcard_dev_set_blocklen(&_sdcard_device, 512)) )
42        return sdcard_rsp;
43
44    /**
45     * Incrementing SDCARD clock frequency for normal function
46     */
47    spi_dev_config (
48        _spi_device ,
49        10000000    , /**< SPI_clkL 10 Mhz */
50        SYSCLK_FREQ , /**< Sys_clk         */
51        -1          , /**< Charlen: 8      */
52        -1          ,
53        -1
54    );
55
56    boot_puts("Finish block device initialization\n\r");
57#endif
58
59    return 0;
60}
61
62/**
63 * _boot_ioc_completed()
64 *
65 * This blocking function checks completion of an I/O transfer and reports errors.
66 *
67 * \note It returns 0 if the transfer is successfully completed.
68 *       It returns -1 if an error has been reported.
69 */
70#ifdef SOCLIB_IOC
71static int _boot_ioc_completed()
72{
73    unsigned int status = 0;
74
75
76    unsigned int * ioc_address = ( unsigned int * )VCIBD_BASE;
77 
78    while ( 1 )
79    { 
80        status = ioread32(&ioc_address[BLOCK_DEVICE_STATUS]);
81
82        if (( status == BLOCK_DEVICE_READ_SUCCESS ) ||
83            ( status == BLOCK_DEVICE_READ_ERROR  ))
84        break;
85    }
86   
87    return status;
88}
89#endif
90
91/**
92 * boot_ioc_read()
93 *
94 * Transfer data from a file on the block device to a memory buffer.
95 *
96 * \param lba    : first block index on the disk
97 * \param buffer : base address of the memory buffer
98 * \param count  : number of blocks to be transfered
99 *
100 * \note This is a blocking function. The function returns once the transfer
101 *       has finished
102 */
103int boot_ioc_read(unsigned int lba, void* buffer, unsigned int count)
104{
105#ifdef SOCLIB_IOC
106
107    unsigned int * ioc_address  = (unsigned int*)VCIBD_BASE;
108
109    // block_device configuration
110    iowrite32( &ioc_address[BLOCK_DEVICE_BUFFER],
111            ( unsigned int ) buffer );
112
113    iowrite32( &ioc_address[BLOCK_DEVICE_COUNT],
114            ( unsigned int ) count );
115
116    iowrite32( &ioc_address[BLOCK_DEVICE_LBA],
117            ( unsigned int ) lba );
118
119    iowrite32( &ioc_address[BLOCK_DEVICE_IRQ_ENABLE],
120            ( unsigned int ) 0 );
121
122    iowrite32( &ioc_address[BLOCK_DEVICE_OP],
123            ( unsigned int ) BLOCK_DEVICE_READ );
124
125    _boot_ioc_completed();
126
127#else
128    unsigned int sdcard_rsp;
129
130    sdcard_dev_lseek(&_sdcard_device, lba);
131
132    unsigned int i;
133    for(i = 0; i < count; i++)
134    {
135        if (( sdcard_rsp = sdcard_dev_read (
136                        &_sdcard_device,
137                        (unsigned char *) buffer + (512 * i),
138                        512
139                        ) 
140            ))
141        {
142            boot_puts("ERROR during read on the SDCARD device. Code: "); 
143            boot_putx(sdcard_rsp);
144            boot_puts("\n\r");
145
146            return 1;
147        }   
148    }
149   
150#endif
151
152    return 0;
153}
154
155/**
156 * boot_ioc_write()
157 *
158 * Transfer data from a memory buffer to a file on the block_device.
159 *
160 * \param lba    : first block index on the disk
161 * \param buffer : base address of the memory buffer
162 * \param count  : number of blocks to be transfered
163 *
164 * \note The source buffer must be in user address space.
165 *
166 *in_reset int _ioc_write(unsigned int lba, void* buffer, unsigned int count)
167 *{
168 *#ifdef SOCLIB_IOC
169 *
170 *    unsigned int * ioc_address = ( unsigned int * )VCIBD_BASE;
171 *
172 *    // block_device configuration
173 *    iowrite32( &ioc_address[BLOCK_DEVICE_BUFFER],
174 *            ( unsigned int ) buffer );
175 *
176 *    iowrite32( &ioc_address[BLOCK_DEVICE_COUNT],
177 *            ( unsigned int ) count );
178 *
179 *    iowrite32( &ioc_address[BLOCK_DEVICE_LBA],
180 *            ( unsigned int ) lba );
181 *
182 *    iowrite32( &ioc_address[BLOCK_DEVICE_IRQ_ENABLE],
183 *            ( unsigned int ) 0 );
184 *
185 *    iowrite32( &ioc_address[BLOCK_DEVICE_OP],
186 *            ( unsigned int ) BLOCK_DEVICE_WRITE);
187 *
188 *    _boot_ioc_completed();
189 *
190 *#else   
191 *       
192 *    sdcard_dev_lseek(&_sdcard_device, lba);
193 *    sdcard_dev_write(&_sdcard_device, buffer, count*512);
194 *
195 *#endif
196 *
197 *    return 0;
198 *}
199 */
200
201/**
202 * _dcache_buf_invalidate()
203 *
204 * Invalidate all cache lines corresponding to a memory buffer.
205 * This is used by the block_device driver.
206 *
207 *in_reset static void _dcache_buf_invalidate(const void * buffer, unsigned int size)
208 *{
209 *    unsigned int i;
210 *    unsigned int dcache_line_size;
211 *
212 *    // retrieve dcache line size from config register (bits 12:10)
213 *    asm volatile("mfc0 %0, $16, 1" : "=r" (dcache_line_size));
214 *
215 *    dcache_line_size = 2 << ((dcache_line_size>>10) & 0x7);
216 *
217 *    // iterate on lines to invalidate each one of them
218 *    for ( i=0; i<size; i+=dcache_line_size )
219 *        asm volatile
220 *            (" mtc2 %0,     $7\n"
221 *             :
222 *             : "r" (*((char*)buffer+i))
223 *             );
224 *}
225 */
226
227/*
228 * vim: tabstop=4 : shiftwidth=4 : expandtab
229 */
Note: See TracBrowser for help on using the repository browser.