source: rtems/c/src/libchip/ide/ide_controller.c @ 86c79849

4.115
Last change on this file since 86c79849 was 86c79849, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/03/11 at 05:16:57

2011-12-03 Ralf Corsépius <ralf.corsepius@…>

  • libchip/ide/ata.c: Make ata_interrupt_handler static.
  • libchip/ide/ide_controller.c: Include libchip/ide_ctrl.h.
  • Property mode set to 100644
File size: 5.9 KB
Line 
1/*
2 * ide_controller.c
3 *
4 * This is generic rtems driver for IDE controllers.
5 *
6 * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
7 * Authors: Alexandra Kossovsky <sasha@oktet.ru>
8 *          Eugeny S. Mints <Eugeny.Mints@oktet.ru>
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.rtems.com/license/LICENSE.
13 *
14 * $Id$
15 *
16 */
17
18#define IDE_CONTROLLER_TRACE 0
19
20#include <rtems/chain.h>
21#include <errno.h>
22#include <rtems/blkdev.h>
23
24#include <libchip/ide_ctrl.h>
25#include <libchip/ide_ctrl_cfg.h>
26#include <libchip/ide_ctrl_io.h>
27
28#if IDE_CONTROLLER_TRACE
29int ide_controller_trace = 1;
30#endif
31
32/*
33 * ide_controller_initialize --
34 *     Initializes all configured IDE controllers. Controllers configuration
35 *     table is provided by BSP
36 *
37 * PARAMETERS:
38 *     major     - device major number
39 *     minor_arg - device minor number
40 *     args      - arguments
41 *
42 * RETURNS:
43 *     RTEMS_SUCCESSFUL on success, or error code if
44 *     error occured
45 */
46rtems_device_driver
47ide_controller_initialize(rtems_device_major_number  major,
48                          rtems_device_minor_number  minor_arg,
49                          void                      *args)
50{
51    unsigned long       minor;
52
53    /* FIXME: may be it should be done on compilation phase */
54    if (IDE_Controller_Count > IDE_CTRL_MAX_MINOR_NUMBER)
55        rtems_fatal_error_occurred(RTEMS_TOO_MANY);
56
57    for (minor=0; minor < IDE_Controller_Count; minor++)
58    {
59        IDE_Controller_Table[minor].status = IDE_CTRL_NON_INITIALIZED;
60
61        if ((IDE_Controller_Table[minor].probe == NULL ||
62             IDE_Controller_Table[minor].probe(minor)) &&
63            (IDE_Controller_Table[minor].fns->ctrl_probe == NULL ||
64             IDE_Controller_Table[minor].fns->ctrl_probe(minor)))
65        {
66            dev_t  dev;
67            dev = rtems_filesystem_make_dev_t( major, minor );
68            if (mknod(IDE_Controller_Table[minor].name,
69                      0777 | S_IFBLK, dev ) < 0)
70                rtems_fatal_error_occurred(errno);
71            IDE_Controller_Table[minor].fns->ctrl_initialize(minor);
72            IDE_Controller_Table[minor].status = IDE_CTRL_INITIALIZED;
73        }
74    }
75    return RTEMS_SUCCESSFUL;
76}
77
78/*
79 * ide_controller_read_data_block --
80 *     Read data block via controller's data register
81 *
82 * PARAMETERS:
83 *     minor      - minor number of controller
84 *     block_size - number of bytes to read
85 *     bufs       - set of buffers to store data
86 *     cbuf       - number of current buffer from the set
87 *     pos        - position inside current buffer 'cbuf'
88 *
89 * RETURNS:
90 *     NONE
91 */
92void
93ide_controller_read_data_block(rtems_device_minor_number  minor,
94                               uint32_t                   block_size,
95                               rtems_blkdev_sg_buffer    *bufs,
96                               uint32_t                  *cbuf,
97                               uint32_t                  *pos)
98{
99#if IDE_CONTROLLER_TRACE
100    if (ide_controller_trace)
101        printk ("IDE data block read: %d:%d\n", *cbuf, bufs[*cbuf].block);
102#endif
103    IDE_Controller_Table[minor].fns->ctrl_read_block(minor, block_size, bufs,
104                                                     cbuf, pos);
105}
106
107/*
108 * ide_controller_write_data_block --
109 *     Write data block via controller's data register
110 *
111 * PARAMETERS:
112 *     minor      - minor number of controller
113 *     block_size - number of bytes to write
114 *     bufs       - set of buffers which store data
115 *     cbuf       - number of current buffer from the set
116 *     pos        - position inside current buffer 'cbuf'
117 *
118 * RETURNS:
119 *     NONE
120 */
121void
122ide_controller_write_data_block(rtems_device_minor_number  minor,
123                                uint32_t                   block_size,
124                                rtems_blkdev_sg_buffer    *bufs,
125                                uint32_t                  *cbuf,
126                                uint32_t                  *pos)
127
128{
129#if IDE_CONTROLLER_TRACE
130    if (ide_controller_trace)
131        printk ("IDE data block write: %d:%d\n", *cbuf, bufs[*cbuf].block);
132#endif
133    IDE_Controller_Table[minor].fns->ctrl_write_block(minor, block_size, bufs,
134                                                      cbuf, pos);
135}
136
137/*
138 * ide_controller_read_register --
139 *     Read controller's register
140 *
141 * PARAMETERS:
142 *     minor - minor number of controller
143 *     reg   - register to read
144 *     value - placeholder for result
145 *
146 * RETURNS
147 *     NONE
148 */
149void
150ide_controller_read_register(rtems_device_minor_number  minor,
151                             int                        reg,
152                             uint16_t                  *value)
153{
154    IDE_Controller_Table[minor].fns->ctrl_reg_read(minor, reg, value);
155#if IDE_CONTROLLER_TRACE
156    if (ide_controller_trace)
157        printk ("IDE read reg: %d => %04x\n", reg, *value);
158#endif
159}
160
161/*
162 * ide_controller_write_register --
163 *     Write controller's register
164 *
165 * PARAMETERS:
166 *     minor - minor number of controller
167 *     reg   - register to write
168 *     value - value to write
169 *
170 * RETURNS:
171 *     NONE
172 */
173void
174ide_controller_write_register(rtems_device_minor_number minor, int reg,
175                              uint16_t   value)
176{
177#if IDE_CONTROLLER_TRACE
178    if (ide_controller_trace)
179        printk ("IDE write reg: %d => %04x\n", reg, value);
180#endif
181    IDE_Controller_Table[minor].fns->ctrl_reg_write(minor, reg, value);
182}
183
184/*
185 * ide_controller_config_io_speed --
186 *     Set controller's speed of IO operations
187 *
188 * PARAMETERS:
189 *     minor           - minor number of controller
190 *     modes_available - speeds available
191 *
192 * RETURNS:
193 *     RTEMS_SUCCESSFUL on success, or error code if
194 *     error occured
195 */
196rtems_status_code
197ide_controller_config_io_speed(int minor, uint16_t modes_available)
198{
199    return IDE_Controller_Table[minor].fns->ctrl_config_io_speed(
200               minor,
201               modes_available);
202}
Note: See TracBrowser for help on using the repository browser.