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

4.104.115
Last change on this file since debbc9e was debbc9e, checked in by Joel Sherrill <joel.sherrill@…>, on 05/06/09 at 16:36:16

2009-05-06 Joel Sherrill <joel.sherrill@…>

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