source: rtems/c/src/libchip/ide/ide_controller.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

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