1 /* $NetBSD: tx39var.h,v 1.8 2000/10/22 10:42:33 uch Exp $ */ 2 3 /*- 4 * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by UCHIYAMA Yasushi. 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 enum tx_chipset { 40 __TX391X, 41 __TX392X, 42 }; 43 44 /* attach priority of TX-internal modules. */ 45 enum tx_attach_order { 46 ATTACH_FIRST = 3, 47 ATTACH_NORMAL = 2, 48 ATTACH_LAST = 1, 49 }; 50 51 /* unified I/O manager */ 52 enum txio_group { 53 MFIO = 0, 54 IO, 55 BETTY, 56 SNOWBALL, 57 PLUM, 58 NTXIO_GROUP 59 }; 60 61 struct txio_ops; 62 63 struct tx_chipset_tag { 64 enum tx_chipset tc_chipset; 65 void *tc_intrt; /* interrupt tag */ 66 void *tc_powert; /* power tag */ 67 void *tc_clockt; /* clock/timer tag */ 68 void *tc_soundt; /* sound tag */ 69 struct txio_ops *tc_ioops[NTXIO_GROUP]; 70 void *tc_videot; /* video chip tag */ 71 }; 72 73 typedef struct tx_chipset_tag* tx_chipset_tag_t __attribute__((__unused__)); 74 typedef u_int32_t txreg_t; 75 extern struct tx_chipset_tag tx_chipset; 76 #define tx_conf_get_tag() (&tx_chipset) 77 78 #if defined TX391X && defined TX392X 79 #define IS_TX391X(t) ((t)->tc_chipset == __TX391X) 80 #define IS_TX392X(t) ((t)->tc_chipset == __TX392X) 81 #elif defined TX391X 82 #define IS_TX391X(t) (1) 83 #define IS_TX392X(t) (0) 84 #elif defined TX392X 85 #define IS_TX391X(t) (0) 86 #define IS_TX392X(t) (1) 87 #endif 88 89 void tx_conf_register_intr(tx_chipset_tag_t, void *); 90 void tx_conf_register_power(tx_chipset_tag_t, void *); 91 void tx_conf_register_clock(tx_chipset_tag_t, void *); 92 void tx_conf_register_sound(tx_chipset_tag_t, void *); 93 void tx_conf_register_ioman(tx_chipset_tag_t, struct txio_ops *); 94 void tx_conf_register_video(tx_chipset_tag_t, void *); 95 96 /* Unified IO manager */ 97 struct txio_ops { 98 void *_v; /* context */ 99 enum txio_group _group; 100 int (*_in)(void *, int); 101 void (*_out)(void *, int, int); 102 void (*_intr_map)(void *, int, int *, int *); 103 void *(*_intr_establish)(void *, int, int (*)(void *), void *); 104 void (*_intr_disestablish)(void *, void *); 105 void (*_update)(void *); /* debug */ 106 void (*_dump)(void *); /* debug */ 107 }; 108 #define tx_ioman_T(g, ops, args...) \ 109 ({ \ 110 struct txio_ops *__o = tx_chipset.tc_ioops[g]; \ 111 KASSERT(__o); \ 112 __o->_##ops(__o->_v , ##args); \ 113 }) 114 /* access ops */ 115 #define tx_ioman_in(g, args...) tx_ioman_T(g, in, args) 116 #define tx_ioman_out(g, args...) tx_ioman_T(g, out, args) 117 #define tx_ioman_intr_map(g, args...) tx_ioman_T(g, intr_map, args) 118 #define tx_ioman_intr_establish(g, args...) \ 119 tx_ioman_T(g, intr_establish, args) 120 #define tx_ioman_intr_disestablish(g, args...) \ 121 tx_ioman_T(g, intr_disestablish, args) 122 #define tx_ioman_update(g) tx_ioman_T(g, update) 123 #define tx_ioman_dump(g) tx_ioman_T(g, dump) 124 125 /* 126 * TX39 Internal Function Register access 127 */ 128 #define TX39_SYSADDR_CONFIG_REG_KSEG1 0xb0c00000 129 #define tx_conf_read(t, reg) ( \ 130 (*((volatile txreg_t *)(TX39_SYSADDR_CONFIG_REG_KSEG1 + (reg))))) 131 #define tx_conf_write(t, reg, val) ( \ 132 (*((volatile txreg_t *)(TX39_SYSADDR_CONFIG_REG_KSEG1 + (reg))) \ 133 = (val))) 134 135 /* 136 * txsim attach arguments. (txsim ... TX System Internal Module) 137 */ 138 struct txsimbus_attach_args { 139 char *tba_busname; 140 }; 141 142 /* 143 * txsim module attach arguments. 144 */ 145 struct txsim_attach_args { 146 tx_chipset_tag_t ta_tc; /* Chipset tag */ 147 }; 148 149 /* 150 * Interrupt staff 151 */ 152 #define MAKEINTR(s, b) ((s) * 32 + (ffs(b) - 1)) 153 void* tx_intr_establish(tx_chipset_tag_t, int, int, int, int (*)(void *), 154 void *); 155 void tx_intr_disestablish(tx_chipset_tag_t, void *); 156 157 #ifdef USE_POLL 158 void* tx39_poll_establish(tx_chipset_tag_t, int, int, int (*)(void *), 159 void *); 160 void tx39_poll_disestablish(tx_chipset_tag_t, void *); 161 #define POLL_CONT 0 162 #define POLL_END 1 163 #endif /* USE_POLL */ 164 165 u_int32_t tx_intr_status(tx_chipset_tag_t, int); 166 extern u_int32_t tx39intrvec; 167 168 /* 169 * Power management staff 170 */ 171 void tx39power_suspend_cpu(void); 172 173 #ifdef TX39_DEBUG 174 extern u_int32_t tx39debugflag; 175 /* 176 * Debugging use. 177 */ 178 #define __bitdisp(a, s, e, m, c) \ 179 ({ \ 180 u_int32_t __j, __j1; \ 181 int __i, __s, __e, __n; \ 182 __n = sizeof(typeof(a)) * NBBY - 1; \ 183 __j1 = 1 << __n; \ 184 __e = e ? e : __n; \ 185 __s = s; \ 186 for (__j = __j1, __i = __n; __j > 0; __j >>=1, __i--) { \ 187 if (__i > __e || __i < __s) { \ 188 printf("%c", a & __j ? '+' : '-'); \ 189 } else { \ 190 printf("%c", a & __j ? '|' : '.'); \ 191 } \ 192 } \ 193 if (m) { \ 194 printf("[%s]", (char*)m); \ 195 } \ 196 if (c) { \ 197 for (__j = __j1, __i = __n; __j > 0; __j >>=1, __i--) { \ 198 if (!(__i > __e || __i < __s) && (a & __j)) { \ 199 printf(" %d", __i); \ 200 } \ 201 } \ 202 } \ 203 printf("\n"); \ 204 }) 205 #define bitdisp(a) __bitdisp((a), 0, 0, 0, 1) 206 #else /* TX39_DEBUG */ 207 #define __bitdisp(a, s, e, m, c) 208 #define bitdisp(a) 209 #endif /* TX39_DEBUG */ 210 211 int __is_set_print(u_int32_t, int, char *); 212