1 /* $NetBSD: intiovar.h,v 1.15 2024/01/28 17:31:40 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1996, 1998, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Autoconfiguration definitions and prototypes for the hp300
34 * internal i/o space.
35 */
36
37 #include <machine/bus.h>
38 #include <machine/cpu.h>
39
40 #include <arch/hp300/dev/intioreg.h>
41
42 #define INTIO_MOD_LEN 8
43
44 /*
45 * Arguments used to attach a device to the internal i/o space.
46 */
47 struct intio_attach_args {
48 char ia_modname[INTIO_MOD_LEN]; /* module name */
49 bus_space_tag_t ia_bst; /* bus space tag */
50 bus_addr_t ia_addr; /* physical address */
51 bus_size_t ia_iobase; /* intio iobase */
52 int ia_ipl; /* interrupt priority level */
53 };
54
55 struct intio_builtins {
56 const char *ib_modname; /* module name */
57 bus_size_t ib_offset; /* intio offset */
58 int ib_ipl; /* interrupt priority level */
59 uint32_t ib_spumask; /* which machines have it */
60 };
61
62 /*
63 * Devices such as the HIL and RTC chips are wired in a consistent
64 * fashion. These routines provide a uniform mechanism for accessing
65 * the devices that are wired to the machine. Doesn't include
66 * memory-mapped devices such as framebuffers.
67 */
68
69 #define WAIT(bst,bsh) \
70 while (bus_space_read_1(bst,bsh,INTIO_DEV_3xx_STAT) \
71 & INTIO_DEV_BUSY)
72 #define DATAWAIT(bst,bsh) \
73 while (!(bus_space_read_1(bst, bsh, INTIO_DEV_3xx_STAT) \
74 & INTIO_DEV_DATA_READY))
75
76 static inline int
intio_device_readcmd(bus_space_tag_t bst,bus_space_handle_t bsh,int cmd,uint8_t * datap)77 intio_device_readcmd(bus_space_tag_t bst, bus_space_handle_t bsh, int cmd,
78 uint8_t *datap)
79 {
80 uint8_t status;
81
82 if (cmd != 0) {
83 WAIT(bst, bsh);
84 bus_space_write_1(bst, bsh, INTIO_DEV_3xx_CMD, cmd);
85 }
86 do {
87 DATAWAIT(bst, bsh);
88 status = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_STAT);
89 *datap = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_DATA);
90 } while (((status >> INTIO_DEV_SRSHIFT) & INTIO_DEV_SRMASK)
91 != INTIO_DEV_SR_DATAAVAIL);
92 return (0);
93 }
94
95 static inline int
intio_device_writecmd(bus_space_tag_t bst,bus_space_handle_t bsh,int cmd,uint8_t * datap,int len)96 intio_device_writecmd(bus_space_tag_t bst, bus_space_handle_t bsh,
97 int cmd, uint8_t *datap, int len)
98 {
99
100 WAIT(bst, bsh);
101 bus_space_write_1(bst, bsh, INTIO_DEV_3xx_CMD, cmd);
102 while (len--) {
103 WAIT(bst, bsh);
104 bus_space_write_1(bst, bsh, INTIO_DEV_3xx_DATA, *datap++);
105 }
106 return (0);
107 }
108
109 static inline int
intio_device_readstate(bus_space_tag_t bst,bus_space_handle_t bsh,uint8_t * statusp,uint8_t * datap)110 intio_device_readstate(bus_space_tag_t bst, bus_space_handle_t bsh,
111 uint8_t *statusp, uint8_t *datap)
112 {
113 *statusp = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_STAT);
114 *datap = bus_space_read_1(bst, bsh, INTIO_DEV_3xx_DATA);
115 return (0);
116 }
117 #undef WAIT
118 #undef DATAWAIT
119
120 #define INTIO_DEVSIZE 4096 /* large enough for all machines */
121
122 #define intio_intr_establish(func, arg, ipl, priority) \
123 intr_establish((func),(arg),(ipl),(priority))
124