summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/i386/pc386/ide/idecfg.c
blob: 371a6eea53ee3afa0ad9d6661a88b3aa8125ba22 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*===============================================================*\
| Project: RTEMS PC386 IDE harddisc driver tables                 |
+-----------------------------------------------------------------+
| File: idecfg.c                                                  |
+-----------------------------------------------------------------+
|                    Copyright (c) 2003 IMD                       |
|      Ingenieurbuero fuer Microcomputertechnik Th. Doerfler      |
|               <Thomas.Doerfler@imd-systems.de>                  |
|                       all rights reserved                       |
+-----------------------------------------------------------------+
| this file contains the table of functions for the BSP layer     |
| for IDE access below the libchip IDE harddisc driver            |
|                                                                 |
+-----------------------------------------------------------------+
|   date                      history                        ID   |
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 01.14.03  creation                                         doe  |
\*===============================================================*/

#include <rtems.h>
#include <bsp.h>
#include <libchip/ide_ctrl.h>
#include <libchip/ide_ctrl_cfg.h>
#include <libchip/ide_ctrl_io.h>

extern bool pc386_ide_show;

/*
 * The following table configures the functions used for IDE drivers
 * in this BSP.
 */

/*
 * The following table configures the IDE drivers used in this BSP.
 */
extern ide_ctrl_fns_t pc386_ide_ctrl_fns;

/* IDE controllers Table */
ide_controller_bsp_table_t IDE_Controller_Table[] = {
  {"/dev/ide0",
   IDE_STD, /* standard IDE controller */
   &pc386_ide_ctrl_fns,
   NULL, /* probe for IDE standard registers */
   FALSE, /* not (yet) initialized */
   0x1f0,  /* base I/O address for first IDE controller */
   FALSE,0, /* not (yet) interrupt driven */
   NULL
  }
  , /* colon only needed when both interfaces present */
  {"/dev/ide1",
   IDE_STD, /* standard IDE controller */
   &pc386_ide_ctrl_fns,
   NULL, /* probe for IDE standard registers */
   FALSE, /* not (yet) initialized */
   0x170,  /* base I/O address for second IDE controller */
   FALSE,0, /* not (yet) interrupt driven */
   NULL
  }
};

/* Number of rows in IDE_Controller_Table. Default is 0. */
unsigned long IDE_Controller_Count;

#if IDE_USE_PRIMARY_INTERFACE
#define IDE1_DEFAULT true
#else
#define IDE1_DEFAULT false
#endif
#if IDE_USE_SECONDARY_INTERFACE
#define IDE2_DEFAULT true
#else
#define IDE2_DEFAULT false
#endif

void bsp_ide_cmdline_init(void)
{
  const char* ide_disable;

  ide_disable = bsp_cmdline_arg ("--ide-disable");

  if (ide_disable == NULL) {
    bool ide1 = IDE1_DEFAULT;
    bool ide2 = IDE2_DEFAULT;
    const char* ide;

    /*
     * Can have:
     *  --ide=0,1
     */
    ide = bsp_cmdline_arg ("--ide=");

    if (ide)
    {
      int i;
      /*
       * If a command line option exists remove the defaults.
       */
      ide1 = ide2 = false;

      ide += sizeof ("--ide=") - 1;

      for (i = 0; i < 3; i++)
      {
        switch (ide[i])
        {
          case '0':
            ide1 = true;
            break;
          case '1':
            ide2 = true;
            break;
          case '2':
          case '3':
          case '4':
          case '5':
          case '6':
          case '7':
          case '8':
          case '9':
          case ',':
            break;
          default:
            break;
        }
      }
    }

    if (ide2 && !ide1)
      IDE_Controller_Table[0] = IDE_Controller_Table[1];

    if (ide1)
      IDE_Controller_Count++;
    if (ide2)
      IDE_Controller_Count++;

    /*
     * Allow the user to get the initialise to print probing
     * type information.
     */
    ide = bsp_cmdline_arg ("--ide-show");

    if (ide)
      pc386_ide_show = true;
  }
}