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

4.104.114.84.95
Last change on this file since af2abc9e was af2abc9e, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:51:23

2003-09-04 Joel Sherrill <joel@…>

  • clock/ckinit.c, clock/rtc.c, console/console.c, console/inch.c, console/outch.c, ide/ide.c, include/bsp.h, include/crt.h, ne2000/ne2000.c, start/start.S, startup/bspstart.c, startup/exit.c, startup/ldsegs.S, startup/linkcmds, timer/timer.c, timer/timerisr.S: URL for license changed.
  • Property mode set to 100644
File size: 13.8 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 * support functions for IDE harddisk IF
35 */
36/*=========================================================================*\
37| Function:                                                                 |
38\*-------------------------------------------------------------------------*/
39boolean pc386_ide_probe
40(
41/*-------------------------------------------------------------------------*\
42| Purpose:                                                                  |
43|  This function should probe, whether a IDE disk is available              |
44+---------------------------------------------------------------------------+
45| Input Parameters:                                                         |
46\*-------------------------------------------------------------------------*/
47 int minor
48 )
49/*-------------------------------------------------------------------------*\
50| Return Value:                                                             |
51|    TRUE, when flash disk available                                        |
52\*=========================================================================*/
53{
54  boolean ide_card_plugged = TRUE; /* assume: we have a disk here */
55 
56  return ide_card_plugged;
57}
58
59/*=========================================================================*\
60| Function:                                                                 |
61\*-------------------------------------------------------------------------*/
62void pc386_ide_initialize
63(
64/*-------------------------------------------------------------------------*\
65| Purpose:                                                                  |
66|  initialize IDE access                                                    |
67+---------------------------------------------------------------------------+
68| Input Parameters:                                                         |
69\*-------------------------------------------------------------------------*/
70 int  minor                              /* controller minor number       */
71 )
72/*-------------------------------------------------------------------------*\
73| Return Value:                                                             |
74|    <none>                                                                 |
75\*=========================================================================*/
76{
77  /*
78   * FIXME: enable interrupts, if needed
79   */
80}
81
82/*=========================================================================*\
83| Function:                                                                 |
84\*-------------------------------------------------------------------------*/
85void pc386_ide_read_reg
86(
87/*-------------------------------------------------------------------------*\
88| Purpose:                                                                  |
89|  read a IDE controller register                                           |
90+---------------------------------------------------------------------------+
91| Input Parameters:                                                         |
92\*-------------------------------------------------------------------------*/
93 int                        minor,  /* controller minor number       */
94 int                        reg,    /* register index to access      */
95 unsigned16                *value   /* ptr to return value location  */
96 )
97/*-------------------------------------------------------------------------*\
98| Return Value:                                                             |
99|    <none>                                                                 |
100\*=========================================================================*/
101{
102  unsigned32  port = IDE_Controller_Table[minor].port1;
103  unsigned8 bval1,bval2;
104
105  if (reg == IDE_REGISTER_DATA_WORD) {
106    inport_byte(port+reg, bval1);
107    inport_byte(port+reg+1, bval2);
108    *value = bval1 + (bval2 << 8);
109  }
110  else {
111    inport_byte(port+reg, bval1);
112    *value = bval1;
113  }
114#ifdef DEBUG_OUT
115  printk("pc386_ide_read_reg (0x%x)=0x%x\r\n",reg,*value & 0xff);
116#endif
117}
118
119/*=========================================================================*\
120| Function:                                                                 |
121\*-------------------------------------------------------------------------*/
122void pc386_ide_write_reg
123(
124/*-------------------------------------------------------------------------*\
125| Purpose:                                                                  |
126|  write a IDE controller register                                          |
127+---------------------------------------------------------------------------+
128| Input Parameters:                                                         |
129\*-------------------------------------------------------------------------*/
130 int                        minor,  /* controller minor number       */
131 int                        reg,    /* register index to access      */
132 unsigned16                 value   /* value to write                */
133 )
134/*-------------------------------------------------------------------------*\
135| Return Value:                                                             |
136|    <none>                                                                 |
137\*=========================================================================*/
138{
139  unsigned32  port = IDE_Controller_Table[minor].port1;
140
141#ifdef DEBUG_OUT
142  printk("pc386_ide_write_reg(0x%x,0x%x)\r\n",reg,value & 0xff);
143#endif
144  if (reg == IDE_REGISTER_DATA_WORD) {
145    outport_word(port+reg,value);
146  }
147  else {
148    outport_byte(port+reg,value);
149  }
150}
151
152/*=========================================================================*\
153| Function:                                                                 |
154\*-------------------------------------------------------------------------*/
155void pc386_ide_read_block
156(
157/*-------------------------------------------------------------------------*\
158| Purpose:                                                                  |
159|  read a IDE controller data block                                         |
160+---------------------------------------------------------------------------+
161| Input Parameters:                                                         |
162\*-------------------------------------------------------------------------*/
163 int minor,
164 unsigned16 block_size,
165 blkdev_sg_buffer *bufs,
166 rtems_unsigned32 *cbuf,
167 rtems_unsigned32 *pos
168 )
169/*-------------------------------------------------------------------------*\
170| Return Value:                                                             |
171|    <none>                                                                 |
172\*=========================================================================*/
173{
174  unsigned32  port = IDE_Controller_Table[minor].port1;
175  unsigned16  cnt = 0;
176  unsigned32  llength = bufs[(*cbuf)].length;
177  unsigned8 status_val;
178  unsigned16 *lbuf = (unsigned16 *)
179    ((unsigned8 *)(bufs[(*cbuf)].buffer) + (*pos));
180
181  inport_byte(port+IDE_REGISTER_STATUS,status_val);
182  while ((status_val & IDE_REGISTER_STATUS_DRQ) &&
183         (cnt < block_size)) {
184    inport_word(port+IDE_REGISTER_DATA,*lbuf);
185
186#ifdef DEBUG_OUT
187    printk("0x%x ",*lbuf);
188#endif
189    lbuf++;
190    cnt    += sizeof(*lbuf);
191    (*pos) += sizeof(*lbuf);
192    if ((*pos) == llength) {
193      (*pos) = 0;
194      (*cbuf)++;
195      lbuf = bufs[(*cbuf)].buffer;
196      llength = bufs[(*cbuf)].length;
197    }
198    inport_byte(port+IDE_REGISTER_STATUS,status_val);
199  }
200#ifdef DEBUG_OUT
201  printk("pc386_ide_read_block()\r\n");
202#endif
203}
204
205/*=========================================================================*\
206| Function:                                                                 |
207\*-------------------------------------------------------------------------*/
208void pc386_ide_write_block
209(
210/*-------------------------------------------------------------------------*\
211| Purpose:                                                                  |
212|  write a IDE controller data block                                        |
213+---------------------------------------------------------------------------+
214| Input Parameters:                                                         |
215\*-------------------------------------------------------------------------*/
216 int minor,
217 unsigned16 block_size,
218 blkdev_sg_buffer *bufs,
219 rtems_unsigned32 *cbuf,
220 rtems_unsigned32 *pos
221 )
222/*-------------------------------------------------------------------------*\
223| Return Value:                                                             |
224|    <none>                                                                 |
225\*=========================================================================*/
226{
227  unsigned32  port = IDE_Controller_Table[minor].port1;
228  unsigned16  cnt = 0;
229  unsigned32  llength = bufs[(*cbuf)].length;
230  unsigned8   status_val;
231  unsigned16 *lbuf = (unsigned16 *)
232    ((unsigned8 *)(bufs[(*cbuf)].buffer) + (*pos));
233   
234#ifdef DEBUG_OUT
235  printk("pc386_ide_write_block()\r\n");
236#endif
237  inport_byte(port+IDE_REGISTER_STATUS,status_val);
238  while ((status_val & IDE_REGISTER_STATUS_DRQ) &&
239         (cnt < block_size)) {
240#ifdef DEBUG_OUT
241    printk("0x%x ",*lbuf);
242#endif
243    outport_word(port+IDE_REGISTER_DATA,*lbuf);
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    inport_byte(port+IDE_REGISTER_STATUS,status_val);
254  }
255}
256
257/*=========================================================================*\
258| Function:                                                                 |
259\*-------------------------------------------------------------------------*/
260int pc386_ide_control
261(
262/*-------------------------------------------------------------------------*\
263| Purpose:                                                                  |
264|  control interface for controller                                         |
265+---------------------------------------------------------------------------+
266| Input Parameters:                                                         |
267\*-------------------------------------------------------------------------*/
268 int  minor,                        /* controller minor number       */
269 unsigned32 cmd,                    /* command to send               */
270 void * arg                         /* optional argument             */
271 )
272/*-------------------------------------------------------------------------*\
273| Return Value:                                                             |
274|    <none>                                                                 |
275\*=========================================================================*/
276{
277  return 0;
278}
279
280/*=========================================================================*\
281| Function:                                                                 |
282\*-------------------------------------------------------------------------*/
283rtems_status_code pc386_ide_config_io_speed
284(
285/*-------------------------------------------------------------------------*\
286| Purpose:                                                                  |
287|  set up transfer speed, if possible                                       |
288+---------------------------------------------------------------------------+
289| Input Parameters:                                                         |
290\*-------------------------------------------------------------------------*/
291 int       minor,                   /* controller minor number       */
292 unsigned8 modes_avail              /* optional argument             */
293 )
294/*-------------------------------------------------------------------------*\
295| Return Value:                                                             |
296|    rtems_status_code                                                      |
297\*=========================================================================*/
298{
299  return RTEMS_SUCCESSFUL;
300}
301
302/*
303 * The following table configures the functions used for IDE drivers
304 * in this BSP.
305 */
306
307ide_ctrl_fns_t pc386_ide_ctrl_fns = {
308  pc386_ide_probe,
309  pc386_ide_initialize,
310  pc386_ide_control,
311  pc386_ide_read_reg,
312  pc386_ide_write_reg,
313  pc386_ide_read_block,
314  pc386_ide_write_block,
315  pc386_ide_config_io_speed
316};
317
Note: See TracBrowser for help on using the repository browser.