source: rtems/c/src/lib/libbsp/i386/pc386/ide/ide.c @ 1c5ebc5

4.104.115
Last change on this file since 1c5ebc5 was 1c5ebc5, checked in by Chris Johns <chrisj@…>, on 04/28/09 at 06:20:35

2009-04-28 Chris Johns <chrisj@…>

  • Makefile.am: Add bspcmdline.c.
  • include/bsp.h: Add boot command line interfaces.
  • start/start.c: Save the multiboot command line. Pass the command line to boot_card.
  • start/start.S: Update for boot_card command line change.
  • startup/bspstart.c: Initialise the command line.
  • startup/bspcmdline.c: New.
  • console/console.c, ide/idecfg.c: Add boot command line support.
  • Property mode set to 100644
File size: 15.1 KB
RevLine 
[176f133]1/*===============================================================*\
2| Project: RTEMS PC386 IDE harddisc driver                        |
3+-----------------------------------------------------------------+
4| File: ide.c                                                     |
5+-----------------------------------------------------------------+
6|                    Copyright (c) 2003 IMD                       |
7|      Ingenieurbuero fuer Microcomputertechnik Th. Doerfler      |
8|               <Thomas.Doerfler@imd-systems.de>                  |
9|                       all rights reserved                       |
10+-----------------------------------------------------------------+
11| this file contains the BSP layer for IDE access below the       |
12| libchip IDE harddisc driver                                     |
13| based on a board specific driver from                           |
14| Eugeny S. Mints, Oktet                                          |
15|                                                                 |
16|  The license and distribution terms for this file may be        |
17|  found in the file LICENSE in this distribution or at           |
18|  http://www.rtems.com/license/LICENSE.                     |
19|                                                                 |
20+-----------------------------------------------------------------+
21|   date                      history                        ID   |
22| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
23| 01.14.03  creation                                         doe  |
24\*===============================================================*/
25
26#include <rtems.h>
27#include <bsp.h>
28#include <libchip/ide_ctrl.h>
29#include <libchip/ide_ctrl_cfg.h>
30#include <libchip/ide_ctrl_io.h>
31
32/* #define DEBUG_OUT */
[1c5ebc5]33
34static bool pc386_ide_status_busy (uint32_t port,
35                                   uint32_t timeout,
36                                   uint8_t* status_val)
37{
38  do
39  {
40    inport_byte (port + IDE_REGISTER_STATUS, *status_val);
41    if ((*status_val & IDE_REGISTER_STATUS_BSY) == 0)
42      return true;
43
44    if (timeout)
45    {
46      timeout--;
47      rtems_task_wake_after (TOD_MICROSECONDS_TO_TICKS (1000));
48    }
49  }
50  while (timeout);
51
52  return false;
53}
54
55static bool pc386_ide_status_data_ready (uint32_t port,
56                                         uint32_t timeout,
57                                         uint8_t* status_val)
58{
59  do
60  {
61    inport_byte (port + IDE_REGISTER_STATUS, *status_val);
62   
63    if (((*status_val & IDE_REGISTER_STATUS_BSY) == 0) &&
64        (*status_val & IDE_REGISTER_STATUS_DRQ))
65      return true;
66
67    if (timeout)
68    {
69      timeout--;
70      rtems_task_wake_after (TOD_MICROSECONDS_TO_TICKS (1000));
71    }
72  }
73  while (timeout);
74
75  return false;
76}
77
[176f133]78/*
79 * support functions for IDE harddisk IF
80 */
81/*=========================================================================*\
82| Function:                                                                 |
83\*-------------------------------------------------------------------------*/
[39d08d55]84bool pc386_ide_probe
[176f133]85(
86/*-------------------------------------------------------------------------*\
87| Purpose:                                                                  |
88|  This function should probe, whether a IDE disk is available              |
89+---------------------------------------------------------------------------+
90| Input Parameters:                                                         |
91\*-------------------------------------------------------------------------*/
92 int minor
93 )
94/*-------------------------------------------------------------------------*\
95| Return Value:                                                             |
[39d08d55]96|    true, when flash disk available                                        |
[176f133]97\*=========================================================================*/
98{
[39d08d55]99  bool ide_card_plugged = true; /* assume: we have a disk here */
[176f133]100
101  return ide_card_plugged;
102}
103
104/*=========================================================================*\
105| Function:                                                                 |
106\*-------------------------------------------------------------------------*/
107void pc386_ide_initialize
108(
109/*-------------------------------------------------------------------------*\
110| Purpose:                                                                  |
111|  initialize IDE access                                                    |
112+---------------------------------------------------------------------------+
113| Input Parameters:                                                         |
114\*-------------------------------------------------------------------------*/
115 int  minor                              /* controller minor number       */
116 )
117/*-------------------------------------------------------------------------*\
118| Return Value:                                                             |
119|    <none>                                                                 |
120\*=========================================================================*/
121{
122  /*
123   * FIXME: enable interrupts, if needed
124   */
125}
126
127/*=========================================================================*\
128| Function:                                                                 |
129\*-------------------------------------------------------------------------*/
130void pc386_ide_read_reg
131(
132/*-------------------------------------------------------------------------*\
133| Purpose:                                                                  |
134|  read a IDE controller register                                           |
135+---------------------------------------------------------------------------+
136| Input Parameters:                                                         |
137\*-------------------------------------------------------------------------*/
138 int                        minor,  /* controller minor number       */
139 int                        reg,    /* register index to access      */
140 uint16_t                  *value   /* ptr to return value location  */
141 )
142/*-------------------------------------------------------------------------*\
143| Return Value:                                                             |
144|    <none>                                                                 |
145\*=========================================================================*/
146{
147  uint32_t    port = IDE_Controller_Table[minor].port1;
148  uint8_t   bval1,bval2;
149
150  if (reg == IDE_REGISTER_DATA_WORD) {
151    inport_byte(port+reg, bval1);
152    inport_byte(port+reg+1, bval2);
153    *value = bval1 + (bval2 << 8);
154  }
155  else {
156    inport_byte(port+reg, bval1);
157    *value = bval1;
158  }
159#ifdef DEBUG_OUT
160  printk("pc386_ide_read_reg (0x%x)=0x%x\r\n",reg,*value & 0xff);
161#endif
162}
163
164/*=========================================================================*\
165| Function:                                                                 |
166\*-------------------------------------------------------------------------*/
167void pc386_ide_write_reg
168(
169/*-------------------------------------------------------------------------*\
170| Purpose:                                                                  |
171|  write a IDE controller register                                          |
172+---------------------------------------------------------------------------+
173| Input Parameters:                                                         |
174\*-------------------------------------------------------------------------*/
175 int                        minor,  /* controller minor number       */
176 int                        reg,    /* register index to access      */
177 uint16_t                   value   /* value to write                */
178 )
179/*-------------------------------------------------------------------------*\
180| Return Value:                                                             |
181|    <none>                                                                 |
182\*=========================================================================*/
183{
184  uint32_t    port = IDE_Controller_Table[minor].port1;
185
186#ifdef DEBUG_OUT
187  printk("pc386_ide_write_reg(0x%x,0x%x)\r\n",reg,value & 0xff);
188#endif
189  if (reg == IDE_REGISTER_DATA_WORD) {
190    outport_word(port+reg,value);
191  }
192  else {
193    outport_byte(port+reg,value);
194  }
195}
196
197/*=========================================================================*\
198| Function:                                                                 |
199\*-------------------------------------------------------------------------*/
200void pc386_ide_read_block
201(
202/*-------------------------------------------------------------------------*\
203| Purpose:                                                                  |
204|  read a IDE controller data block                                         |
205+---------------------------------------------------------------------------+
206| Input Parameters:                                                         |
207\*-------------------------------------------------------------------------*/
208 int minor,
209 uint16_t                block_size,
210 rtems_blkdev_sg_buffer *bufs,
211 uint32_t               *cbuf,
212 uint32_t               *pos
213 )
214/*-------------------------------------------------------------------------*\
215| Return Value:                                                             |
216|    <none>                                                                 |
217\*=========================================================================*/
218{
219  uint32_t    port = IDE_Controller_Table[minor].port1;
220  uint16_t    cnt = 0;
221  uint32_t    llength = bufs[(*cbuf)].length;
[1c5ebc5]222  uint8_t     status_val;
[176f133]223  uint16_t   *lbuf = (uint16_t*)
224    ((uint8_t*)(bufs[(*cbuf)].buffer) + (*pos));
225
[1c5ebc5]226  while (cnt < block_size)
227  {
228    if (!pc386_ide_status_data_ready (port, 100, &status_val))
229    {
230      printk ("pc386_ide_read_block: status=%02x, cnt=%d bs=%d\n", status_val, cnt, block_size);
231      /* FIXME: add an error here. */
232      return;
233    }
234   
235    if (status_val & IDE_REGISTER_STATUS_ERR)
236      printk("pc386_ide_read_block: error: %02x\n", status_val);
237   
[176f133]238    inport_word(port+IDE_REGISTER_DATA,*lbuf);
239
240#ifdef DEBUG_OUT
241    printk("0x%x ",*lbuf);
242#endif
[1c5ebc5]243
[176f133]244    lbuf++;
245    cnt    += sizeof(*lbuf);
246    (*pos) += sizeof(*lbuf);
247    if ((*pos) == llength) {
248      (*pos) = 0;
249      (*cbuf)++;
250      lbuf = bufs[(*cbuf)].buffer;
251      llength = bufs[(*cbuf)].length;
252    }
253  }
254}
255
256/*=========================================================================*\
257| Function:                                                                 |
258\*-------------------------------------------------------------------------*/
259void pc386_ide_write_block
260(
261/*-------------------------------------------------------------------------*\
262| Purpose:                                                                  |
263|  write a IDE controller data block                                        |
264+---------------------------------------------------------------------------+
265| Input Parameters:                                                         |
266\*-------------------------------------------------------------------------*/
267 int minor,
268 uint16_t                block_size,
269 rtems_blkdev_sg_buffer *bufs,
270 uint32_t               *cbuf,
271 uint32_t               *pos
272 )
273/*-------------------------------------------------------------------------*\
274| Return Value:                                                             |
275|    <none>                                                                 |
276\*=========================================================================*/
277{
278  uint32_t    port = IDE_Controller_Table[minor].port1;
279  uint16_t    cnt = 0;
280  uint32_t    llength = bufs[(*cbuf)].length;
281  uint8_t     status_val;
282  uint16_t   *lbuf = (uint16_t*)
283    ((uint8_t*)(bufs[(*cbuf)].buffer) + (*pos));
[1c5ebc5]284 
[176f133]285#ifdef DEBUG_OUT
[1c5ebc5]286  printk("pc386_ide_write_block()\n");
[176f133]287#endif
[1c5ebc5]288
289  while (cnt < block_size)
290  {
291    if (!pc386_ide_status_data_ready (port, 100, &status_val))
292    {
293      printk ("pc386_ide_write_block: status=%02x, cnt=%d bs=%d\n", status_val, cnt, block_size);
294      /* FIXME: add an error here. */
295      return;
296    }
297   
298    if (status_val & IDE_REGISTER_STATUS_ERR)
299      printk("pc386_ide_write_block: error: %02x\n", status_val);
300   
[176f133]301#ifdef DEBUG_OUT
302    printk("0x%x ",*lbuf);
303#endif
304    outport_word(port+IDE_REGISTER_DATA,*lbuf);
305    lbuf++;
306    cnt    += sizeof(*lbuf);
307    (*pos) += sizeof(*lbuf);
308    if ((*pos) == llength) {
309      (*pos) = 0;
310      (*cbuf)++;
311      lbuf = bufs[(*cbuf)].buffer;
312      llength = bufs[(*cbuf)].length;
313    }
314  }
315}
316
317/*=========================================================================*\
318| Function:                                                                 |
319\*-------------------------------------------------------------------------*/
320int pc386_ide_control
321(
322/*-------------------------------------------------------------------------*\
323| Purpose:                                                                  |
324|  control interface for controller                                         |
325+---------------------------------------------------------------------------+
326| Input Parameters:                                                         |
327\*-------------------------------------------------------------------------*/
328 int  minor,                        /* controller minor number       */
329 uint32_t   cmd,                    /* command to send               */
330 void * arg                         /* optional argument             */
331 )
332/*-------------------------------------------------------------------------*\
333| Return Value:                                                             |
334|    <none>                                                                 |
335\*=========================================================================*/
336{
337  return 0;
338}
339
340/*=========================================================================*\
341| Function:                                                                 |
342\*-------------------------------------------------------------------------*/
343rtems_status_code pc386_ide_config_io_speed
344(
345/*-------------------------------------------------------------------------*\
346| Purpose:                                                                  |
347|  set up transfer speed, if possible                                       |
348+---------------------------------------------------------------------------+
349| Input Parameters:                                                         |
350\*-------------------------------------------------------------------------*/
351 int        minor,                   /* controller minor number       */
352 uint16_t   modes_avail              /* optional argument             */
353 )
354/*-------------------------------------------------------------------------*\
355| Return Value:                                                             |
356|    rtems_status_code                                                      |
357\*=========================================================================*/
358{
359  return RTEMS_SUCCESSFUL;
360}
361
362/*
363 * The following table configures the functions used for IDE drivers
364 * in this BSP.
365 */
366
367ide_ctrl_fns_t pc386_ide_ctrl_fns = {
368  pc386_ide_probe,
369  pc386_ide_initialize,
370  pc386_ide_control,
371  pc386_ide_read_reg,
372  pc386_ide_write_reg,
373  pc386_ide_read_block,
374  pc386_ide_write_block,
375  pc386_ide_config_io_speed
376};
Note: See TracBrowser for help on using the repository browser.