dioreg.h revision 1.5 1 1.5 tsutsui /* $NetBSD: dioreg.h,v 1.5 2005/01/02 12:03:12 tsutsui Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.1 thorpej * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe.
9 1.1 thorpej *
10 1.1 thorpej * Portions of this file are derived from software contributed to Berkeley
11 1.1 thorpej * by the Systems Programming Group of the University of Utah Computer
12 1.1 thorpej * Science Department.
13 1.1 thorpej *
14 1.1 thorpej * Redistribution and use in source and binary forms, with or without
15 1.1 thorpej * modification, are permitted provided that the following conditions
16 1.1 thorpej * are met:
17 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
18 1.1 thorpej * notice, this list of conditions and the following disclaimer.
19 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
20 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
21 1.1 thorpej * documentation and/or other materials provided with the distribution.
22 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
23 1.1 thorpej * must display the following acknowledgement:
24 1.1 thorpej * This product includes software developed by the NetBSD
25 1.1 thorpej * Foundation, Inc. and its contributors.
26 1.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
27 1.1 thorpej * contributors may be used to endorse or promote products derived
28 1.1 thorpej * from this software without specific prior written permission.
29 1.1 thorpej *
30 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
31 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 1.4 jtc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
34 1.4 jtc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
41 1.1 thorpej */
42 1.1 thorpej
43 1.1 thorpej /*
44 1.1 thorpej * Register definitions for the DIO and DIO-II bus.
45 1.1 thorpej */
46 1.1 thorpej
47 1.1 thorpej /*
48 1.1 thorpej * DIO/DIO-II device registers, offsets from base of device. All
49 1.1 thorpej * registers are 8-bit.
50 1.1 thorpej */
51 1.1 thorpej #define DIO_IDOFF 0x01 /* primary device id */
52 1.1 thorpej #define DIO_IPLOFF 0x03 /* interrupt level */
53 1.1 thorpej #define DIO_SECIDOFF 0x15 /* secondary device id */
54 1.1 thorpej #define DIOII_SIZEOFF 0x101 /* device size */
55 1.1 thorpej
56 1.1 thorpej /*
57 1.1 thorpej * System physical addresses of some `special' DIO devices.
58 1.1 thorpej */
59 1.1 thorpej #define DIO_IHPIBADDR 0x478000 /* internal HP-IB; select code 7 */
60 1.1 thorpej
61 1.1 thorpej /*
62 1.1 thorpej * DIO ranges from select codes 0-63 at physical addresses given by:
63 1.1 thorpej * 0x600000 + (sc - 32) * 0x10000
64 1.1 thorpej * DIO cards are addressed in the range 0-31 [0x600000-0x800000) for
65 1.1 thorpej * their control space and the remaining areas, [0x200000-0x400000) and
66 1.1 thorpej * [0x800000-0x1000000), are for additional space required by a card;
67 1.1 thorpej * e.g. a display framebuffer.
68 1.1 thorpej *
69 1.1 thorpej * DIO-II ranges from select codes 132-255 at physical addresses given by:
70 1.1 thorpej * 0x1000000 + (sc - 132) * 0x400000
71 1.1 thorpej * The address range of DIO-II space is thus [0x1000000-0x20000000).
72 1.1 thorpej *
73 1.1 thorpej * DIO/DIO-II space is too large to map in its entirety, instead devices
74 1.1 thorpej * are mapped into kernel virtual address space allocated from a range
75 1.1 thorpej * of EIOMAPSIZE pages (vmparam.h) starting at ``extiobase''.
76 1.1 thorpej */
77 1.1 thorpej #define DIO_BASE 0x600000 /* start of DIO space */
78 1.1 thorpej #define DIO_END 0x1000000 /* end of DIO space */
79 1.1 thorpej #define DIO_DEVSIZE 0x10000 /* size of a DIO device */
80 1.1 thorpej
81 1.1 thorpej #define DIOII_BASE 0x01000000 /* start of DIO-II space */
82 1.1 thorpej #define DIOII_END 0x20000000 /* end of DIO-II space */
83 1.1 thorpej #define DIOII_DEVSIZE 0x00400000 /* size of a DIO-II device */
84 1.1 thorpej
85 1.1 thorpej /*
86 1.1 thorpej * Find the highest select code for a given machine; HP320 doesn't
87 1.1 thorpej * have DIO-II.
88 1.1 thorpej */
89 1.1 thorpej #define DIO_SCMAX(machineid) ((machineid) == HP_320 ? 32 : 256)
90 1.1 thorpej
91 1.1 thorpej /*
92 1.2 thorpej * Base of DIO-II select codes.
93 1.2 thorpej */
94 1.2 thorpej #define DIOII_SCBASE 132
95 1.2 thorpej
96 1.2 thorpej /*
97 1.1 thorpej * Macro that returns true if a select code lies within
98 1.1 thorpej * the select code `hole'.
99 1.1 thorpej */
100 1.1 thorpej #define DIO_INHOLE(scode) ((scode) >= 32 && (scode) < 132)
101 1.1 thorpej
102 1.1 thorpej /*
103 1.1 thorpej * Macros to determine if device is DIO or DIO-II.
104 1.1 thorpej */
105 1.1 thorpej #define DIO_ISDIO(scode) ((scode) >= 0 && (scode) < 32)
106 1.2 thorpej #define DIO_ISDIOII(scode) ((scode) >= DIOII_SCBASE && (scode) < 256)
107 1.1 thorpej
108 1.1 thorpej /*
109 1.1 thorpej * Macro to determine if device is a framebuffer, given the
110 1.1 thorpej * primary id of the device. We key off this to determine if
111 1.1 thorpej * we should look at secondary id and ignore interrupt level.
112 1.1 thorpej */
113 1.1 thorpej #define DIO_ISFRAMEBUFFER(id) \
114 1.1 thorpej ((id) == DIO_DEVICE_ID_FRAMEBUFFER)
115 1.1 thorpej
116 1.1 thorpej /*
117 1.1 thorpej * Macro to extract primary and decondary device ids, given
118 1.1 thorpej * the base address of the device.
119 1.1 thorpej */
120 1.1 thorpej #define DIO_ID(base) \
121 1.5 tsutsui (*((uint8_t *)((u_long)(base) + DIO_IDOFF)))
122 1.1 thorpej #define DIO_SECID(base) \
123 1.5 tsutsui (*((uint8_t *)((u_long)(base) + DIO_SECIDOFF)))
124 1.1 thorpej
125 1.1 thorpej /*
126 1.1 thorpej * Macro to extract the interrupt level, given the
127 1.1 thorpej * base address of the device.
128 1.1 thorpej */
129 1.1 thorpej #define DIO_IPL(base) \
130 1.5 tsutsui ((((*((uint8_t *)((u_long)(base) + DIO_IPLOFF))) >> 4) & 0x03) + 3)
131 1.1 thorpej
132 1.1 thorpej /*
133 1.1 thorpej * Macro to compute the size of a DIO-II device's address
134 1.1 thorpej * space, given the base address of the device.
135 1.1 thorpej */
136 1.1 thorpej #define DIOII_SIZE(base) \
137 1.5 tsutsui ((int)((*((uint8_t *)((u_long)(base) + DIOII_SIZEOFF)) + 1) \
138 1.1 thorpej * 0x100000))
139 1.1 thorpej
140 1.1 thorpej /*
141 1.1 thorpej * Given a select code and device base address, compute
142 1.1 thorpej * the size of the DIO/DIO-II device.
143 1.1 thorpej */
144 1.1 thorpej #define DIO_SIZE(scode, base) \
145 1.1 thorpej (DIO_ISDIOII((scode)) ? DIOII_SIZE((base)) : DIO_DEVSIZE)
146