1 /* *********************************************************************
2 * Broadcom Common Firmware Environment (CFE)
4 * IDE disk driver File: dev_ide.c
6 * This is a simple driver for IDE hard disks. The disks
7 * are expected to be connected to the generic bus (this
8 * driver doesn't support PCI).
10 * Author: Mitch Lichtenberg (mpl@broadcom.com)
12 *********************************************************************
14 * Copyright 2000,2001,2002,2003
15 * Broadcom Corporation. All rights reserved.
17 * This software is furnished under license and may be used and
18 * copied only in accordance with the following terms and
19 * conditions. Subject to these conditions, you may download,
20 * copy, install, use, modify and distribute modified or unmodified
21 * copies of this software in source and/or binary form. No title
22 * or ownership is transferred hereby.
24 * 1) Any source code used, modified or distributed must reproduce
25 * and retain this copyright notice and list of conditions
26 * as they appear in the source file.
28 * 2) No right is granted to use any trade name, trademark, or
29 * logo of Broadcom Corporation. The "Broadcom Corporation"
30 * name may not be used to endorse or promote products derived
31 * from this software without the prior written permission of
32 * Broadcom Corporation.
34 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
35 * IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
36 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
37 * PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
38 * SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
39 * PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
40 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
41 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
42 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
44 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
45 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
46 * THE POSSIBILITY OF SUCH DAMAGE.
47 ********************************************************************* */
51 #include "lib_types.h"
52 #include "lib_malloc.h"
53 #include "lib_printf.h"
54 #include "lib_string.h"
55 #include "cfe_timer.h"
57 #include "cfe_device.h"
58 #include "cfe_ioctl.h"
60 #include "dev_ide_common.h"
66 /* *********************************************************************
68 ********************************************************************* */
70 /* *********************************************************************
71 * Forward declarations
72 ********************************************************************* */
74 static void idedrv_probe(cfe_driver_t
*drv
,
75 unsigned long probe_a
, unsigned long probe_b
,
78 /* *********************************************************************
80 ********************************************************************* */
82 static cfe_devdisp_t idedrv_dispatch
= {
93 const cfe_driver_t idedrv
= {
101 const cfe_driver_t atapidrv
= {
110 #define IDE_REG_ADDR_SHIFT 5
113 /* *********************************************************************
116 * These routines are called back from the common code to do
117 * I/O cycles to the IDE disk. We provide routines for
118 * reading and writing bytes, words, and strings of words.
119 ********************************************************************* */
121 static uint8_t idedrv_inb(idecommon_dispatch_t
*disp
,uint32_t reg
)
123 reg
<<= IDE_REG_ADDR_SHIFT
;
125 return (*((volatile uint8_t *) PHYS_TO_K1(reg
+disp
->baseaddr
)));
128 static uint16_t idedrv_inw(idecommon_dispatch_t
*disp
,uint32_t reg
)
130 reg
<<= IDE_REG_ADDR_SHIFT
;
132 return *((volatile uint16_t *) PHYS_TO_K1((reg
+disp
->baseaddr
)));
135 static void idedrv_ins(idecommon_dispatch_t
*disp
,uint32_t reg
,uint8_t *buf
,int len
)
140 reg
<<= IDE_REG_ADDR_SHIFT
;
142 /* Do 16-bit reads/writes so that the byteswaps will work out right */
144 buf16
= (uint16_t *) buf
;
147 data
= *((volatile uint16_t *) PHYS_TO_K1(reg
+disp
->baseaddr
));
155 static void idedrv_outb(idecommon_dispatch_t
*disp
,uint32_t reg
,uint8_t val
)
157 reg
<<= IDE_REG_ADDR_SHIFT
;
159 *((volatile uint8_t *) PHYS_TO_K1(reg
+disp
->baseaddr
)) = (uint8_t) (val
);
162 static void idedrv_outw(idecommon_dispatch_t
*disp
,uint32_t reg
,uint16_t val
)
164 reg
<<= IDE_REG_ADDR_SHIFT
;
166 *((volatile uint16_t *) PHYS_TO_K1(reg
+disp
->baseaddr
)) = val
;
169 static void idedrv_outs(idecommon_dispatch_t
*disp
,uint32_t reg
,uint8_t *buf
,int len
)
174 reg
<<= IDE_REG_ADDR_SHIFT
;
176 buf16
= (uint16_t *) buf
;
180 *((volatile uint16_t *) PHYS_TO_K1(reg
+disp
->baseaddr
)) = data
;
188 /* *********************************************************************
189 * idedrv_probe(drv,probe_a,probe_b,probe_ptr)
191 * Our probe routine. Attach an IDE device to the firmware.
194 * drv - driver structure
195 * probe_a - physical address of IDE registers
196 * probe_b - unit number
197 * probe_ptr - not used
201 ********************************************************************* */
203 static void idedrv_probe(cfe_driver_t
*drv
,
204 unsigned long probe_a
, unsigned long probe_b
,
207 idecommon_t
*softc
= NULL
;
208 idecommon_dispatch_t
*disp
= NULL
;
212 cfe_driver_t
*realdrv
;
216 * probe_a is the IDE base address
217 * probe_b is a bitmask of unit numbers to check
218 * probe_ptr is unused.
221 for (unit
= 0; unit
< 2; unit
++) {
223 if (IDE_PROBE_GET_TYPE(probe_b
,unit
) == IDE_DEVTYPE_NOPROBE
) {
227 softc
= (idecommon_t
*) KMALLOC(sizeof(idecommon_t
),0);
228 disp
= (idecommon_dispatch_t
*) KMALLOC(sizeof(idecommon_dispatch_t
),0);
230 if (!softc
|| !disp
) {
231 if (softc
) KFREE(softc
);
232 if (disp
) KFREE(disp
);
233 return; /* out of memory, stop here */
236 softc
->idecommon_addr
= probe_a
;
237 softc
->idecommon_unit
= unit
;
238 softc
->idecommon_deferprobe
= 0;
241 disp
->baseaddr
= softc
->idecommon_addr
;
242 softc
->idecommon_dispatch
= disp
;
244 disp
->outb
= idedrv_outb
;
245 disp
->outw
= idedrv_outw
;
246 disp
->outs
= idedrv_outs
;
248 disp
->inb
= idedrv_inb
;
249 disp
->inw
= idedrv_inw
;
250 disp
->ins
= idedrv_ins
;
253 * If we're autoprobing, do it now. Loop back if we have
254 * trouble finding the device.
256 * If not autoprobing, assume the device is there and set the
257 * common routines to double check later.
260 if (IDE_PROBE_GET_TYPE(probe_b
,unit
) == IDE_DEVTYPE_AUTO
) {
261 res
= idecommon_devprobe(softc
,1);
269 idecommon_init(softc
,IDE_PROBE_GET_TYPE(probe_b
,unit
));
270 softc
->idecommon_deferprobe
= 1;
274 xsprintf(descr
,"%s unit %d at %08X",drv
->drv_description
,unit
,probe_a
);
275 xsprintf(unitstr
,"%d",unit
);
277 realdrv
= (cfe_driver_t
*) (softc
->idecommon_atapi
? &atapidrv
: &idedrv
);
278 idecommon_attach(&idedrv_dispatch
);
280 cfe_attach(realdrv
,softc
,unitstr
,descr
);