Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:04

0001 /*
0002  * ide_controller.c
0003  *
0004  * This is generic rtems driver for IDE controllers.
0005  *
0006  * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia
0007  * Authors: Alexandra Kossovsky <sasha@oktet.ru>
0008  *          Eugeny S. Mints <Eugeny.Mints@oktet.ru>
0009  *
0010  *  The license and distribution terms for this file may be
0011  *  found in the file LICENSE in this distribution or at
0012  *  http://www.rtems.org/license/LICENSE.
0013  *
0014  */
0015 
0016 #define IDE_CONTROLLER_TRACE 0
0017 
0018 #include <rtems/chain.h>
0019 #include <errno.h>
0020 #include <rtems/blkdev.h>
0021 
0022 #include <libchip/ide_ctrl.h>
0023 #include <libchip/ide_ctrl_cfg.h>
0024 #include <libchip/ide_ctrl_io.h>
0025 
0026 #if IDE_CONTROLLER_TRACE
0027 int ide_controller_trace = 1;
0028 #endif
0029 
0030 /*
0031  * ide_controller_initialize --
0032  *     Initializes all configured IDE controllers. Controllers configuration
0033  *     table is provided by BSP
0034  *
0035  * PARAMETERS:
0036  *     major     - device major number
0037  *     minor_arg - device minor number
0038  *     args      - arguments
0039  *
0040  * RETURNS:
0041  *     RTEMS_SUCCESSFUL on success, or error code if
0042  *     error occured
0043  */
0044 rtems_device_driver
0045 ide_controller_initialize(rtems_device_major_number  major,
0046                           rtems_device_minor_number  minor_arg,
0047                           void                      *args)
0048 {
0049     unsigned long       minor;
0050 
0051     /* FIXME: may be it should be done on compilation phase */
0052     if (IDE_Controller_Count > IDE_CTRL_MAX_MINOR_NUMBER)
0053         rtems_fatal_error_occurred(RTEMS_TOO_MANY);
0054 
0055     for (minor=0; minor < IDE_Controller_Count; minor++)
0056     {
0057         IDE_Controller_Table[minor].status = IDE_CTRL_NON_INITIALIZED;
0058 
0059         if ((IDE_Controller_Table[minor].probe == NULL ||
0060              IDE_Controller_Table[minor].probe(minor)) &&
0061             (IDE_Controller_Table[minor].fns->ctrl_probe == NULL ||
0062              IDE_Controller_Table[minor].fns->ctrl_probe(minor)))
0063         {
0064             dev_t  dev;
0065             dev = rtems_filesystem_make_dev_t( major, minor );
0066             if (mknod(IDE_Controller_Table[minor].name,
0067                       0777 | S_IFBLK, dev ) < 0)
0068                 rtems_fatal_error_occurred(errno);
0069             IDE_Controller_Table[minor].fns->ctrl_initialize(minor);
0070             IDE_Controller_Table[minor].status = IDE_CTRL_INITIALIZED;
0071         }
0072     }
0073     return RTEMS_SUCCESSFUL;
0074 }
0075 
0076 /*
0077  * ide_controller_read_data_block --
0078  *     Read data block via controller's data register
0079  *
0080  * PARAMETERS:
0081  *     minor      - minor number of controller
0082  *     block_size - number of bytes to read
0083  *     bufs       - set of buffers to store data
0084  *     cbuf       - number of current buffer from the set
0085  *     pos        - position inside current buffer 'cbuf'
0086  *
0087  * RETURNS:
0088  *     NONE
0089  */
0090 void
0091 ide_controller_read_data_block(rtems_device_minor_number  minor,
0092                                uint32_t                   block_size,
0093                                rtems_blkdev_sg_buffer    *bufs,
0094                                uint32_t                  *cbuf,
0095                                uint32_t                  *pos)
0096 {
0097 #if IDE_CONTROLLER_TRACE
0098     if (ide_controller_trace)
0099         printk ("IDE data block read: %d:%d\n", *cbuf, bufs[*cbuf].block);
0100 #endif
0101     IDE_Controller_Table[minor].fns->ctrl_read_block(minor, block_size, bufs,
0102                                                      cbuf, pos);
0103 }
0104 
0105 /*
0106  * ide_controller_write_data_block --
0107  *     Write data block via controller's data register
0108  *
0109  * PARAMETERS:
0110  *     minor      - minor number of controller
0111  *     block_size - number of bytes to write
0112  *     bufs       - set of buffers which store data
0113  *     cbuf       - number of current buffer from the set
0114  *     pos        - position inside current buffer 'cbuf'
0115  *
0116  * RETURNS:
0117  *     NONE
0118  */
0119 void
0120 ide_controller_write_data_block(rtems_device_minor_number  minor,
0121                                 uint32_t                   block_size,
0122                                 rtems_blkdev_sg_buffer    *bufs,
0123                                 uint32_t                  *cbuf,
0124                                 uint32_t                  *pos)
0125 
0126 {
0127 #if IDE_CONTROLLER_TRACE
0128     if (ide_controller_trace)
0129         printk ("IDE data block write: %d:%d\n", *cbuf, bufs[*cbuf].block);
0130 #endif
0131     IDE_Controller_Table[minor].fns->ctrl_write_block(minor, block_size, bufs,
0132                                                       cbuf, pos);
0133 }
0134 
0135 /*
0136  * ide_controller_read_register --
0137  *     Read controller's register
0138  *
0139  * PARAMETERS:
0140  *     minor - minor number of controller
0141  *     reg   - register to read
0142  *     value - placeholder for result
0143  *
0144  * RETURNS
0145  *     NONE
0146  */
0147 void
0148 ide_controller_read_register(rtems_device_minor_number  minor,
0149                              int                        reg,
0150                              uint16_t                  *value)
0151 {
0152     IDE_Controller_Table[minor].fns->ctrl_reg_read(minor, reg, value);
0153 #if IDE_CONTROLLER_TRACE
0154     if (ide_controller_trace)
0155         printk ("IDE read reg: %d => %04x\n", reg, *value);
0156 #endif
0157 }
0158 
0159 /*
0160  * ide_controller_write_register --
0161  *     Write controller's register
0162  *
0163  * PARAMETERS:
0164  *     minor - minor number of controller
0165  *     reg   - register to write
0166  *     value - value to write
0167  *
0168  * RETURNS:
0169  *     NONE
0170  */
0171 void
0172 ide_controller_write_register(rtems_device_minor_number minor, int reg,
0173                               uint16_t   value)
0174 {
0175 #if IDE_CONTROLLER_TRACE
0176     if (ide_controller_trace)
0177         printk ("IDE write reg: %d => %04x\n", reg, value);
0178 #endif
0179     IDE_Controller_Table[minor].fns->ctrl_reg_write(minor, reg, value);
0180 }
0181 
0182 /*
0183  * ide_controller_config_io_speed --
0184  *     Set controller's speed of IO operations
0185  *
0186  * PARAMETERS:
0187  *     minor           - minor number of controller
0188  *     modes_available - speeds available
0189  *
0190  * RETURNS:
0191  *     RTEMS_SUCCESSFUL on success, or error code if
0192  *     error occured
0193  */
0194 rtems_status_code
0195 ide_controller_config_io_speed(int minor, uint16_t modes_available)
0196 {
0197     return IDE_Controller_Table[minor].fns->ctrl_config_io_speed(
0198                minor,
0199                modes_available);
0200 }