Tue Jan 31 04:28:50 2012 UTC ()
Convert stragglers to use real C89 prototypes.


(matt)
diff -r1.11 -r1.12 src/sys/arch/shark/isa/isa_io.c
diff -r1.15 -r1.16 src/sys/arch/shark/isa/isadma_machdep.c
diff -r1.26 -r1.27 src/sys/arch/shark/shark/scr.c

cvs diff -r1.11 -r1.12 src/sys/arch/shark/isa/isa_io.c (switch to unified diff)

--- src/sys/arch/shark/isa/isa_io.c 2011/07/19 15:07:43 1.11
+++ src/sys/arch/shark/isa/isa_io.c 2012/01/31 04:28:50 1.12
@@ -1,411 +1,406 @@ @@ -1,411 +1,406 @@
1/* $NetBSD: isa_io.c,v 1.11 2011/07/19 15:07:43 dyoung Exp $ */ 1/* $NetBSD: isa_io.c,v 1.12 2012/01/31 04:28:50 matt Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 4 * Copyright 1997
5 * Digital Equipment Corporation. All rights reserved. 5 * Digital Equipment Corporation. All rights reserved.
6 * 6 *
7 * This software is furnished under license and may be used and 7 * This software is furnished under license and may be used and
8 * copied only in accordance with the following terms and conditions. 8 * copied only in accordance with the following terms and conditions.
9 * Subject to these conditions, you may download, copy, install, 9 * Subject to these conditions, you may download, copy, install,
10 * use, modify and distribute this software in source and/or binary 10 * use, modify and distribute this software in source and/or binary
11 * form. No title or ownership is transferred hereby. 11 * form. No title or ownership is transferred hereby.
12 * 12 *
13 * 1) Any source code used, modified or distributed must reproduce 13 * 1) Any source code used, modified or distributed must reproduce
14 * and retain this copyright notice and list of conditions as 14 * and retain this copyright notice and list of conditions as
15 * they appear in the source file. 15 * they appear in the source file.
16 * 16 *
17 * 2) No right is granted to use any trade name, trademark, or logo of 17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Digital Equipment Corporation. Neither the "Digital Equipment 18 * Digital Equipment Corporation. Neither the "Digital Equipment
19 * Corporation" name nor any trademark or logo of Digital Equipment 19 * Corporation" name nor any trademark or logo of Digital Equipment
20 * Corporation may be used to endorse or promote products derived 20 * Corporation may be used to endorse or promote products derived
21 * from this software without the prior written permission of 21 * from this software without the prior written permission of
22 * Digital Equipment Corporation. 22 * Digital Equipment Corporation.
23 * 23 *
24 * 3) This software is provided "AS-IS" and any express or implied 24 * 3) This software is provided "AS-IS" and any express or implied
25 * warranties, including but not limited to, any implied warranties 25 * warranties, including but not limited to, any implied warranties
26 * of merchantability, fitness for a particular purpose, or 26 * of merchantability, fitness for a particular purpose, or
27 * non-infringement are disclaimed. In no event shall DIGITAL be 27 * non-infringement are disclaimed. In no event shall DIGITAL be
28 * liable for any damages whatsoever, and in particular, DIGITAL 28 * liable for any damages whatsoever, and in particular, DIGITAL
29 * shall not be liable for special, indirect, consequential, or 29 * shall not be liable for special, indirect, consequential, or
30 * incidental damages or damages for lost profits, loss of 30 * incidental damages or damages for lost profits, loss of
31 * revenue or loss of use, whether such damages arise in contract, 31 * revenue or loss of use, whether such damages arise in contract,
32 * negligence, tort, under statute, in equity, at law or otherwise, 32 * negligence, tort, under statute, in equity, at law or otherwise,
33 * even if advised of the possibility of such damage. 33 * even if advised of the possibility of such damage.
34 */ 34 */
35 35
36/* 36/*
37 * bus_space I/O functions for isa 37 * bus_space I/O functions for isa
38 */ 38 */
39 39
40#include <sys/cdefs.h> 40#include <sys/cdefs.h>
41__KERNEL_RCSID(0, "$NetBSD: isa_io.c,v 1.11 2011/07/19 15:07:43 dyoung Exp $"); 41__KERNEL_RCSID(0, "$NetBSD: isa_io.c,v 1.12 2012/01/31 04:28:50 matt Exp $");
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/systm.h> 44#include <sys/systm.h>
45#include <sys/bus.h> 45#include <sys/bus.h>
46#include <machine/pio.h> 46#include <machine/pio.h>
47#include <machine/isa_machdep.h> 47#include <machine/isa_machdep.h>
48#include <machine/ofw.h> 48#include <machine/ofw.h>
49#include "igsfb_ofbus.h" 49#include "igsfb_ofbus.h"
50 50
51#if NIGSFB_OFBUS > 0 51#if NIGSFB_OFBUS > 0
52extern vaddr_t igsfb_mem_vaddr, igsfb_mmio_vaddr; 52extern vaddr_t igsfb_mem_vaddr, igsfb_mmio_vaddr;
53extern paddr_t igsfb_mem_paddr; 53extern paddr_t igsfb_mem_paddr;
54#endif 54#endif
55 55
56/* Proto types for all the bus_space structure functions */ 56/* Proto types for all the bus_space structure functions */
57 57
58bs_protos(isa); 58bs_protos(isa);
59bs_protos(bs_notimpl); 59bs_protos(bs_notimpl);
60 60
61/* 61/*
62 * Declare the isa bus space tags 62 * Declare the isa bus space tags
63 * The IO and MEM structs are identical, except for the cookies, 63 * The IO and MEM structs are identical, except for the cookies,
64 * which contain the address space bases. 64 * which contain the address space bases.
65 */ 65 */
66 66
67/* 67/*
68 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF  68 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
69 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/IO! 69 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/IO!
70 */ 70 */
71struct bus_space isa_io_bs_tag = { 71struct bus_space isa_io_bs_tag = {
72 /* cookie */ 72 /* cookie */
73 NULL, /* initialized below */ 73 NULL, /* initialized below */
74 74
75 /* mapping/unmapping */ 75 /* mapping/unmapping */
76 isa_bs_map, 76 isa_bs_map,
77 isa_bs_unmap, 77 isa_bs_unmap,
78 isa_bs_subregion, 78 isa_bs_subregion,
79 79
80 /* allocation/deallocation */ 80 /* allocation/deallocation */
81 isa_bs_alloc, 81 isa_bs_alloc,
82 isa_bs_free, 82 isa_bs_free,
83 83
84 /* get kernel virtual address */ 84 /* get kernel virtual address */
85 isa_bs_vaddr, 85 isa_bs_vaddr,
86 86
87 /* mmap bus space for userland */ 87 /* mmap bus space for userland */
88 isa_bs_mmap, 88 isa_bs_mmap,
89 89
90 /* barrier */ 90 /* barrier */
91 isa_bs_barrier, 91 isa_bs_barrier,
92 92
93 /* read (single) */ 93 /* read (single) */
94 isa_bs_r_1, 94 isa_bs_r_1,
95 isa_bs_r_2, 95 isa_bs_r_2,
96 isa_bs_r_4, 96 isa_bs_r_4,
97 bs_notimpl_bs_r_8, 97 bs_notimpl_bs_r_8,
98 98
99 /* read multiple */ 99 /* read multiple */
100 isa_bs_rm_1, 100 isa_bs_rm_1,
101 isa_bs_rm_2, 101 isa_bs_rm_2,
102 isa_bs_rm_4, 102 isa_bs_rm_4,
103 bs_notimpl_bs_rm_8, 103 bs_notimpl_bs_rm_8,
104 104
105 /* read region */ 105 /* read region */
106 isa_bs_rr_1, 106 isa_bs_rr_1,
107 isa_bs_rr_2, 107 isa_bs_rr_2,
108 isa_bs_rr_4, 108 isa_bs_rr_4,
109 bs_notimpl_bs_rr_8, 109 bs_notimpl_bs_rr_8,
110 110
111 /* write (single) */ 111 /* write (single) */
112 isa_bs_w_1, 112 isa_bs_w_1,
113 isa_bs_w_2, 113 isa_bs_w_2,
114 isa_bs_w_4, 114 isa_bs_w_4,
115 bs_notimpl_bs_w_8, 115 bs_notimpl_bs_w_8,
116 116
117 /* write multiple */ 117 /* write multiple */
118 isa_bs_wm_1, 118 isa_bs_wm_1,
119 isa_bs_wm_2, 119 isa_bs_wm_2,
120 isa_bs_wm_4, 120 isa_bs_wm_4,
121 bs_notimpl_bs_wm_8, 121 bs_notimpl_bs_wm_8,
122 122
123 /* write region */ 123 /* write region */
124 isa_bs_wr_1, 124 isa_bs_wr_1,
125 isa_bs_wr_2, 125 isa_bs_wr_2,
126 isa_bs_wr_4, 126 isa_bs_wr_4,
127 bs_notimpl_bs_wr_8, 127 bs_notimpl_bs_wr_8,
128 128
129 /* set multiple */ 129 /* set multiple */
130 bs_notimpl_bs_sm_1, 130 bs_notimpl_bs_sm_1,
131 bs_notimpl_bs_sm_2, 131 bs_notimpl_bs_sm_2,
132 bs_notimpl_bs_sm_4, 132 bs_notimpl_bs_sm_4,
133 bs_notimpl_bs_sm_8, 133 bs_notimpl_bs_sm_8,
134 134
135 /* set region */ 135 /* set region */
136 bs_notimpl_bs_sr_1, 136 bs_notimpl_bs_sr_1,
137 isa_bs_sr_2, 137 isa_bs_sr_2,
138 bs_notimpl_bs_sr_4, 138 bs_notimpl_bs_sr_4,
139 bs_notimpl_bs_sr_8, 139 bs_notimpl_bs_sr_8,
140 140
141 /* copy */ 141 /* copy */
142 bs_notimpl_bs_c_1, 142 bs_notimpl_bs_c_1,
143 isa_bs_c_2, 143 isa_bs_c_2,
144 bs_notimpl_bs_c_4, 144 bs_notimpl_bs_c_4,
145 bs_notimpl_bs_c_8, 145 bs_notimpl_bs_c_8,
146 146
147 /* stream methods are identical to regular read/write here */ 147 /* stream methods are identical to regular read/write here */
148 /* read stream single */ 148 /* read stream single */
149 isa_bs_r_1, 149 isa_bs_r_1,
150 isa_bs_r_2, 150 isa_bs_r_2,
151 isa_bs_r_4, 151 isa_bs_r_4,
152 bs_notimpl_bs_r_8, 152 bs_notimpl_bs_r_8,
153 153
154 /* read stream multiple */ 154 /* read stream multiple */
155 isa_bs_rm_1, 155 isa_bs_rm_1,
156 isa_bs_rm_2, 156 isa_bs_rm_2,
157 isa_bs_rm_4, 157 isa_bs_rm_4,
158 bs_notimpl_bs_rm_8, 158 bs_notimpl_bs_rm_8,
159 159
160 /* read region stream */ 160 /* read region stream */
161 isa_bs_rr_1, 161 isa_bs_rr_1,
162 isa_bs_rr_2, 162 isa_bs_rr_2,
163 isa_bs_rr_4, 163 isa_bs_rr_4,
164 bs_notimpl_bs_rr_8, 164 bs_notimpl_bs_rr_8,
165 165
166 /* write stream single */ 166 /* write stream single */
167 isa_bs_w_1, 167 isa_bs_w_1,
168 isa_bs_w_2, 168 isa_bs_w_2,
169 isa_bs_w_4, 169 isa_bs_w_4,
170 bs_notimpl_bs_w_8, 170 bs_notimpl_bs_w_8,
171 171
172 /* write stream multiple */ 172 /* write stream multiple */
173 isa_bs_wm_1, 173 isa_bs_wm_1,
174 isa_bs_wm_2, 174 isa_bs_wm_2,
175 isa_bs_wm_4, 175 isa_bs_wm_4,
176 bs_notimpl_bs_wm_8, 176 bs_notimpl_bs_wm_8,
177 177
178 /* write region stream */ 178 /* write region stream */
179 isa_bs_wr_1, 179 isa_bs_wr_1,
180 isa_bs_wr_2, 180 isa_bs_wr_2,
181 isa_bs_wr_4, 181 isa_bs_wr_4,
182 bs_notimpl_bs_wr_8, 182 bs_notimpl_bs_wr_8,
183  183
184}; 184};
185 185
186/* 186/*
187 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF  187 * NOTE: ASSEMBLY LANGUAGE RELIES ON THE COOKIE -- THE FIRST MEMBER OF
188 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/MEMORY! 188 * THIS STRUCTURE -- TO BE THE VIRTUAL ADDRESS OF ISA/MEMORY!
189 */ 189 */
190struct bus_space isa_mem_bs_tag = { 190struct bus_space isa_mem_bs_tag = {
191 /* cookie */ 191 /* cookie */
192 NULL, /* initialized below */ 192 NULL, /* initialized below */
193 193
194 /* mapping/unmapping */ 194 /* mapping/unmapping */
195 isa_bs_map, 195 isa_bs_map,
196 isa_bs_unmap, 196 isa_bs_unmap,
197 isa_bs_subregion, 197 isa_bs_subregion,
198 198
199 /* allocation/deallocation */ 199 /* allocation/deallocation */
200 isa_bs_alloc, 200 isa_bs_alloc,
201 isa_bs_free, 201 isa_bs_free,
202 202
203 /* get kernel virtual address */ 203 /* get kernel virtual address */
204 isa_bs_vaddr, 204 isa_bs_vaddr,
205 205
206 /* mmap bus space for userland */ 206 /* mmap bus space for userland */
207 isa_bs_mmap, 207 isa_bs_mmap,
208 208
209 /* barrier */ 209 /* barrier */
210 isa_bs_barrier, 210 isa_bs_barrier,
211 211
212 /* read (single) */ 212 /* read (single) */
213 isa_bs_r_1, 213 isa_bs_r_1,
214 isa_bs_r_2, 214 isa_bs_r_2,
215 isa_bs_r_4, 215 isa_bs_r_4,
216 bs_notimpl_bs_r_8, 216 bs_notimpl_bs_r_8,
217 217
218 /* read multiple */ 218 /* read multiple */
219 isa_bs_rm_1, 219 isa_bs_rm_1,
220 isa_bs_rm_2, 220 isa_bs_rm_2,
221 isa_bs_rm_4, 221 isa_bs_rm_4,
222 bs_notimpl_bs_rm_8, 222 bs_notimpl_bs_rm_8,
223 223
224 /* read region */ 224 /* read region */
225 isa_bs_rr_1, 225 isa_bs_rr_1,
226 isa_bs_rr_2, 226 isa_bs_rr_2,
227 isa_bs_rr_4, 227 isa_bs_rr_4,
228 bs_notimpl_bs_rr_8, 228 bs_notimpl_bs_rr_8,
229 229
230 /* write (single) */ 230 /* write (single) */
231 isa_bs_w_1, 231 isa_bs_w_1,
232 isa_bs_w_2, 232 isa_bs_w_2,
233 isa_bs_w_4, 233 isa_bs_w_4,
234 bs_notimpl_bs_w_8, 234 bs_notimpl_bs_w_8,
235 235
236 /* write multiple */ 236 /* write multiple */
237 isa_bs_wm_1, 237 isa_bs_wm_1,
238 isa_bs_wm_2, 238 isa_bs_wm_2,
239 isa_bs_wm_4, 239 isa_bs_wm_4,
240 bs_notimpl_bs_wm_8, 240 bs_notimpl_bs_wm_8,
241 241
242 /* write region */ 242 /* write region */
243 isa_bs_wr_1, 243 isa_bs_wr_1,
244 isa_bs_wr_2, 244 isa_bs_wr_2,
245 isa_bs_wr_4, 245 isa_bs_wr_4,
246 bs_notimpl_bs_wr_8, 246 bs_notimpl_bs_wr_8,
247 247
248 /* set multiple */ 248 /* set multiple */
249 bs_notimpl_bs_sm_1, 249 bs_notimpl_bs_sm_1,
250 bs_notimpl_bs_sm_2, 250 bs_notimpl_bs_sm_2,
251 bs_notimpl_bs_sm_4, 251 bs_notimpl_bs_sm_4,
252 bs_notimpl_bs_sm_8, 252 bs_notimpl_bs_sm_8,
253 253
254 /* set region */ 254 /* set region */
255 bs_notimpl_bs_sr_1, 255 bs_notimpl_bs_sr_1,
256 isa_bs_sr_2, 256 isa_bs_sr_2,
257 bs_notimpl_bs_sr_4, 257 bs_notimpl_bs_sr_4,
258 bs_notimpl_bs_sr_8, 258 bs_notimpl_bs_sr_8,
259 259
260 /* copy */ 260 /* copy */
261 bs_notimpl_bs_c_1, 261 bs_notimpl_bs_c_1,
262 isa_bs_c_2, 262 isa_bs_c_2,
263 bs_notimpl_bs_c_4, 263 bs_notimpl_bs_c_4,
264 bs_notimpl_bs_c_8, 264 bs_notimpl_bs_c_8,
265 265
266 /* stream methods are identical to regular read/write here */ 266 /* stream methods are identical to regular read/write here */
267 /* read stream single */ 267 /* read stream single */
268 isa_bs_r_1, 268 isa_bs_r_1,
269 isa_bs_r_2, 269 isa_bs_r_2,
270 isa_bs_r_4, 270 isa_bs_r_4,
271 bs_notimpl_bs_r_8, 271 bs_notimpl_bs_r_8,
272 272
273 /* read stream multiple */ 273 /* read stream multiple */
274 isa_bs_rm_1, 274 isa_bs_rm_1,
275 isa_bs_rm_2, 275 isa_bs_rm_2,
276 isa_bs_rm_4, 276 isa_bs_rm_4,
277 bs_notimpl_bs_rm_8, 277 bs_notimpl_bs_rm_8,
278 278
279 /* read region stream */ 279 /* read region stream */
280 isa_bs_rr_1, 280 isa_bs_rr_1,
281 isa_bs_rr_2, 281 isa_bs_rr_2,
282 isa_bs_rr_4, 282 isa_bs_rr_4,
283 bs_notimpl_bs_rr_8, 283 bs_notimpl_bs_rr_8,
284 284
285 /* write stream single */ 285 /* write stream single */
286 isa_bs_w_1, 286 isa_bs_w_1,
287 isa_bs_w_2, 287 isa_bs_w_2,
288 isa_bs_w_4, 288 isa_bs_w_4,
289 bs_notimpl_bs_w_8, 289 bs_notimpl_bs_w_8,
290 290
291 /* write stream multiple */ 291 /* write stream multiple */
292 isa_bs_wm_1, 292 isa_bs_wm_1,
293 isa_bs_wm_2, 293 isa_bs_wm_2,
294 isa_bs_wm_4, 294 isa_bs_wm_4,
295 bs_notimpl_bs_wm_8, 295 bs_notimpl_bs_wm_8,
296 296
297 /* write region stream */ 297 /* write region stream */
298 isa_bs_wr_1, 298 isa_bs_wr_1,
299 isa_bs_wr_2, 299 isa_bs_wr_2,
300 isa_bs_wr_4, 300 isa_bs_wr_4,
301 bs_notimpl_bs_wr_8, 301 bs_notimpl_bs_wr_8,
302}; 302};
303 303
304/* bus space functions */ 304/* bus space functions */
305 305
306void 306void
307isa_io_init(vaddr_t isa_io_addr, vaddr_t isa_mem_addr) 307isa_io_init(vaddr_t isa_io_addr, vaddr_t isa_mem_addr)
308{ 308{
309 isa_io_bs_tag.bs_cookie = (void *)isa_io_addr; 309 isa_io_bs_tag.bs_cookie = (void *)isa_io_addr;
310 isa_mem_bs_tag.bs_cookie = (void *)isa_mem_addr; 310 isa_mem_bs_tag.bs_cookie = (void *)isa_mem_addr;
311} 311}
312 312
313/* 313/*
314 * break the abstraction: sometimes, other parts of the system 314 * break the abstraction: sometimes, other parts of the system
315 * (e.g. X servers) need to map ISA space directly. use these 315 * (e.g. X servers) need to map ISA space directly. use these
316 * functions sparingly! 316 * functions sparingly!
317 */ 317 */
318vaddr_t 318vaddr_t
319isa_io_data_vaddr(void) 319isa_io_data_vaddr(void)
320{ 320{
321 return (vaddr_t)isa_io_bs_tag.bs_cookie; 321 return (vaddr_t)isa_io_bs_tag.bs_cookie;
322} 322}
323 323
324vaddr_t 324vaddr_t
325isa_mem_data_vaddr(void) 325isa_mem_data_vaddr(void)
326{ 326{
327 return (vaddr_t)isa_mem_bs_tag.bs_cookie; 327 return (vaddr_t)isa_mem_bs_tag.bs_cookie;
328} 328}
329 329
330int 330int
331isa_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp) 331isa_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int cacheable, bus_space_handle_t *bshp)
332{ 332{
333 *bshp = bpa + (bus_addr_t)t; 333 *bshp = bpa + (bus_addr_t)t;
334 return(0); 334 return(0);
335} 335}
336 336
337void 337void
338isa_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size) 338isa_bs_unmap(void *t, bus_space_handle_t bsh, bus_size_t size)
339{ 339{
340 /* Nothing to do. */ 340 /* Nothing to do. */
341} 341}
342 342
343paddr_t 343paddr_t
344isa_bs_mmap(void *cookie, bus_addr_t addr, off_t off, int prot, 344isa_bs_mmap(void *cookie, bus_addr_t addr, off_t off, int prot,
345 int flags) 345 int flags)
346{ 346{
347 paddr_t paddr, ret; 347 paddr_t paddr, ret;
348 348
349#ifdef OFISA_DEBUG 349#ifdef OFISA_DEBUG
350 printf("mmap %08x %08x %08x", (uint32_t)cookie, (uint32_t)addr, (uint32_t)off); 350 printf("mmap %08x %08x %08x", (uint32_t)cookie, (uint32_t)addr, (uint32_t)off);
351#endif 351#endif
352#if NIGSFB_OFBUS > 0 352#if NIGSFB_OFBUS > 0
353 if ((vaddr_t)cookie == igsfb_mem_vaddr) { 353 if ((vaddr_t)cookie == igsfb_mem_vaddr) {
354 paddr = igsfb_mem_paddr; 354 paddr = igsfb_mem_paddr;
355 } else 355 } else
356#endif 356#endif
357 paddr = ofw_gettranslation((vaddr_t)cookie); 357 paddr = ofw_gettranslation((vaddr_t)cookie);
358  358
359 if (paddr == -1) { 359 if (paddr == -1) {
360#ifdef OFISA_DEBUG 360#ifdef OFISA_DEBUG
361 printf(" no translation\n"); 361 printf(" no translation\n");
362#endif 362#endif
363 return -1; 363 return -1;
364 } 364 }
365 ret = paddr + addr + off; 365 ret = paddr + addr + off;
366#ifdef OFISA_DEBUG 366#ifdef OFISA_DEBUG
367 printf(" -> %08x %08x\n", (uint32_t)paddr, (uint32_t)ret); 367 printf(" -> %08x %08x\n", (uint32_t)paddr, (uint32_t)ret);
368#endif 368#endif
369 return arm_btop(ret); 369 return arm_btop(ret);
370} 370}
371 371
372int 372int
373isa_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp) 373isa_bs_subregion(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t size, bus_space_handle_t *nbshp)
374{ 374{
375/* printf("isa_subregion(tag=%p, bsh=%lx, off=%lx, sz=%lx)\n", 375/* printf("isa_subregion(tag=%p, bsh=%lx, off=%lx, sz=%lx)\n",
376 t, bsh, offset, size);*/ 376 t, bsh, offset, size);*/
377 *nbshp = bsh + offset; 377 *nbshp = bsh + offset;
378 return(0); 378 return(0);
379} 379}
380 380
381int 381int
382isa_bs_alloc(t, rstart, rend, size, alignment, boundary, cacheable, 382isa_bs_alloc(void *t, bus_addr_t rstart, bus_addr_t rend, bus_size_t size,
383 bpap, bshp) 383 bus_size_t alignment, bus_size_t boundary, int cacheable,
384 void *t; 384 bus_addr_t *bpap, bus_space_handle_t *bshp)
385 bus_addr_t rstart, rend; 
386 bus_size_t size, alignment, boundary; 
387 int cacheable; 
388 bus_addr_t *bpap; 
389 bus_space_handle_t *bshp; 
390{ 385{
391 panic("isa_alloc(): Help!"); 386 panic("isa_alloc(): Help!");
392} 387}
393 388
394void  389void
395isa_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size) 390isa_bs_free(void *t, bus_space_handle_t bsh, bus_size_t size)
396{ 391{
397 panic("isa_free(): Help!"); 392 panic("isa_free(): Help!");
398} 393}
399 394
400void * 395void *
401isa_bs_vaddr(void *t, bus_space_handle_t bsh) 396isa_bs_vaddr(void *t, bus_space_handle_t bsh)
402{ 397{
403 398
404 return ((void *)bsh); 399 return ((void *)bsh);
405} 400}
406 401
407void 402void
408isa_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags) 403isa_bs_barrier(void *t, bus_space_handle_t bsh, bus_size_t offset, bus_size_t len, int flags)
409{ 404{
410 /* just return */ 405 /* just return */
411}  406}

cvs diff -r1.15 -r1.16 src/sys/arch/shark/isa/isadma_machdep.c (switch to unified diff)

--- src/sys/arch/shark/isa/isadma_machdep.c 2011/07/19 15:07:43 1.15
+++ src/sys/arch/shark/isa/isadma_machdep.c 2012/01/31 04:28:50 1.16
@@ -1,631 +1,623 @@ @@ -1,631 +1,623 @@
1/* $NetBSD: isadma_machdep.c,v 1.15 2011/07/19 15:07:43 dyoung Exp $ */ 1/* $NetBSD: isadma_machdep.c,v 1.16 2012/01/31 04:28:50 matt Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. 4 * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center. 9 * NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer. 15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright 16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the 17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution. 18 * documentation and/or other materials provided with the distribution.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: isadma_machdep.c,v 1.15 2011/07/19 15:07:43 dyoung Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: isadma_machdep.c,v 1.16 2012/01/31 04:28:50 matt Exp $");
35 35
36#define ISA_DMA_STATS 36#define ISA_DMA_STATS
37 37
38#include <sys/param.h> 38#include <sys/param.h>
39#include <sys/systm.h> 39#include <sys/systm.h>
40#include <sys/syslog.h> 40#include <sys/syslog.h>
41#include <sys/device.h> 41#include <sys/device.h>
42#include <sys/malloc.h> 42#include <sys/malloc.h>
43#include <sys/proc.h> 43#include <sys/proc.h>
44#include <sys/mbuf.h> 44#include <sys/mbuf.h>
45 45
46#define _ARM32_BUS_DMA_PRIVATE 46#define _ARM32_BUS_DMA_PRIVATE
47#include <sys/bus.h> 47#include <sys/bus.h>
48 48
49#include <dev/isa/isareg.h> 49#include <dev/isa/isareg.h>
50#include <dev/isa/isavar.h> 50#include <dev/isa/isavar.h>
51 51
52#include <uvm/uvm_extern.h> 52#include <uvm/uvm_extern.h>
53 53
54/* 54/*
55 * ISA has a 24-bit address limitation, so at most it has a 16M 55 * ISA has a 24-bit address limitation, so at most it has a 16M
56 * DMA range. However, some platforms have a more limited range, 56 * DMA range. However, some platforms have a more limited range,
57 * e.g. the Shark NC. On these systems, we are provided with 57 * e.g. the Shark NC. On these systems, we are provided with
58 * a set of DMA ranges. The pmap module is aware of these ranges 58 * a set of DMA ranges. The pmap module is aware of these ranges
59 * and places DMA-safe memory for them onto an alternate free list 59 * and places DMA-safe memory for them onto an alternate free list
60 * so that they are protected from being used to service page faults, 60 * so that they are protected from being used to service page faults,
61 * etc. (unless we've run out of memory elsewhere). 61 * etc. (unless we've run out of memory elsewhere).
62 */ 62 */
63extern struct arm32_dma_range *shark_isa_dma_ranges; 63extern struct arm32_dma_range *shark_isa_dma_ranges;
64extern int shark_isa_dma_nranges; 64extern int shark_isa_dma_nranges;
65 65
66int _isa_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, 66int _isa_bus_dmamap_create(bus_dma_tag_t, bus_size_t, int,
67 bus_size_t, bus_size_t, int, bus_dmamap_t *); 67 bus_size_t, bus_size_t, int, bus_dmamap_t *);
68void _isa_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t); 68void _isa_bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
69int _isa_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, 69int _isa_bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *,
70 bus_size_t, struct proc *, int); 70 bus_size_t, struct proc *, int);
71int _isa_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, 71int _isa_bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t,
72 struct mbuf *, int); 72 struct mbuf *, int);
73int _isa_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, 73int _isa_bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t,
74 struct uio *, int); 74 struct uio *, int);
75int _isa_bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, 75int _isa_bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t,
76 bus_dma_segment_t *, int, bus_size_t, int); 76 bus_dma_segment_t *, int, bus_size_t, int);
77void _isa_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t); 77void _isa_bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
78void _isa_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, 78void _isa_bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t,
79 bus_addr_t, bus_size_t, int); 79 bus_addr_t, bus_size_t, int);
80 80
81int _isa_bus_dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, 81int _isa_bus_dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t,
82 bus_size_t, bus_dma_segment_t *, int, int *, int); 82 bus_size_t, bus_dma_segment_t *, int, int *, int);
83 83
84int _isa_dma_alloc_bouncebuf(bus_dma_tag_t, bus_dmamap_t, 84int _isa_dma_alloc_bouncebuf(bus_dma_tag_t, bus_dmamap_t,
85 bus_size_t, int); 85 bus_size_t, int);
86void _isa_dma_free_bouncebuf(bus_dma_tag_t, bus_dmamap_t); 86void _isa_dma_free_bouncebuf(bus_dma_tag_t, bus_dmamap_t);
87 87
88/* 88/*
89 * Entry points for ISA DMA. These are mostly wrappers around 89 * Entry points for ISA DMA. These are mostly wrappers around
90 * the generic functions that understand how to deal with bounce 90 * the generic functions that understand how to deal with bounce
91 * buffers, if necessary. 91 * buffers, if necessary.
92 */ 92 */
93struct arm32_bus_dma_tag isa_bus_dma_tag = { 93struct arm32_bus_dma_tag isa_bus_dma_tag = {
94 0, /* _ranges */ 94 0, /* _ranges */
95 0, /* _nranges */ 95 0, /* _nranges */
96 NULL, /* _cookie */ 96 NULL, /* _cookie */
97 _isa_bus_dmamap_create, 97 _isa_bus_dmamap_create,
98 _isa_bus_dmamap_destroy, 98 _isa_bus_dmamap_destroy,
99 _isa_bus_dmamap_load, 99 _isa_bus_dmamap_load,
100 _isa_bus_dmamap_load_mbuf, 100 _isa_bus_dmamap_load_mbuf,
101 _isa_bus_dmamap_load_uio, 101 _isa_bus_dmamap_load_uio,
102 _isa_bus_dmamap_load_raw, 102 _isa_bus_dmamap_load_raw,
103 _isa_bus_dmamap_unload, 103 _isa_bus_dmamap_unload,
104 _isa_bus_dmamap_sync, /* pre */ 104 _isa_bus_dmamap_sync, /* pre */
105 _isa_bus_dmamap_sync, /* post */ 105 _isa_bus_dmamap_sync, /* post */
106 _isa_bus_dmamem_alloc, 106 _isa_bus_dmamem_alloc,
107 _bus_dmamem_free, 107 _bus_dmamem_free,
108 _bus_dmamem_map, 108 _bus_dmamem_map,
109 _bus_dmamem_unmap, 109 _bus_dmamem_unmap,
110 _bus_dmamem_mmap,  110 _bus_dmamem_mmap,
111}; 111};
112 112
113/* 113/*
114 * Initialize ISA DMA. 114 * Initialize ISA DMA.
115 */ 115 */
116void 116void
117isa_dma_init(void) 117isa_dma_init(void)
118{ 118{
119 119
120 isa_bus_dma_tag._ranges = shark_isa_dma_ranges; 120 isa_bus_dma_tag._ranges = shark_isa_dma_ranges;
121 isa_bus_dma_tag._nranges = shark_isa_dma_nranges; 121 isa_bus_dma_tag._nranges = shark_isa_dma_nranges;
122} 122}
123 123
124/********************************************************************** 124/**********************************************************************
125 * bus.h dma interface entry points 125 * bus.h dma interface entry points
126 **********************************************************************/ 126 **********************************************************************/
127 127
128#ifdef ISA_DMA_STATS 128#ifdef ISA_DMA_STATS
129#define STAT_INCR(v) (v)++ 129#define STAT_INCR(v) (v)++
130#define STAT_DECR(v) do { \ 130#define STAT_DECR(v) do { \
131 if ((v) == 0) \ 131 if ((v) == 0) \
132 printf("%s:%d -- Already 0!\n", __FILE__, __LINE__); \ 132 printf("%s:%d -- Already 0!\n", __FILE__, __LINE__); \
133 else \ 133 else \
134 (v)--; \ 134 (v)--; \
135 } while (0) 135 } while (0)
136u_long isa_dma_stats_loads; 136u_long isa_dma_stats_loads;
137u_long isa_dma_stats_bounces; 137u_long isa_dma_stats_bounces;
138u_long isa_dma_stats_nbouncebufs; 138u_long isa_dma_stats_nbouncebufs;
139#else 139#else
140#define STAT_INCR(v) 140#define STAT_INCR(v)
141#define STAT_DECR(v) 141#define STAT_DECR(v)
142#endif 142#endif
143 143
144/* 144/*
145 * Create an ISA DMA map. 145 * Create an ISA DMA map.
146 */ 146 */
147int 147int
148_isa_bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments, bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamp) 148_isa_bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments, bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamp)
149{ 149{
150 struct arm32_isa_dma_cookie *cookie; 150 struct arm32_isa_dma_cookie *cookie;
151 bus_dmamap_t map; 151 bus_dmamap_t map;
152 int error, cookieflags; 152 int error, cookieflags;
153 void *cookiestore; 153 void *cookiestore;
154 size_t cookiesize; 154 size_t cookiesize;
155 155
156 /* Call common function to create the basic map. */ 156 /* Call common function to create the basic map. */
157 error = _bus_dmamap_create(t, size, nsegments, maxsegsz, boundary, 157 error = _bus_dmamap_create(t, size, nsegments, maxsegsz, boundary,
158 flags, dmamp); 158 flags, dmamp);
159 if (error) 159 if (error)
160 return (error); 160 return (error);
161 161
162 map = *dmamp; 162 map = *dmamp;
163 map->_dm_cookie = NULL; 163 map->_dm_cookie = NULL;
164 164
165 cookiesize = sizeof(struct arm32_isa_dma_cookie); 165 cookiesize = sizeof(struct arm32_isa_dma_cookie);
166 166
167 /* 167 /*
168 * ISA only has 24-bits of address space. This means 168 * ISA only has 24-bits of address space. This means
169 * we can't DMA to pages over 16M. In order to DMA to 169 * we can't DMA to pages over 16M. In order to DMA to
170 * arbitrary buffers, we use "bounce buffers" - pages 170 * arbitrary buffers, we use "bounce buffers" - pages
171 * in memory below the 16M boundary. On DMA reads, 171 * in memory below the 16M boundary. On DMA reads,
172 * DMA happens to the bounce buffers, and is copied into 172 * DMA happens to the bounce buffers, and is copied into
173 * the caller's buffer. On writes, data is copied into 173 * the caller's buffer. On writes, data is copied into
174 * but bounce buffer, and the DMA happens from those 174 * but bounce buffer, and the DMA happens from those
175 * pages. To software using the DMA mapping interface, 175 * pages. To software using the DMA mapping interface,
176 * this looks simply like a data cache. 176 * this looks simply like a data cache.
177 * 177 *
178 * If we have more than 16M of RAM in the system, we may 178 * If we have more than 16M of RAM in the system, we may
179 * need bounce buffers. We check and remember that here. 179 * need bounce buffers. We check and remember that here.
180 * 180 *
181 * There are exceptions, however. VLB devices can do 181 * There are exceptions, however. VLB devices can do
182 * 32-bit DMA, and indicate that here. 182 * 32-bit DMA, and indicate that here.
183 * 183 *
184 * ...or, there is an opposite case. The most segments 184 * ...or, there is an opposite case. The most segments
185 * a transfer will require is (maxxfer / PAGE_SIZE) + 1. If 185 * a transfer will require is (maxxfer / PAGE_SIZE) + 1. If
186 * the caller can't handle that many segments (e.g. the 186 * the caller can't handle that many segments (e.g. the
187 * ISA DMA controller), we may have to bounce it as well. 187 * ISA DMA controller), we may have to bounce it as well.
188 * 188 *
189 * Well, not really... see note above regarding DMA ranges. 189 * Well, not really... see note above regarding DMA ranges.
190 * Because of the range issue on this platform, we just 190 * Because of the range issue on this platform, we just
191 * always "might bounce". 191 * always "might bounce".
192 */ 192 */
193 cookieflags = ID_MIGHT_NEED_BOUNCE; 193 cookieflags = ID_MIGHT_NEED_BOUNCE;
194 cookiesize += (sizeof(bus_dma_segment_t) * map->_dm_segcnt); 194 cookiesize += (sizeof(bus_dma_segment_t) * map->_dm_segcnt);
195 195
196 /* 196 /*
197 * Allocate our cookie. 197 * Allocate our cookie.
198 */ 198 */
199 if ((cookiestore = malloc(cookiesize, M_DMAMAP, 199 if ((cookiestore = malloc(cookiesize, M_DMAMAP,
200 (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) { 200 (flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL) {
201 error = ENOMEM; 201 error = ENOMEM;
202 goto out; 202 goto out;
203 } 203 }
204 memset(cookiestore, 0, cookiesize); 204 memset(cookiestore, 0, cookiesize);
205 cookie = (struct arm32_isa_dma_cookie *)cookiestore; 205 cookie = (struct arm32_isa_dma_cookie *)cookiestore;
206 cookie->id_flags = cookieflags; 206 cookie->id_flags = cookieflags;
207 map->_dm_cookie = cookie; 207 map->_dm_cookie = cookie;
208 208
209 if (cookieflags & ID_MIGHT_NEED_BOUNCE) { 209 if (cookieflags & ID_MIGHT_NEED_BOUNCE) {
210 /* 210 /*
211 * Allocate the bounce pages now if the caller 211 * Allocate the bounce pages now if the caller
212 * wishes us to do so. 212 * wishes us to do so.
213 */ 213 */
214 if ((flags & BUS_DMA_ALLOCNOW) == 0) 214 if ((flags & BUS_DMA_ALLOCNOW) == 0)
215 goto out; 215 goto out;
216 216
217 error = _isa_dma_alloc_bouncebuf(t, map, size, flags); 217 error = _isa_dma_alloc_bouncebuf(t, map, size, flags);
218 } 218 }
219 219
220 out: 220 out:
221 if (error) { 221 if (error) {
222 if (map->_dm_cookie != NULL) 222 if (map->_dm_cookie != NULL)
223 free(map->_dm_cookie, M_DMAMAP); 223 free(map->_dm_cookie, M_DMAMAP);
224 _bus_dmamap_destroy(t, map); 224 _bus_dmamap_destroy(t, map);
225 } 225 }
226 return (error); 226 return (error);
227} 227}
228 228
229/* 229/*
230 * Destroy an ISA DMA map. 230 * Destroy an ISA DMA map.
231 */ 231 */
232void 232void
233_isa_bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map) 233_isa_bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
234{ 234{
235 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie; 235 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie;
236 236
237 /* 237 /*
238 * Free any bounce pages this map might hold. 238 * Free any bounce pages this map might hold.
239 */ 239 */
240 if (cookie->id_flags & ID_HAS_BOUNCE) 240 if (cookie->id_flags & ID_HAS_BOUNCE)
241 _isa_dma_free_bouncebuf(t, map); 241 _isa_dma_free_bouncebuf(t, map);
242 242
243 free(cookie, M_DMAMAP); 243 free(cookie, M_DMAMAP);
244 _bus_dmamap_destroy(t, map); 244 _bus_dmamap_destroy(t, map);
245} 245}
246 246
247/* 247/*
248 * Load an ISA DMA map with a linear buffer. 248 * Load an ISA DMA map with a linear buffer.
249 */ 249 */
250int 250int
251_isa_bus_dmamap_load(t, map, buf, buflen, p, flags) 251_isa_bus_dmamap_load(bus_dma_tag_t t, bus_dmamap_t map, void *buf,
252 bus_dma_tag_t t; 252 bus_size_t buflen, struct proc *p, int flags)
253 bus_dmamap_t map;  
254 void *buf; 
255 bus_size_t buflen; 
256 struct proc *p; 
257 int flags; 
258{ 253{
259 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie; 254 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie;
260 int error; 255 int error;
261 256
262 STAT_INCR(isa_dma_stats_loads); 257 STAT_INCR(isa_dma_stats_loads);
263 258
264 /* 259 /*
265 * Make sure that on error condition we return "no valid mappings." 260 * Make sure that on error condition we return "no valid mappings."
266 */ 261 */
267 map->dm_mapsize = 0; 262 map->dm_mapsize = 0;
268 map->dm_nsegs = 0; 263 map->dm_nsegs = 0;
269 264
270 /* 265 /*
271 * Try to load the map the normal way. If this errors out, 266 * Try to load the map the normal way. If this errors out,
272 * and we can bounce, we will. 267 * and we can bounce, we will.
273 */ 268 */
274 error = _bus_dmamap_load(t, map, buf, buflen, p, flags); 269 error = _bus_dmamap_load(t, map, buf, buflen, p, flags);
275 if (error == 0 || 270 if (error == 0 ||
276 (error != 0 && (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) == 0)) 271 (error != 0 && (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) == 0))
277 return (error); 272 return (error);
278 273
279 /* 274 /*
280 * First attempt failed; bounce it. 275 * First attempt failed; bounce it.
281 */ 276 */
282 277
283 STAT_INCR(isa_dma_stats_bounces); 278 STAT_INCR(isa_dma_stats_bounces);
284 279
285 /* 280 /*
286 * Allocate bounce pages, if necessary. 281 * Allocate bounce pages, if necessary.
287 */ 282 */
288 if ((cookie->id_flags & ID_HAS_BOUNCE) == 0) { 283 if ((cookie->id_flags & ID_HAS_BOUNCE) == 0) {
289 error = _isa_dma_alloc_bouncebuf(t, map, buflen, flags); 284 error = _isa_dma_alloc_bouncebuf(t, map, buflen, flags);
290 if (error) 285 if (error)
291 return (error); 286 return (error);
292 } 287 }
293 288
294 /* 289 /*
295 * Cache a pointer to the caller's buffer and load the DMA map 290 * Cache a pointer to the caller's buffer and load the DMA map
296 * with the bounce buffer. 291 * with the bounce buffer.
297 */ 292 */
298 cookie->id_origbuf = buf; 293 cookie->id_origbuf = buf;
299 cookie->id_origbuflen = buflen; 294 cookie->id_origbuflen = buflen;
300 cookie->id_buftype = ID_BUFTYPE_LINEAR; 295 cookie->id_buftype = ID_BUFTYPE_LINEAR;
301 error = _bus_dmamap_load(t, map, cookie->id_bouncebuf, buflen, 296 error = _bus_dmamap_load(t, map, cookie->id_bouncebuf, buflen,
302 NULL, flags); 297 NULL, flags);
303 if (error) { 298 if (error) {
304 /* 299 /*
305 * Free the bounce pages, unless our resources 300 * Free the bounce pages, unless our resources
306 * are reserved for our exclusive use. 301 * are reserved for our exclusive use.
307 */ 302 */
308 if ((map->_dm_flags & BUS_DMA_ALLOCNOW) == 0) 303 if ((map->_dm_flags & BUS_DMA_ALLOCNOW) == 0)
309 _isa_dma_free_bouncebuf(t, map); 304 _isa_dma_free_bouncebuf(t, map);
310 return (error); 305 return (error);
311 } 306 }
312 307
313 /* ...so _isa_bus_dmamap_sync() knows we're bouncing */ 308 /* ...so _isa_bus_dmamap_sync() knows we're bouncing */
314 cookie->id_flags |= ID_IS_BOUNCING; 309 cookie->id_flags |= ID_IS_BOUNCING;
315 return (0); 310 return (0);
316} 311}
317 312
318/* 313/*
319 * Like _isa_bus_dmamap_load(), but for mbufs. 314 * Like _isa_bus_dmamap_load(), but for mbufs.
320 */ 315 */
321int 316int
322_isa_bus_dmamap_load_mbuf(t, map, m0, flags)  317_isa_bus_dmamap_load_mbuf( bus_dma_tag_t t, bus_dmamap_t map, struct mbuf *m0,
323 bus_dma_tag_t t; 318 int flags)
324 bus_dmamap_t map; 
325 struct mbuf *m0; 
326 int flags; 
327{ 319{
328 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie; 320 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie;
329 int error; 321 int error;
330 322
331 /* 323 /*
332 * Make sure that on error condition we return "no valid mappings." 324 * Make sure that on error condition we return "no valid mappings."
333 */ 325 */
334 map->dm_mapsize = 0; 326 map->dm_mapsize = 0;
335 map->dm_nsegs = 0; 327 map->dm_nsegs = 0;
336 328
337#ifdef DIAGNOSTIC 329#ifdef DIAGNOSTIC
338 if ((m0->m_flags & M_PKTHDR) == 0) 330 if ((m0->m_flags & M_PKTHDR) == 0)
339 panic("_isa_bus_dmamap_load_mbuf: no packet header"); 331 panic("_isa_bus_dmamap_load_mbuf: no packet header");
340#endif 332#endif
341 333
342 if (m0->m_pkthdr.len > map->_dm_size) 334 if (m0->m_pkthdr.len > map->_dm_size)
343 return (EINVAL); 335 return (EINVAL);
344 336
345 /* 337 /*
346 * Try to load the map the normal way. If this errors out, 338 * Try to load the map the normal way. If this errors out,
347 * and we can bounce, we will. 339 * and we can bounce, we will.
348 */ 340 */
349 error = _bus_dmamap_load_mbuf(t, map, m0, flags); 341 error = _bus_dmamap_load_mbuf(t, map, m0, flags);
350 if (error == 0 || 342 if (error == 0 ||
351 (error != 0 && (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) == 0)) 343 (error != 0 && (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) == 0))
352 return (error); 344 return (error);
353 345
354 /* 346 /*
355 * First attempt failed; bounce it. 347 * First attempt failed; bounce it.
356 */ 348 */
357 349
358 STAT_INCR(isa_dma_stats_bounces); 350 STAT_INCR(isa_dma_stats_bounces);
359 351
360 /* 352 /*
361 * Allocate bounce pages, if necessary. 353 * Allocate bounce pages, if necessary.
362 */ 354 */
363 if ((cookie->id_flags & ID_HAS_BOUNCE) == 0) { 355 if ((cookie->id_flags & ID_HAS_BOUNCE) == 0) {
364 error = _isa_dma_alloc_bouncebuf(t, map, m0->m_pkthdr.len, 356 error = _isa_dma_alloc_bouncebuf(t, map, m0->m_pkthdr.len,
365 flags); 357 flags);
366 if (error) 358 if (error)
367 return (error); 359 return (error);
368 } 360 }
369 361
370 /* 362 /*
371 * Cache a pointer to the caller's buffer and load the DMA map 363 * Cache a pointer to the caller's buffer and load the DMA map
372 * with the bounce buffer. 364 * with the bounce buffer.
373 */ 365 */
374 cookie->id_origbuf = m0; 366 cookie->id_origbuf = m0;
375 cookie->id_origbuflen = m0->m_pkthdr.len; /* not really used */ 367 cookie->id_origbuflen = m0->m_pkthdr.len; /* not really used */
376 cookie->id_buftype = ID_BUFTYPE_MBUF; 368 cookie->id_buftype = ID_BUFTYPE_MBUF;
377 error = _bus_dmamap_load(t, map, cookie->id_bouncebuf, 369 error = _bus_dmamap_load(t, map, cookie->id_bouncebuf,
378 m0->m_pkthdr.len, NULL, flags); 370 m0->m_pkthdr.len, NULL, flags);
379 if (error) { 371 if (error) {
380 /* 372 /*
381 * Free the bounce pages, unless our resources 373 * Free the bounce pages, unless our resources
382 * are reserved for our exclusive use. 374 * are reserved for our exclusive use.
383 */ 375 */
384 if ((map->_dm_flags & BUS_DMA_ALLOCNOW) == 0) 376 if ((map->_dm_flags & BUS_DMA_ALLOCNOW) == 0)
385 _isa_dma_free_bouncebuf(t, map); 377 _isa_dma_free_bouncebuf(t, map);
386 return (error); 378 return (error);
387 } 379 }
388 380
389 /* ...so _isa_bus_dmamap_sync() knows we're bouncing */ 381 /* ...so _isa_bus_dmamap_sync() knows we're bouncing */
390 cookie->id_flags |= ID_IS_BOUNCING; 382 cookie->id_flags |= ID_IS_BOUNCING;
391 return (0); 383 return (0);
392} 384}
393 385
394/* 386/*
395 * Like _isa_bus_dmamap_load(), but for uios. 387 * Like _isa_bus_dmamap_load(), but for uios.
396 */ 388 */
397int 389int
398_isa_bus_dmamap_load_uio(bus_dma_tag_t t, bus_dmamap_t map, struct uio *uio, int flags) 390_isa_bus_dmamap_load_uio(bus_dma_tag_t t, bus_dmamap_t map, struct uio *uio, int flags)
399{ 391{
400 392
401 panic("_isa_bus_dmamap_load_uio: not implemented"); 393 panic("_isa_bus_dmamap_load_uio: not implemented");
402} 394}
403 395
404/* 396/*
405 * Like _isa_bus_dmamap_load(), but for raw memory allocated with 397 * Like _isa_bus_dmamap_load(), but for raw memory allocated with
406 * bus_dmamem_alloc(). 398 * bus_dmamem_alloc().
407 */ 399 */
408int 400int
409_isa_bus_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t map, bus_dma_segment_t *segs, int nsegs, bus_size_t size, int flags) 401_isa_bus_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t map, bus_dma_segment_t *segs, int nsegs, bus_size_t size, int flags)
410{ 402{
411 403
412 panic("_isa_bus_dmamap_load_raw: not implemented"); 404 panic("_isa_bus_dmamap_load_raw: not implemented");
413} 405}
414 406
415/* 407/*
416 * Unload an ISA DMA map. 408 * Unload an ISA DMA map.
417 */ 409 */
418void 410void
419_isa_bus_dmamap_unload(bus_dma_tag_t t, bus_dmamap_t map) 411_isa_bus_dmamap_unload(bus_dma_tag_t t, bus_dmamap_t map)
420{ 412{
421 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie; 413 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie;
422 414
423 /* 415 /*
424 * If we have bounce pages, free them, unless they're 416 * If we have bounce pages, free them, unless they're
425 * reserved for our exclusive use. 417 * reserved for our exclusive use.
426 */ 418 */
427 if ((cookie->id_flags & ID_HAS_BOUNCE) && 419 if ((cookie->id_flags & ID_HAS_BOUNCE) &&
428 (map->_dm_flags & BUS_DMA_ALLOCNOW) == 0) 420 (map->_dm_flags & BUS_DMA_ALLOCNOW) == 0)
429 _isa_dma_free_bouncebuf(t, map); 421 _isa_dma_free_bouncebuf(t, map);
430 422
431 cookie->id_flags &= ~ID_IS_BOUNCING; 423 cookie->id_flags &= ~ID_IS_BOUNCING;
432 cookie->id_buftype = ID_BUFTYPE_INVALID; 424 cookie->id_buftype = ID_BUFTYPE_INVALID;
433 425
434 /* 426 /*
435 * Do the generic bits of the unload. 427 * Do the generic bits of the unload.
436 */ 428 */
437 _bus_dmamap_unload(t, map); 429 _bus_dmamap_unload(t, map);
438} 430}
439 431
440/* 432/*
441 * Synchronize an ISA DMA map. 433 * Synchronize an ISA DMA map.
442 */ 434 */
443void 435void
444_isa_bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t map, bus_addr_t offset, bus_size_t len, int ops) 436_isa_bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t map, bus_addr_t offset, bus_size_t len, int ops)
445{ 437{
446 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie; 438 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie;
447 439
448 /* 440 /*
449 * Mixing PRE and POST operations is not allowed. 441 * Mixing PRE and POST operations is not allowed.
450 */ 442 */
451 if ((ops & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)) != 0 && 443 if ((ops & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)) != 0 &&
452 (ops & (BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)) != 0) 444 (ops & (BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)) != 0)
453 panic("_isa_bus_dmamap_sync: mix PRE and POST"); 445 panic("_isa_bus_dmamap_sync: mix PRE and POST");
454 446
455#ifdef DIAGNOSTIC 447#ifdef DIAGNOSTIC
456 if ((ops & (BUS_DMASYNC_PREWRITE|BUS_DMASYNC_POSTREAD)) != 0) { 448 if ((ops & (BUS_DMASYNC_PREWRITE|BUS_DMASYNC_POSTREAD)) != 0) {
457 if (offset >= map->dm_mapsize) 449 if (offset >= map->dm_mapsize)
458 panic("_isa_bus_dmamap_sync: bad offset"); 450 panic("_isa_bus_dmamap_sync: bad offset");
459 if (len == 0 || (offset + len) > map->dm_mapsize) 451 if (len == 0 || (offset + len) > map->dm_mapsize)
460 panic("_isa_bus_dmamap_sync: bad length"); 452 panic("_isa_bus_dmamap_sync: bad length");
461 } 453 }
462#endif 454#endif
463 455
464 /* 456 /*
465 * If we're not bouncing, just return; nothing to do. 457 * If we're not bouncing, just return; nothing to do.
466 */ 458 */
467 if ((cookie->id_flags & ID_IS_BOUNCING) == 0) 459 if ((cookie->id_flags & ID_IS_BOUNCING) == 0)
468 return; 460 return;
469 461
470 switch (cookie->id_buftype) { 462 switch (cookie->id_buftype) {
471 case ID_BUFTYPE_LINEAR: 463 case ID_BUFTYPE_LINEAR:
472 /* 464 /*
473 * Nothing to do for pre-read. 465 * Nothing to do for pre-read.
474 */ 466 */
475 467
476 if (ops & BUS_DMASYNC_PREWRITE) { 468 if (ops & BUS_DMASYNC_PREWRITE) {
477 /* 469 /*
478 * Copy the caller's buffer to the bounce buffer. 470 * Copy the caller's buffer to the bounce buffer.
479 */ 471 */
480 memcpy((char *)cookie->id_bouncebuf + offset, 472 memcpy((char *)cookie->id_bouncebuf + offset,
481 (char *)cookie->id_origbuf + offset, len); 473 (char *)cookie->id_origbuf + offset, len);
482 } 474 }
483 475
484 if (ops & BUS_DMASYNC_POSTREAD) { 476 if (ops & BUS_DMASYNC_POSTREAD) {
485 /* 477 /*
486 * Copy the bounce buffer to the caller's buffer. 478 * Copy the bounce buffer to the caller's buffer.
487 */ 479 */
488 memcpy((char *)cookie->id_origbuf + offset, 480 memcpy((char *)cookie->id_origbuf + offset,
489 (char *)cookie->id_bouncebuf + offset, len); 481 (char *)cookie->id_bouncebuf + offset, len);
490 } 482 }
491 483
492 /* 484 /*
493 * Nothing to do for post-write. 485 * Nothing to do for post-write.
494 */ 486 */
495 break; 487 break;
496 488
497 case ID_BUFTYPE_MBUF: 489 case ID_BUFTYPE_MBUF:
498 { 490 {
499 struct mbuf *m, *m0 = cookie->id_origbuf; 491 struct mbuf *m, *m0 = cookie->id_origbuf;
500 bus_size_t minlen, moff; 492 bus_size_t minlen, moff;
501 493
502 /* 494 /*
503 * Nothing to do for pre-read. 495 * Nothing to do for pre-read.
504 */ 496 */
505 497
506 if (ops & BUS_DMASYNC_PREWRITE) { 498 if (ops & BUS_DMASYNC_PREWRITE) {
507 /* 499 /*
508 * Copy the caller's buffer to the bounce buffer. 500 * Copy the caller's buffer to the bounce buffer.
509 */ 501 */
510 m_copydata(m0, offset, len, 502 m_copydata(m0, offset, len,
511 (char *)cookie->id_bouncebuf + offset); 503 (char *)cookie->id_bouncebuf + offset);
512 } 504 }
513 505
514 if (ops & BUS_DMASYNC_POSTREAD) { 506 if (ops & BUS_DMASYNC_POSTREAD) {
515 /* 507 /*
516 * Copy the bounce buffer to the caller's buffer. 508 * Copy the bounce buffer to the caller's buffer.
517 */ 509 */
518 for (moff = offset, m = m0; m != NULL && len != 0; 510 for (moff = offset, m = m0; m != NULL && len != 0;
519 m = m->m_next) { 511 m = m->m_next) {
520 /* Find the beginning mbuf. */ 512 /* Find the beginning mbuf. */
521 if (moff >= m->m_len) { 513 if (moff >= m->m_len) {
522 moff -= m->m_len; 514 moff -= m->m_len;
523 continue; 515 continue;
524 } 516 }
525 517
526 /* 518 /*
527 * Now at the first mbuf to sync; nail 519 * Now at the first mbuf to sync; nail
528 * each one until we have exhausted the 520 * each one until we have exhausted the
529 * length. 521 * length.
530 */ 522 */
531 minlen = len < m->m_len - moff ? 523 minlen = len < m->m_len - moff ?
532 len : m->m_len - moff; 524 len : m->m_len - moff;
533 525
534 memcpy(mtod(m, char *) + moff, 526 memcpy(mtod(m, char *) + moff,
535 (char *)cookie->id_bouncebuf + offset, 527 (char *)cookie->id_bouncebuf + offset,
536 minlen); 528 minlen);
537 529
538 moff = 0; 530 moff = 0;
539 len -= minlen; 531 len -= minlen;
540 offset += minlen; 532 offset += minlen;
541 } 533 }
542 } 534 }
543 535
544 /* 536 /*
545 * Nothing to do for post-write. 537 * Nothing to do for post-write.
546 */ 538 */
547 break; 539 break;
548 } 540 }
549  541
550 case ID_BUFTYPE_UIO: 542 case ID_BUFTYPE_UIO:
551 panic("_isa_bus_dmamap_sync: ID_BUFTYPE_UIO"); 543 panic("_isa_bus_dmamap_sync: ID_BUFTYPE_UIO");
552 break; 544 break;
553 545
554 case ID_BUFTYPE_RAW: 546 case ID_BUFTYPE_RAW:
555 panic("_isa_bus_dmamap_sync: ID_BUFTYPE_RAW"); 547 panic("_isa_bus_dmamap_sync: ID_BUFTYPE_RAW");
556 break; 548 break;
557 549
558 case ID_BUFTYPE_INVALID: 550 case ID_BUFTYPE_INVALID:
559 panic("_isa_bus_dmamap_sync: ID_BUFTYPE_INVALID"); 551 panic("_isa_bus_dmamap_sync: ID_BUFTYPE_INVALID");
560 break; 552 break;
561 553
562 default: 554 default:
563 printf("unknown buffer type %d\n", cookie->id_buftype); 555 printf("unknown buffer type %d\n", cookie->id_buftype);
564 panic("_isa_bus_dmamap_sync"); 556 panic("_isa_bus_dmamap_sync");
565 } 557 }
566} 558}
567 559
568/* 560/*
569 * Allocate memory safe for ISA DMA. 561 * Allocate memory safe for ISA DMA.
570 */ 562 */
571int 563int
572_isa_bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags) 564_isa_bus_dmamem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs, int flags)
573{ 565{
574 566
575 if (t->_ranges == NULL) 567 if (t->_ranges == NULL)
576 return (ENOMEM); 568 return (ENOMEM);
577 569
578 /* _bus_dmamem_alloc() does the range checks for us. */ 570 /* _bus_dmamem_alloc() does the range checks for us. */
579 return (_bus_dmamem_alloc(t, size, alignment, boundary, segs, nsegs, 571 return (_bus_dmamem_alloc(t, size, alignment, boundary, segs, nsegs,
580 rsegs, flags)); 572 rsegs, flags));
581} 573}
582 574
583/********************************************************************** 575/**********************************************************************
584 * ISA DMA utility functions 576 * ISA DMA utility functions
585 **********************************************************************/ 577 **********************************************************************/
586 578
587int 579int
588_isa_dma_alloc_bouncebuf(bus_dma_tag_t t, bus_dmamap_t map, bus_size_t size, int flags) 580_isa_dma_alloc_bouncebuf(bus_dma_tag_t t, bus_dmamap_t map, bus_size_t size, int flags)
589{ 581{
590 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie; 582 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie;
591 int error = 0; 583 int error = 0;
592 584
593 cookie->id_bouncebuflen = round_page(size); 585 cookie->id_bouncebuflen = round_page(size);
594 error = _isa_bus_dmamem_alloc(t, cookie->id_bouncebuflen, 586 error = _isa_bus_dmamem_alloc(t, cookie->id_bouncebuflen,
595 PAGE_SIZE, map->_dm_boundary, cookie->id_bouncesegs, 587 PAGE_SIZE, map->_dm_boundary, cookie->id_bouncesegs,
596 map->_dm_segcnt, &cookie->id_nbouncesegs, flags); 588 map->_dm_segcnt, &cookie->id_nbouncesegs, flags);
597 if (error) 589 if (error)
598 goto out; 590 goto out;
599 error = _bus_dmamem_map(t, cookie->id_bouncesegs, 591 error = _bus_dmamem_map(t, cookie->id_bouncesegs,
600 cookie->id_nbouncesegs, cookie->id_bouncebuflen, 592 cookie->id_nbouncesegs, cookie->id_bouncebuflen,
601 (void **)&cookie->id_bouncebuf, flags); 593 (void **)&cookie->id_bouncebuf, flags);
602 594
603 out: 595 out:
604 if (error) { 596 if (error) {
605 _bus_dmamem_free(t, cookie->id_bouncesegs, 597 _bus_dmamem_free(t, cookie->id_bouncesegs,
606 cookie->id_nbouncesegs); 598 cookie->id_nbouncesegs);
607 cookie->id_bouncebuflen = 0; 599 cookie->id_bouncebuflen = 0;
608 cookie->id_nbouncesegs = 0; 600 cookie->id_nbouncesegs = 0;
609 } else { 601 } else {
610 cookie->id_flags |= ID_HAS_BOUNCE; 602 cookie->id_flags |= ID_HAS_BOUNCE;
611 STAT_INCR(isa_dma_stats_nbouncebufs); 603 STAT_INCR(isa_dma_stats_nbouncebufs);
612 } 604 }
613 605
614 return (error); 606 return (error);
615} 607}
616 608
617void 609void
618_isa_dma_free_bouncebuf(bus_dma_tag_t t, bus_dmamap_t map) 610_isa_dma_free_bouncebuf(bus_dma_tag_t t, bus_dmamap_t map)
619{ 611{
620 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie; 612 struct arm32_isa_dma_cookie *cookie = map->_dm_cookie;
621 613
622 STAT_DECR(isa_dma_stats_nbouncebufs); 614 STAT_DECR(isa_dma_stats_nbouncebufs);
623 615
624 _bus_dmamem_unmap(t, cookie->id_bouncebuf, 616 _bus_dmamem_unmap(t, cookie->id_bouncebuf,
625 cookie->id_bouncebuflen); 617 cookie->id_bouncebuflen);
626 _bus_dmamem_free(t, cookie->id_bouncesegs, 618 _bus_dmamem_free(t, cookie->id_bouncesegs,
627 cookie->id_nbouncesegs); 619 cookie->id_nbouncesegs);
628 cookie->id_bouncebuflen = 0; 620 cookie->id_bouncebuflen = 0;
629 cookie->id_nbouncesegs = 0; 621 cookie->id_nbouncesegs = 0;
630 cookie->id_flags &= ~ID_HAS_BOUNCE; 622 cookie->id_flags &= ~ID_HAS_BOUNCE;
631} 623}

cvs diff -r1.26 -r1.27 src/sys/arch/shark/shark/scr.c (switch to unified diff)

--- src/sys/arch/shark/shark/scr.c 2011/07/26 08:56:26 1.26
+++ src/sys/arch/shark/shark/scr.c 2012/01/31 04:28:50 1.27
@@ -1,1104 +1,1104 @@ @@ -1,1104 +1,1104 @@
1/* $NetBSD: scr.c,v 1.26 2011/07/26 08:56:26 mrg Exp $ */ 1/* $NetBSD: scr.c,v 1.27 2012/01/31 04:28:50 matt Exp $ */
2 2
3/* 3/*
4 * Copyright 1997 4 * Copyright 1997
5 * Digital Equipment Corporation. All rights reserved. 5 * Digital Equipment Corporation. All rights reserved.
6 * 6 *
7 * This software is furnished under license and may be used and 7 * This software is furnished under license and may be used and
8 * copied only in accordance with the following terms and conditions. 8 * copied only in accordance with the following terms and conditions.
9 * Subject to these conditions, you may download, copy, install, 9 * Subject to these conditions, you may download, copy, install,
10 * use, modify and distribute this software in source and/or binary 10 * use, modify and distribute this software in source and/or binary
11 * form. No title or ownership is transferred hereby. 11 * form. No title or ownership is transferred hereby.
12 * 12 *
13 * 1) Any source code used, modified or distributed must reproduce 13 * 1) Any source code used, modified or distributed must reproduce
14 * and retain this copyright notice and list of conditions as 14 * and retain this copyright notice and list of conditions as
15 * they appear in the source file. 15 * they appear in the source file.
16 * 16 *
17 * 2) No right is granted to use any trade name, trademark, or logo of 17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Digital Equipment Corporation. Neither the "Digital Equipment 18 * Digital Equipment Corporation. Neither the "Digital Equipment
19 * Corporation" name nor any trademark or logo of Digital Equipment 19 * Corporation" name nor any trademark or logo of Digital Equipment
20 * Corporation may be used to endorse or promote products derived 20 * Corporation may be used to endorse or promote products derived
21 * from this software without the prior written permission of 21 * from this software without the prior written permission of
22 * Digital Equipment Corporation. 22 * Digital Equipment Corporation.
23 * 23 *
24 * 3) This software is provided "AS-IS" and any express or implied 24 * 3) This software is provided "AS-IS" and any express or implied
25 * warranties, including but not limited to, any implied warranties 25 * warranties, including but not limited to, any implied warranties
26 * of merchantability, fitness for a particular purpose, or 26 * of merchantability, fitness for a particular purpose, or
27 * non-infringement are disclaimed. In no event shall DIGITAL be 27 * non-infringement are disclaimed. In no event shall DIGITAL be
28 * liable for any damages whatsoever, and in particular, DIGITAL 28 * liable for any damages whatsoever, and in particular, DIGITAL
29 * shall not be liable for special, indirect, consequential, or 29 * shall not be liable for special, indirect, consequential, or
30 * incidental damages or damages for lost profits, loss of 30 * incidental damages or damages for lost profits, loss of
31 * revenue or loss of use, whether such damages arise in contract, 31 * revenue or loss of use, whether such damages arise in contract,
32 * negligence, tort, under statute, in equity, at law or otherwise, 32 * negligence, tort, under statute, in equity, at law or otherwise,
33 * even if advised of the possibility of such damage. 33 * even if advised of the possibility of such damage.
34 */ 34 */
35 35
36/* 36/*
37**++ 37**++
38**  38**
39** FACILITY: 39** FACILITY:
40** 40**
41** Driver for smart card 41** Driver for smart card
42** 42**
43** ABSTRACT: 43** ABSTRACT:
44** 44**
45** The driver provides access to a Smart Card for the DNARD.  45** The driver provides access to a Smart Card for the DNARD.
46** 46**
47** There is no Smart Card silicon. Several i/o pins 47** There is no Smart Card silicon. Several i/o pins
48** connect to the pads on the Smart Card, and the driver is  48** connect to the pads on the Smart Card, and the driver is
49** is responsible for driving the signals in accordance with  49** is responsible for driving the signals in accordance with
50** ISO 7816-3 (the Smart Card spec) 50** ISO 7816-3 (the Smart Card spec)
51** 51**
52** This driver puts a high load on the system due to the need 52** This driver puts a high load on the system due to the need
53** to interrupt at a high rate (up to 50 kHz) during bit detection. 53** to interrupt at a high rate (up to 50 kHz) during bit detection.
54**  54**
55** 55**
56** The driver is dived into the standard top half ioctl, and bottom 56** The driver is dived into the standard top half ioctl, and bottom
57** half interrupt. The interrupt is FIQ, which requires its own stack.  57** half interrupt. The interrupt is FIQ, which requires its own stack.
58** disable_interrupts and restore_interrupts must be used to protect from 58** disable_interrupts and restore_interrupts must be used to protect from
59** a FIQ. Since splxxx functions do not use this, the bottom half cannot 59** a FIQ. Since splxxx functions do not use this, the bottom half cannot
60** use any standard functions (ie like wakeup, timeout, etc.  60** use any standard functions (ie like wakeup, timeout, etc.
61** Thus the communication from the bottom half 61** Thus the communication from the bottom half
62** to the top half uses a "done" bit called masterDone. This bit 62** to the top half uses a "done" bit called masterDone. This bit
63** is set by the master state machine when all bottom half work is  63** is set by the master state machine when all bottom half work is
64** complete. The top half checks/sleeps on this masterDone bit. 64** complete. The top half checks/sleeps on this masterDone bit.
65** 65**
66** The FIQ is driven by Timer 2 (T2)in the sequoia. All times are 66** The FIQ is driven by Timer 2 (T2)in the sequoia. All times are
67** referenced to T2 counts. 67** referenced to T2 counts.
68** 68**
69** The bottom half is done as a several linked state machines.  69** The bottom half is done as a several linked state machines.
70** The top level machine is the maserSM (ie master State Machine). This  70** The top level machine is the maserSM (ie master State Machine). This
71** machine calls mid level protocol machines, ie ATRSM (Answer To Reset  71** machine calls mid level protocol machines, ie ATRSM (Answer To Reset
72** State Machine), t0SendSM (T=0 Send State Machine), and t0RecvSM (T=0 Recv  72** State Machine), t0SendSM (T=0 Send State Machine), and t0RecvSM (T=0 Recv
73** State Machine). These mid level protocol machines in turn call low level 73** State Machine). These mid level protocol machines in turn call low level
74** bit-bashing machines, ie coldResetSM, t0SendByteSM, T0RecvByteSM. 74** bit-bashing machines, ie coldResetSM, t0SendByteSM, T0RecvByteSM.
75** 75**
76** Smart Cards are driven in a command/response mode. Ie you issue a command 76** Smart Cards are driven in a command/response mode. Ie you issue a command
77** to the Smart Card and it responds. This command/response mode is reflected 77** to the Smart Card and it responds. This command/response mode is reflected
78** in the structure of the driver. Ie the ioctl gets a command, it  78** in the structure of the driver. Ie the ioctl gets a command, it
79** gives it to the bottom half to execute and goes to sleep. The bottom half 79** gives it to the bottom half to execute and goes to sleep. The bottom half
80** executes the command and gets the response to from the card and then 80** executes the command and gets the response to from the card and then
81** notifies the top half that it has completed. Commands usually complete 81** notifies the top half that it has completed. Commands usually complete
82** in under a second.  82** in under a second.
83** 83**
84**  84**
85** 85**
86** AUTHORS: 86** AUTHORS:
87** 87**
88** E. J. Grohn 88** E. J. Grohn
89** Digital Equipment Corporation. 89** Digital Equipment Corporation.
90** 90**
91** CREATION DATE: 91** CREATION DATE:
92** 92**
93** 27-July-97 93** 27-July-97
94** 94**
95**-- 95**--
96*/ 96*/
97 97
98/* 98/*
99** 99**
100** INCLUDE FILES 100** INCLUDE FILES
101** 101**
102*/ 102*/
103 103
104#include <sys/cdefs.h> 104#include <sys/cdefs.h>
105__KERNEL_RCSID(0, "$NetBSD: scr.c,v 1.26 2011/07/26 08:56:26 mrg Exp $"); 105__KERNEL_RCSID(0, "$NetBSD: scr.c,v 1.27 2012/01/31 04:28:50 matt Exp $");
106 106
107#include "opt_ddb.h" 107#include "opt_ddb.h"
108 108
109#include <sys/param.h> 109#include <sys/param.h>
110#include <sys/systm.h> 110#include <sys/systm.h>
111#include <sys/ioctl.h> 111#include <sys/ioctl.h>
112/* #include <sys/select.h> */ 112/* #include <sys/select.h> */
113/* #include <sys/tty.h> */ 113/* #include <sys/tty.h> */
114#include <sys/proc.h> 114#include <sys/proc.h>
115#include <sys/conf.h> 115#include <sys/conf.h>
116/* #include <sys/file.h> */ 116/* #include <sys/file.h> */
117/* #include <sys/uio.h> */ 117/* #include <sys/uio.h> */
118#include <sys/kernel.h> 118#include <sys/kernel.h>
119/* #include <sys/syslog.h> */ 119/* #include <sys/syslog.h> */
120#include <sys/types.h> 120#include <sys/types.h>
121#include <sys/device.h> 121#include <sys/device.h>
122#include <dev/isa/isavar.h> 122#include <dev/isa/isavar.h>
123#include <arm/cpufunc.h> 123#include <arm/cpufunc.h>
124 124
125 125
126/* SCR_DEBUG is the master switch for turning on debugging */  126/* SCR_DEBUG is the master switch for turning on debugging */
127//#define SCR_DEBUG 1  127//#define SCR_DEBUG 1
128#ifdef SCR_DEBUG 128#ifdef SCR_DEBUG
129 #define KERNEL_DEBUG  129 #define KERNEL_DEBUG
130 #ifdef DDB 130 #ifdef DDB
131 #define DEBUGGER printf("file = %s, line = %d\n",__FILE__,__LINE__);Debugger()  131 #define DEBUGGER printf("file = %s, line = %d\n",__FILE__,__LINE__);Debugger()
132 #else 132 #else
133 #define DEBUGGER panic("file = %s, line = %d",__FILE__,__LINE__); 133 #define DEBUGGER panic("file = %s, line = %d",__FILE__,__LINE__);
134 #endif 134 #endif
135#else 135#else
136 #define DEBUGGER 136 #define DEBUGGER
137#endif 137#endif
138 138
139 139
140#include <machine/kerndebug.h> 140#include <machine/kerndebug.h>
141//#include <machine/intr.h> 141//#include <machine/intr.h>
142#include <dev/ic/i8253reg.h> 142#include <dev/ic/i8253reg.h>
143#include <shark/shark/hat.h> 143#include <shark/shark/hat.h>
144#include <shark/shark/sequoia.h> 144#include <shark/shark/sequoia.h>
145#include <machine/scrio.h> 145#include <machine/scrio.h>
146  146
147 147
148 148
149 149
150/* 150/*
151** 151**
152** MACRO DEFINITIONS 152** MACRO DEFINITIONS
153** 153**
154*/ 154*/
155 155
156 156
157#define scr_lcr scr_cfcr 157#define scr_lcr scr_cfcr
158 158
159/*  159/*
160** Macro to extract the minor device number from the device Identifier  160** Macro to extract the minor device number from the device Identifier
161*/ 161*/
162#define SCRUNIT(x) (minor(x)) 162#define SCRUNIT(x) (minor(x))
163 163
164/* 164/*
165** some macros to assist in debugging 165** some macros to assist in debugging
166*/ 166*/
167#ifdef SCR_DEBUG 167#ifdef SCR_DEBUG
168 #define KERNEL_DEBUG 168 #define KERNEL_DEBUG
169 #define ASSERT(f) do { if (!(f)) { DEBUGGER;} }while(0) 169 #define ASSERT(f) do { if (!(f)) { DEBUGGER;} }while(0)
170 #define TOGGLE_TEST_PIN() scrToggleTestPin() 170 #define TOGGLE_TEST_PIN() scrToggleTestPin()
171 #define INVALID_STATE_CMD(sc,state,cmd) invalidStateCmd(sc,state,cmd,__LINE__);  171 #define INVALID_STATE_CMD(sc,state,cmd) invalidStateCmd(sc,state,cmd,__LINE__);
172#else 172#else
173 #define ASSERT(f) 173 #define ASSERT(f)
174 #define TOGGLE_TEST_PIN() 174 #define TOGGLE_TEST_PIN()
175 //#define INVALID_STATE_CMD(sc,state,cmd) panic("scr: invalid state/cmd, sc = %X, state = %X, cmd = %X, line = %d",sc,state,cmd,__LINE__); 175 //#define INVALID_STATE_CMD(sc,state,cmd) panic("scr: invalid state/cmd, sc = %X, state = %X, cmd = %X, line = %d",sc,state,cmd,__LINE__);
176 #define INVALID_STATE_CMD(sc,state,cmd) sc->bigTrouble = true; 176 #define INVALID_STATE_CMD(sc,state,cmd) sc->bigTrouble = true;
177 177
178#endif 178#endif
179 179
180 180
181/*  181/*
182** The first and last bytes of the debug control variables is reserved for 182** The first and last bytes of the debug control variables is reserved for
183** the standard KERN_DEBUG_xxx macros, so we can tailor the middle two bytes 183** the standard KERN_DEBUG_xxx macros, so we can tailor the middle two bytes
184*/ 184*/
185#define SCRPROBE_DEBUG_INFO 0x00000100 185#define SCRPROBE_DEBUG_INFO 0x00000100
186#define SCRATTACH_DEBUG_INFO 0x00000200 186#define SCRATTACH_DEBUG_INFO 0x00000200
187#define SCROPEN_DEBUG_INFO 0x00000400 187#define SCROPEN_DEBUG_INFO 0x00000400
188#define SCRCLOSE_DEBUG_INFO 0x00000800 188#define SCRCLOSE_DEBUG_INFO 0x00000800
189#define SCRREAD_DEBUG_INFO 0x00001000 189#define SCRREAD_DEBUG_INFO 0x00001000
190#define SCRWRITE_DEBUG_INFO 0x00002000 190#define SCRWRITE_DEBUG_INFO 0x00002000
191#define SCRIOCTL_DEBUG_INFO 0x00004000 191#define SCRIOCTL_DEBUG_INFO 0x00004000
192#define MASTER_SM_DEBUG_INFO 0x00008000 192#define MASTER_SM_DEBUG_INFO 0x00008000
193#define COLD_RESET_SM_DEBUG_INFO 0x00010000 193#define COLD_RESET_SM_DEBUG_INFO 0x00010000
194#define ATR_SM_DEBUG_INFO 0x00020000 194#define ATR_SM_DEBUG_INFO 0x00020000
195#define T0_RECV_BYTE_SM_DEBUG_INFO 0x00040000  195#define T0_RECV_BYTE_SM_DEBUG_INFO 0x00040000
196#define T0_SEND_BYTE_SM_DEBUG_INFO 0x00080000  196#define T0_SEND_BYTE_SM_DEBUG_INFO 0x00080000
197#define T0_RECV_SM_DEBUG_INFO 0x00100000  197#define T0_RECV_SM_DEBUG_INFO 0x00100000
198#define T0_SEND_SM_DEBUG_INFO 0x00200000  198#define T0_SEND_SM_DEBUG_INFO 0x00200000
199 199
200 200
201int scrdebug = //SCRPROBE_DEBUG_INFO | 201int scrdebug = //SCRPROBE_DEBUG_INFO |
202 //SCRATTACH_DEBUG_INFO | 202 //SCRATTACH_DEBUG_INFO |
203 //SCROPEN_DEBUG_INFO | 203 //SCROPEN_DEBUG_INFO |
204 //SCRCLOSE_DEBUG_INFO | 204 //SCRCLOSE_DEBUG_INFO |
205 //SCRREAD_DEBUG_INFO | 205 //SCRREAD_DEBUG_INFO |
206 //SCRWRITE_DEBUG_INFO | 206 //SCRWRITE_DEBUG_INFO |
207 //SCRIOCTL_DEBUG_INFO | 207 //SCRIOCTL_DEBUG_INFO |
208 //MASTER_SM_DEBUG_INFO | 208 //MASTER_SM_DEBUG_INFO |
209 //COLD_RESET_SM_DEBUG_INFO| 209 //COLD_RESET_SM_DEBUG_INFO|
210 //ATR_SM_DEBUG_INFO | 210 //ATR_SM_DEBUG_INFO |
211 //T0_RECV_BYTE_SM_DEBUG_INFO | 211 //T0_RECV_BYTE_SM_DEBUG_INFO |
212 //T0_SEND_BYTE_SM_DEBUG_INFO | 212 //T0_SEND_BYTE_SM_DEBUG_INFO |
213 //T0_RECV_SM_DEBUG_INFO | 213 //T0_RECV_SM_DEBUG_INFO |
214 //T0_SEND_SM_DEBUG_INFO | 214 //T0_SEND_SM_DEBUG_INFO |
215 0; 215 0;
216 216
217 217
218 218
219 219
220 220
221 221
222/* 222/*
223** the bottom half of the driver is done as several linked state machines 223** the bottom half of the driver is done as several linked state machines
224** below are all the states of the machines, and the commands that are  224** below are all the states of the machines, and the commands that are
225** sent to each machine 225** sent to each machine
226*/ 226*/
227 227
228/* commands to Master State Machine from ioctl */ 228/* commands to Master State Machine from ioctl */
229#define mcOn 0x0100 /* ioctl on */ 229#define mcOn 0x0100 /* ioctl on */
230#define mcT0DataSend 0x0102 /* ioctl send */ 230#define mcT0DataSend 0x0102 /* ioctl send */
231#define mcT0DataRecv 0x0103 /* ioctl recv */ 231#define mcT0DataRecv 0x0103 /* ioctl recv */
232 232
233/* commands to Master State Machine from lower state machines */ 233/* commands to Master State Machine from lower state machines */
234#define mcColdReset 0x0105 /* cold reset finished */ 234#define mcColdReset 0x0105 /* cold reset finished */
235#define mcATR 0x0106 /* ATR has finished */ 235#define mcATR 0x0106 /* ATR has finished */
236#define mcT0Send 0x0108 /* T0 send finished */ 236#define mcT0Send 0x0108 /* T0 send finished */
237#define mcT0Recv 0x010a /* T0 recv finished */ 237#define mcT0Recv 0x010a /* T0 recv finished */
238 238
239/* states in Master state machine (ms = Master State) */ 239/* states in Master state machine (ms = Master State) */
240#define msIdleOff 0x0200 /* in idle state, card powered off */  240#define msIdleOff 0x0200 /* in idle state, card powered off */
241#define msColdReset 0x0201 /* turning on power, clock, reset */ 241#define msColdReset 0x0201 /* turning on power, clock, reset */
242#define msATR 0x0202 /* getting ATR sequence from card */ 242#define msATR 0x0202 /* getting ATR sequence from card */
243#define msIdleOn 0x0203 /* idle, put card powered on */ 243#define msIdleOn 0x0203 /* idle, put card powered on */
244#define msT0Send 0x0204 /* sending T0 data */ 244#define msT0Send 0x0204 /* sending T0 data */
245#define msT0Recv 0x0205 /* recving T0 data */ 245#define msT0Recv 0x0205 /* recving T0 data */
246 246
247 247
248 248
249 249
250/* commands to T0 send state machine */ 250/* commands to T0 send state machine */
251#define t0scStart 0x0300 /* start */ 251#define t0scStart 0x0300 /* start */
252#define t0scTWorkWaiting 0x0301 /* work waiting timeout */ 252#define t0scTWorkWaiting 0x0301 /* work waiting timeout */
253 253
254/* states in T0 send state machine */ 254/* states in T0 send state machine */
255#define t0ssIdle 0x0400 /* idle state */ 255#define t0ssIdle 0x0400 /* idle state */
256#define t0ssSendHeader 0x0401 /* send 5 header bytes */ 256#define t0ssSendHeader 0x0401 /* send 5 header bytes */
257#define t0ssRecvProcedure 0x0402 /* wait for procedure byte */ 257#define t0ssRecvProcedure 0x0402 /* wait for procedure byte */
258#define t0ssSendByte 0x0403 /* send 1 byte */ 258#define t0ssSendByte 0x0403 /* send 1 byte */
259#define t0ssSendData 0x0404 /* send all bytes */ 259#define t0ssSendData 0x0404 /* send all bytes */
260#define t0ssRecvSW1 0x0405 /* wait for sw1 */ 260#define t0ssRecvSW1 0x0405 /* wait for sw1 */
261#define t0ssRecvSW2 0x0406 /* wait for sw2 */ 261#define t0ssRecvSW2 0x0406 /* wait for sw2 */
262 262
263 263
264 264
265 265
266 266
267/* commands to T0 recv state machine */  267/* commands to T0 recv state machine */
268#define t0rcStart 0x0500 /* start */ 268#define t0rcStart 0x0500 /* start */
269#define t0rcTWorkWaiting 0x0501 /* work waiting timeout */ 269#define t0rcTWorkWaiting 0x0501 /* work waiting timeout */
270 270
271/* states in T0 recv state machine */ 271/* states in T0 recv state machine */
272#define t0rsIdle 0x0600 /* idle state */ 272#define t0rsIdle 0x0600 /* idle state */
273#define t0rsSendHeader 0x0601 /* send 5 header bytes */ 273#define t0rsSendHeader 0x0601 /* send 5 header bytes */
274#define t0rsRecvProcedure 0x0602 /* wait for procedure byte */ 274#define t0rsRecvProcedure 0x0602 /* wait for procedure byte */
275#define t0rsRecvByte 0x0603 /* recv 1 byte */ 275#define t0rsRecvByte 0x0603 /* recv 1 byte */
276#define t0rsRecvData 0x0604 /* recv all bytes */ 276#define t0rsRecvData 0x0604 /* recv all bytes */
277#define t0rsRecvSW1 0x0605 /* wait for sw1 */ 277#define t0rsRecvSW1 0x0605 /* wait for sw1 */
278#define t0rsRecvSW2 0x0606 /* wait for sw2 */ 278#define t0rsRecvSW2 0x0606 /* wait for sw2 */
279 279
280 280
281 281
282/* commands to Cold Reset state machine */ 282/* commands to Cold Reset state machine */
283#define crcStart 0x0900 /* start */ 283#define crcStart 0x0900 /* start */
284#define crcT2 0x0902 /* timeout T2 ISO 7816-3, P6, Figure 2 */ 284#define crcT2 0x0902 /* timeout T2 ISO 7816-3, P6, Figure 2 */
285 285
286/* states in cold reset state machine */ 286/* states in cold reset state machine */
287#define crsIdle 0x0a00 /* idle */ 287#define crsIdle 0x0a00 /* idle */
288#define crsT2Wait 0x0a01 /* wait for T2 ISO 7816-3.P6. Figure 2 */ 288#define crsT2Wait 0x0a01 /* wait for T2 ISO 7816-3.P6. Figure 2 */
289 289
290 290
291 291
292 292
293 293
294/* commands to Answer To Reset (ATR) state machine */ 294/* commands to Answer To Reset (ATR) state machine */
295#define atrcStart 0x0b00 /* start */ 295#define atrcStart 0x0b00 /* start */
296#define atrcT3 0x0b04 /* got T3 timeout */ 296#define atrcT3 0x0b04 /* got T3 timeout */
297#define atrcTWorkWaiting 0x0b05 /* work waiting timeout */ 297#define atrcTWorkWaiting 0x0b05 /* work waiting timeout */
298 298
299/* states in Answer To Reset (ATR) state machine */ 299/* states in Answer To Reset (ATR) state machine */
300#define atrsIdle 0x0c00 /* idle */ 300#define atrsIdle 0x0c00 /* idle */
301#define atrsTS 0x0c01 /* looking for TS, (initial bytes) */ 301#define atrsTS 0x0c01 /* looking for TS, (initial bytes) */
302#define atrsT0 0x0c02 /* looking for T0, (format bytes) */ 302#define atrsT0 0x0c02 /* looking for T0, (format bytes) */
303#define atrsTABCD 0x0c03 /* looking for TAx (interface bytes)*/ 303#define atrsTABCD 0x0c03 /* looking for TAx (interface bytes)*/
304#define atrsTK 0x0c04 /* looking for TK (history bytes) */ 304#define atrsTK 0x0c04 /* looking for TK (history bytes) */
305#define atrsTCK 0x0c05 /* looking for TCK (check bytes */ 305#define atrsTCK 0x0c05 /* looking for TCK (check bytes */
306 306
307 307
308/* commands to T0 Recv Byte state machine */ 308/* commands to T0 Recv Byte state machine */
309#define t0rbcStart 0x0d00 /* start */ 309#define t0rbcStart 0x0d00 /* start */
310#define t0rbcAbort 0x0d01 /* abort */ 310#define t0rbcAbort 0x0d01 /* abort */
311#define t0rbcTFindStartEdge 0x0d02 /* start bit edge search */ 311#define t0rbcTFindStartEdge 0x0d02 /* start bit edge search */
312#define t0rbcTFindStartMid 0x0d03 /* start bit mid search */ 312#define t0rbcTFindStartMid 0x0d03 /* start bit mid search */
313#define t0rbcTClockData 0x0d04 /* data bit search */ 313#define t0rbcTClockData 0x0d04 /* data bit search */
314#define t0rbcTErrorStart 0x0d05 /* start to send error */ 314#define t0rbcTErrorStart 0x0d05 /* start to send error */
315#define t0rbcTErrorStop 0x0d06 /* stop sending error */  315#define t0rbcTErrorStop 0x0d06 /* stop sending error */
316 316
317/* states in T0 Recv Byte state machine */ 317/* states in T0 Recv Byte state machine */
318#define t0rbsIdle 0x0e00 /* idle */  318#define t0rbsIdle 0x0e00 /* idle */
319#define t0rbsFindStartEdge 0x0e01 /* looking for start bit */ 319#define t0rbsFindStartEdge 0x0e01 /* looking for start bit */
320#define t0rbsFindStartMid 0x0e02 /* looking for start bit */ 320#define t0rbsFindStartMid 0x0e02 /* looking for start bit */
321#define t0rbsClockData 0x0e03 /* looking for data bits */ 321#define t0rbsClockData 0x0e03 /* looking for data bits */
322#define t0rbsSendError 0x0e04 /* output error bit */ 322#define t0rbsSendError 0x0e04 /* output error bit */
323 323
324 324
325 325
326 326
327/* commands to T0 Send Byte state machine */ 327/* commands to T0 Send Byte state machine */
328#define t0sbcStart 0x0f00 /* start the machine */ 328#define t0sbcStart 0x0f00 /* start the machine */
329#define t0sbcAbort 0x0f01 /* abort the machine */ 329#define t0sbcAbort 0x0f01 /* abort the machine */
330#define t0sbcTGuardTime 0x0f02 /* guard time finished */ 330#define t0sbcTGuardTime 0x0f02 /* guard time finished */
331#define t0sbcTClockData 0x0f03 /* clock time finished */ 331#define t0sbcTClockData 0x0f03 /* clock time finished */
332#define t0sbcTError 0x0f04 /* start to send error */ 332#define t0sbcTError 0x0f04 /* start to send error */
333#define t0sbcTResend 0x0f05 /* if parity error, then wait unfill we can re-send */ 333#define t0sbcTResend 0x0f05 /* if parity error, then wait unfill we can re-send */
334 334
335 335
336 336
337/* states in T0 Send Byte state machine */ 337/* states in T0 Send Byte state machine */
338#define t0sbsIdle 0x1000 /* idle */ 338#define t0sbsIdle 0x1000 /* idle */
339#define t0sbsWaitGuardTime 0x1001 /* wait for guard time to finish */ 339#define t0sbsWaitGuardTime 0x1001 /* wait for guard time to finish */
340#define t0sbsClockData 0x1002 /* clocking out data & parity */ 340#define t0sbsClockData 0x1002 /* clocking out data & parity */
341#define t0sbsWaitError 0x1003 /* waiting for error indicator */ 341#define t0sbsWaitError 0x1003 /* waiting for error indicator */
342#define t0sbsWaitResend 0x1004 /* waiting to start re-send if error */ 342#define t0sbsWaitResend 0x1004 /* waiting to start re-send if error */
343 343
344 344
345 345
346 346
347/*  347/*
348** generic middle level state machine commands  348** generic middle level state machine commands
349** sent by T0 Send Byte & T0 recv Byte to T0 Send and T0 Recv 349** sent by T0 Send Byte & T0 recv Byte to T0 Send and T0 Recv
350*/ 350*/
351#define gcT0RecvByte 0x1100 /* receive finished */ 351#define gcT0RecvByte 0x1100 /* receive finished */
352#define gcT0RecvByteErr 0x1101 /* receive got error */  352#define gcT0RecvByteErr 0x1101 /* receive got error */
353#define gcT0SendByte 0x1102 /* send finished */ 353#define gcT0SendByte 0x1102 /* send finished */
354#define gcT0SendByteErr 0x1103 /* send got error */ 354#define gcT0SendByteErr 0x1103 /* send got error */
355 355
356 356
357 357
358 358
359 359
360 360
361/*  361/*
362** 362**
363** below are definitions associated with Smart Card 363** below are definitions associated with Smart Card
364** 364**
365*/  365*/
366 366
367 367
368/*  368/*
369** Frequency of clock sent to card 369** Frequency of clock sent to card
370** NCI's card is running at 1/2 freq, so in debug we can make 370** NCI's card is running at 1/2 freq, so in debug we can make
371** use of this to toggle more debug signals and still be within 371** use of this to toggle more debug signals and still be within
372** interrupt time budget  372** interrupt time budget
373*/ 373*/
374#ifdef SCR_DEBUG 374#ifdef SCR_DEBUG
375 #define CARD_FREQ_DEF (3579000/2) 375 #define CARD_FREQ_DEF (3579000/2)
376#else 376#else
377 #define CARD_FREQ_DEF (3579000)  377 #define CARD_FREQ_DEF (3579000)
378#endif 378#endif
379 379
380 380
381 381
382/* byte logic level and msb/lsb coding */ 382/* byte logic level and msb/lsb coding */
383#define CONVENTION_UNKNOWN 0 383#define CONVENTION_UNKNOWN 0
384#define CONVENTION_INVERSE 1 384#define CONVENTION_INVERSE 1
385#define CONVENTION_DIRECT 2  385#define CONVENTION_DIRECT 2
386#define CONVENIONT_INVERSE_ID 0x3f 386#define CONVENIONT_INVERSE_ID 0x3f
387#define CONVENTION_DIRECT_FIX 0x3b 387#define CONVENTION_DIRECT_FIX 0x3b
388#define CONVENTION_DIRECT_ID 0x23 388#define CONVENTION_DIRECT_ID 0x23
389 389
390 390
391/* macros that help us set the T2 count for bit bashing */ 391/* macros that help us set the T2 count for bit bashing */
392#define CLK_COUNT_START (((372 * TIMER_FREQ) / sc->cardFreq) /5) 392#define CLK_COUNT_START (((372 * TIMER_FREQ) / sc->cardFreq) /5)
393#define CLK_COUNT_DATA (((372 * TIMER_FREQ) / sc->cardFreq) ) 393#define CLK_COUNT_DATA (((372 * TIMER_FREQ) / sc->cardFreq) )
394#define START_2_DATA 5 394#define START_2_DATA 5
395 395
396/* default settings to use if not specified in ATR */ 396/* default settings to use if not specified in ATR */
397#define N_DEFAULT 0 /* guard time default */ 397#define N_DEFAULT 0 /* guard time default */
398#define Fi_DEFAULT 372 /* clock rate conversion default */  398#define Fi_DEFAULT 372 /* clock rate conversion default */
399#define Di_DEFAULT 1 /* bit rate adjustment factor */ 399#define Di_DEFAULT 1 /* bit rate adjustment factor */
400#define Wi_DEFAULT 10 /* waiting time */ 400#define Wi_DEFAULT 10 /* waiting time */
401 401
402 402
403/* table for clock rate adjustment in ATR */ 403/* table for clock rate adjustment in ATR */
404int FI2Fi[16] = {372, 372, 558, 744,1116,1488,1860, 0, 404int FI2Fi[16] = {372, 372, 558, 744,1116,1488,1860, 0,
405 0, 512, 768,1024,1536,2048, 0, 0}; 405 0, 512, 768,1024,1536,2048, 0, 0};
406 406
407/* table for bit rate adjustment in ATR*/ 407/* table for bit rate adjustment in ATR*/
408int DI2Di[16] = { 0, 1, 2, 4, 8, 16, 32, 0, 408int DI2Di[16] = { 0, 1, 2, 4, 8, 16, 32, 0,
409 12, 20, 0, 0, 0, 0, 0, 0}; 409 12, 20, 0, 0, 0, 0, 0, 0};
410 410
411/* values of atrY in the ATR sequence*/ 411/* values of atrY in the ATR sequence*/
412#define ATR_Y_TA 0x10 412#define ATR_Y_TA 0x10
413#define ATR_Y_TB 0x20 413#define ATR_Y_TB 0x20
414#define ATR_Y_TC 0x40 414#define ATR_Y_TC 0x40
415#define ATR_Y_TD 0x80 415#define ATR_Y_TD 0x80
416 416
417/* T0,T1,etc information in ATR sequence*/ 417/* T0,T1,etc information in ATR sequence*/
418#define PROTOCOL_T0 0x0001 /* bit 0 for T0 */ 418#define PROTOCOL_T0 0x0001 /* bit 0 for T0 */
419#define PROTOCOL_T1 0x0002 /* bit 1 for T1 */ 419#define PROTOCOL_T1 0x0002 /* bit 1 for T1 */
420#define PROTOCOL_T2 0x0004 /* bit 2 for T2*/ 420#define PROTOCOL_T2 0x0004 /* bit 2 for T2*/
421#define PROTOCOL_T3 0x0008 /* bit 3 for T3*/ 421#define PROTOCOL_T3 0x0008 /* bit 3 for T3*/
422/* etc */ 422/* etc */
423 423
424 424
425/* timeouts for various places - see ISO 7816-3 */ 425/* timeouts for various places - see ISO 7816-3 */
426#define T_t2 ((300 * TIMER_FREQ) / sc->cardFreq)  426#define T_t2 ((300 * TIMER_FREQ) / sc->cardFreq)
427#define T_t3 ((40000 * (TIMER_FREQ/1024)) / (sc->cardFreq/1024))  427#define T_t3 ((40000 * (TIMER_FREQ/1024)) / (sc->cardFreq/1024))
428#define T_WORK_WAITING (((960 * sc->Wi * sc->Fi ) / (sc->cardFreq/1024)) * (TIMER_FREQ/1024)) 428#define T_WORK_WAITING (((960 * sc->Wi * sc->Fi ) / (sc->cardFreq/1024)) * (TIMER_FREQ/1024))
429#define PARITY_ERROR_MAX 3 /* maximum parity errors on 1 byte before giving up */ 429#define PARITY_ERROR_MAX 3 /* maximum parity errors on 1 byte before giving up */
430 430
431/*  431/*
432** its possible for the HAT to wedge. If that happens, all timing is sick, so  432** its possible for the HAT to wedge. If that happens, all timing is sick, so
433** we use timeout below (driven of system sleeps) as a "watchdog"  433** we use timeout below (driven of system sleeps) as a "watchdog"
434*/ 434*/
435#define MAX_FIQ_TIME 5 /* maximum time we are willing to run the FIQ */  435#define MAX_FIQ_TIME 5 /* maximum time we are willing to run the FIQ */
436 436
437 437
438/* used to decode T0 commands */ 438/* used to decode T0 commands */
439#define CMD_BUF_INS_OFF 1 /* offset to INS in header */ 439#define CMD_BUF_INS_OFF 1 /* offset to INS in header */
440#define CMD_BUF_DATA_LEN_OFF 4 /* offset to data length in header */ 440#define CMD_BUF_DATA_LEN_OFF 4 /* offset to data length in header */
441 441
442 442
443/* 443/*
444** 444**
445** DATA STRUCTURES 445** DATA STRUCTURES
446** 446**
447*/  447*/
448typedef unsigned char BYTE; 448typedef unsigned char BYTE;
449 449
450/* our soft c structure */ 450/* our soft c structure */
451struct scr_softc  451struct scr_softc
452{ 452{
453 int open; 453 int open;
454 454
455 /* configuration information */ 455 /* configuration information */
456 int status; /* status to be returned */ 456 int status; /* status to be returned */
457 int cardFreq; /* freq supplied to card */ 457 int cardFreq; /* freq supplied to card */
458 int convention; /* ie direct or inverse */ 458 int convention; /* ie direct or inverse */
459 int protocolType; /* bit 0 indicates T0, bit 1 indicates T1,etc */ 459 int protocolType; /* bit 0 indicates T0, bit 1 indicates T1,etc */
460 int N; /* guard time */ 460 int N; /* guard time */
461 int Fi; /* clock rate */ 461 int Fi; /* clock rate */
462 int Di; /* bit rate adjustment */ 462 int Di; /* bit rate adjustment */
463 int Wi; /* work waiting time */ 463 int Wi; /* work waiting time */
464 int clkCountStartRecv; /* count for clock start bits on recv */ 464 int clkCountStartRecv; /* count for clock start bits on recv */
465 int clkCountDataRecv; /* count for clock data bits on recv*/ 465 int clkCountDataRecv; /* count for clock data bits on recv*/
466 int clkCountDataSend; /* count for clock data bits on send */ 466 int clkCountDataSend; /* count for clock data bits on send */
467 467
468 /* state machines */ 468 /* state machines */
469 int masterS ; 469 int masterS ;
470 int t0RecvS; 470 int t0RecvS;
471 int t0SendS; 471 int t0SendS;
472 int coldResetS; 472 int coldResetS;
473 int ATRS; 473 int ATRS;
474 int t0RecvByteS; 474 int t0RecvByteS;
475 int t0SendByteS; 475 int t0SendByteS;
476 476
477 /* extra stuff kept for t0send state machine */ 477 /* extra stuff kept for t0send state machine */
478 int commandCount; /* number of command bytes sent */ 478 int commandCount; /* number of command bytes sent */
479 int dataCount; /* number of data bytes send/recv */ 479 int dataCount; /* number of data bytes send/recv */
480 int dataMax; /* max number of data bytes to send/recv */ 480 int dataMax; /* max number of data bytes to send/recv */
481 481
482 /* extra stuff kept for t0RecvByteS, t0SendByteS machines */ 482 /* extra stuff kept for t0RecvByteS, t0SendByteS machines */
483 void (*t0ByteParent)(struct scr_softc *,int); /* state machine that is controlling this SM */ 483 void (*t0ByteParent)(struct scr_softc *,int); /* state machine that is controlling this SM */
484 int shiftBits; /* number of bits shifted */ 484 int shiftBits; /* number of bits shifted */
485 BYTE shiftByte; /* intermediate value of bit being shifted */ 485 BYTE shiftByte; /* intermediate value of bit being shifted */
486 BYTE dataByte; /* actual value of byte */ 486 BYTE dataByte; /* actual value of byte */
487 int shiftParity; /* value of parity */ 487 int shiftParity; /* value of parity */
488 int shiftParityCount; /* number of retries due to parity error */ 488 int shiftParityCount; /* number of retries due to parity error */
489 489
490 /* extra stuff kept for ATR machine */ 490 /* extra stuff kept for ATR machine */
491 int atrY; /* indicates if TA,TB,TC,TD is to follow */ 491 int atrY; /* indicates if TA,TB,TC,TD is to follow */
492 int atrK; /* number of historical characters*/ 492 int atrK; /* number of historical characters*/
493 int atrKCount; /* progressive could of historical characters*/ 493 int atrKCount; /* progressive could of historical characters*/
494 int atrTABCDx; /* the 'i' in TA(i), TB(i), TC(i) and TD(i) */ 494 int atrTABCDx; /* the 'i' in TA(i), TB(i), TC(i) and TD(i) */
495 int atrFi; /* value of Fi */ 495 int atrFi; /* value of Fi */
496 int atrDi; /* value of Di */ 496 int atrDi; /* value of Di */
497 497
498 int masterDone; /* flag used by bottom half to tell top half its done */ 498 int masterDone; /* flag used by bottom half to tell top half its done */
499 int bigTrouble; /* david/jim, remove this when the dust settles */ 499 int bigTrouble; /* david/jim, remove this when the dust settles */
500 500
501 /* pointers used by ioctl */  501 /* pointers used by ioctl */
502 ScrOn * pIoctlOn; /* pointer to on ioctl data */ 502 ScrOn * pIoctlOn; /* pointer to on ioctl data */
503 ScrT0 * pIoctlT0; /* pointer to T0 ioctl data */ 503 ScrT0 * pIoctlT0; /* pointer to T0 ioctl data */
504}; 504};
505 505
506/* number of devices */ 506/* number of devices */
507static int devices = 0; 507static int devices = 0;
508 508
509/* used as reference for tsleep */ 509/* used as reference for tsleep */
510static int tsleepIdent;  510static int tsleepIdent;
511 511
512 512
513/*  513/*
514** only 1 device is using the hat at any one time 514** only 1 device is using the hat at any one time
515** variable below must be acquired using splhigh before using the hat 515** variable below must be acquired using splhigh before using the hat
516*/ 516*/
517static int hatLock = false;  517static int hatLock = false;
518 518
519 519
520 520
521 521
522/*  522/*
523** data structures associated with our timeout queue that we run for the  523** data structures associated with our timeout queue that we run for the
524** bottom half of the driver  524** bottom half of the driver
525*/ 525*/
526 526
527/* timeout callout structure */ 527/* timeout callout structure */
528typedef struct callout_t 528typedef struct callout_t
529{ 529{
530 struct callout_t *c_next; /* next callout in queue */ 530 struct callout_t *c_next; /* next callout in queue */
531 struct scr_softc *c_sc; /* soft c */ 531 struct scr_softc *c_sc; /* soft c */
532 int c_arg; /* function argument */ 532 int c_arg; /* function argument */
533 void (*c_func)(struct scr_softc*,int); /* function to call */ 533 void (*c_func)(struct scr_softc*,int); /* function to call */
534 int c_time; /* ticks to the event */ 534 int c_time; /* ticks to the event */
535}Callout; 535}Callout;
536 536
537/* actual callout array */ 537/* actual callout array */
538#define SCR_CLK_CALLOUT_COUNT 10  538#define SCR_CLK_CALLOUT_COUNT 10
539static Callout scrClkCalloutArray[SCR_CLK_CALLOUT_COUNT]; 539static Callout scrClkCalloutArray[SCR_CLK_CALLOUT_COUNT];
540 540
541/* callout lists */ 541/* callout lists */
542static Callout *scrClkCallFree; /* free queue */ 542static Callout *scrClkCallFree; /* free queue */
543static Callout scrClkCallTodo; /* todo queue */ 543static Callout scrClkCallTodo; /* todo queue */
544 544
545/*  545/*
546** information kept for the clock/FIQ that drives our timeout queue 546** information kept for the clock/FIQ that drives our timeout queue
547*/ 547*/
548static int scrClkEnable = 0; /* true if clock enabled */ 548static int scrClkEnable = 0; /* true if clock enabled */
549static void myHatWedge(int nFIQs); /* callback that informs us if FIQ has wedged */ 549static void myHatWedge(int nFIQs); /* callback that informs us if FIQ has wedged */
550static int scrClkCount; /* number used to set t2 that drives FIQ */ 550static int scrClkCount; /* number used to set t2 that drives FIQ */
551 551
552#define HATSTACKSIZE 1024 /* size of stack used during a FIQ */ 552#define HATSTACKSIZE 1024 /* size of stack used during a FIQ */
553static unsigned char hatStack[HATSTACKSIZE]; /* actual stack used during a FIQ */ 553static unsigned char hatStack[HATSTACKSIZE]; /* actual stack used during a FIQ */
554 554
555 555
556 556
557 557
558 558
559 559
560 560
561 561
562 562
563 563
564 564
565 565
566/* 566/*
567** 567**
568** FUNCTIONAL PROTOTYPES 568** FUNCTIONAL PROTOTYPES
569** 569**
570*/ 570*/
571 571
572/* 572/*
573** 573**
574** functions in top half of driver  574** functions in top half of driver
575** 575**
576*/ 576*/
577 577
578/* configure routines */ 578/* configure routines */
579int scrprobe(device_t, cfdata_t, void *); 579int scrprobe(device_t, cfdata_t, void *);
580void scrattach(device_t, device_t, void *); 580void scrattach(device_t, device_t, void *);
581 581
582static void initStates(struct scr_softc * sc);  582static void initStates(struct scr_softc * sc);
583 583
584 584
585 585
586 586
587/* 587/*
588** 588**
589** functions in bottom half of driver 589** functions in bottom half of driver
590** 590**
591*/ 591*/
592 592
593/* top level state machine */ 593/* top level state machine */
594static void masterSM(struct scr_softc * sc,int cmd); 594static void masterSM(struct scr_softc * sc,int cmd);
595 595
596/* mid level state machines, ie protocols */ 596/* mid level state machines, ie protocols */
597static void t0SendSM(struct scr_softc * sc,int cnd); 597static void t0SendSM(struct scr_softc * sc,int cnd);
598static void t0RecvSM(struct scr_softc * sc,int cnd); 598static void t0RecvSM(struct scr_softc * sc,int cnd);
599static void ATRSM(struct scr_softc * sc,int cnd); 599static void ATRSM(struct scr_softc * sc,int cnd);
600 600
601/* low level state machines, ie bash hardware bits */ 601/* low level state machines, ie bash hardware bits */
602static void coldResetSM(struct scr_softc * sc,int cnd); 602static void coldResetSM(struct scr_softc * sc,int cnd);
603 603
604static void t0SendByteSM(struct scr_softc * sc,int cnd); 604static void t0SendByteSM(struct scr_softc * sc,int cnd);
605static void t0RecvByteSM(struct scr_softc * sc,int cnd); 605static void t0RecvByteSM(struct scr_softc * sc,int cnd);
606 606
607static void cardOff(struct scr_softc * sc);  607static void cardOff(struct scr_softc * sc);
608 608
609/*  609/*
610** functions used for our own timeout routines. 610** functions used for our own timeout routines.
611** we cannot use system ones as we are running at a spl level 611** we cannot use system ones as we are running at a spl level
612** that can interrupt the system timeout routines 612** that can interrupt the system timeout routines
613*/ 613*/
614static void scrClkInit(void); 614static void scrClkInit(void);
615static void scrClkStart(struct scr_softc* sc,int countPerTick); 615static void scrClkStart(struct scr_softc* sc,int countPerTick);
616static void scrClkAdj(int count); 616static void scrClkAdj(int count);
617static void scrClkStop(void); 617static void scrClkStop(void);
618static void hatClkIrq(int count);  618static void hatClkIrq(int count);
619 619
620static void scrTimeout(void (*func)(struct scr_softc*,int), struct scr_softc*, int arg, int count);  620static void scrTimeout(void (*func)(struct scr_softc*,int), struct scr_softc*, int arg, int count);
621static void scrUntimeout(void (*func)(struct scr_softc*,int), struct scr_softc*, int arg); 621static void scrUntimeout(void (*func)(struct scr_softc*,int), struct scr_softc*, int arg);
622 622
623 623
624/* debug functions */ 624/* debug functions */
625#ifdef SCR_DEBUG 625#ifdef SCR_DEBUG
626 static void invalidStateCmd(struct scr_softc* sc,int state,int cmd, int line); 626 static void invalidStateCmd(struct scr_softc* sc,int state,int cmd, int line);
627 static char * getText(int x); 627 static char * getText(int x);
628#endif 628#endif
629 629
630 630
631 631
632 632
633 633
634CFATTACH_DECL_NEW(scr, sizeof(struct scr_softc), 634CFATTACH_DECL_NEW(scr, sizeof(struct scr_softc),
635 scrprobe, scrattach, NULL, NULL); 635 scrprobe, scrattach, NULL, NULL);
636 636
637extern struct cfdriver scr_cd; 637extern struct cfdriver scr_cd;
638 638
639dev_type_open(scropen); 639dev_type_open(scropen);
640dev_type_close(scrclose); 640dev_type_close(scrclose);
641dev_type_ioctl(scrioctl); 641dev_type_ioctl(scrioctl);
642 642
643const struct cdevsw scr_cdevsw = { 643const struct cdevsw scr_cdevsw = {
644 scropen, scrclose, noread, nowrite, scrioctl, 644 scropen, scrclose, noread, nowrite, scrioctl,
645 nostop, notty, nopoll, nommap, nokqfilter, D_TTY 645 nostop, notty, nopoll, nommap, nokqfilter, D_TTY
646}; 646};
647 647
648/* 648/*
649**++ 649**++
650** FUNCTIONAL DESCRIPTION: 650** FUNCTIONAL DESCRIPTION:
651** 651**
652** scrProbe 652** scrProbe
653**  653**
654** This is the probe routine for the Smart Card. Because the  654** This is the probe routine for the Smart Card. Because the
655** Smart Card is hard wired, there is no probing to peform. The 655** Smart Card is hard wired, there is no probing to peform. The
656** function ensures that a succesfull problem occurs only once. 656** function ensures that a succesfull problem occurs only once.
657** 657**
658** FORMAL PARAMETERS: 658** FORMAL PARAMETERS:
659** 659**
660** parent - input : pointer to the parent device  660** parent - input : pointer to the parent device
661** match - not used 661** match - not used
662** aux - output : pointer to an isa_attach_args structure. 662** aux - output : pointer to an isa_attach_args structure.
663**  663**
664** IMPLICIT INPUTS: 664** IMPLICIT INPUTS:
665** 665**
666** none. 666** none.
667** 667**
668** IMPLICIT OUTPUTS: 668** IMPLICIT OUTPUTS:
669** 669**
670** none. 670** none.
671** 671**
672** FUNCTION VALUE: 672** FUNCTION VALUE:
673** 673**
674** 0 - Probe failed to find the requested device. 674** 0 - Probe failed to find the requested device.
675** 1 - Probe successfully talked to the device.  675** 1 - Probe successfully talked to the device.
676** 676**
677** SIDE EFFECTS: 677** SIDE EFFECTS:
678** 678**
679** none. 679** none.
680**-- 680**--
681*/ 681*/
682int 682int
683scrprobe(device_t parent, cfdata_t match, void *aux) 683scrprobe(device_t parent, cfdata_t match, void *aux)
684{ 684{
685 struct isa_attach_args *ia = aux; 685 struct isa_attach_args *ia = aux;
686 int rv = 0;  686 int rv = 0;
687 687
688 KERN_DEBUG (scrdebug, SCRPROBE_DEBUG_INFO,("scrprobe: called, name = %s\n", 688 KERN_DEBUG (scrdebug, SCRPROBE_DEBUG_INFO,("scrprobe: called, name = %s\n",
689 device_cfdata(parent)->cf_name)); 689 device_cfdata(parent)->cf_name));
690 690
691 if (device_is_a(parent, "ofisascr") && devices == 0) 691 if (device_is_a(parent, "ofisascr") && devices == 0)
692 { 692 {
693 /* set "devices" to ensure that we respond only once */ 693 /* set "devices" to ensure that we respond only once */
694 devices++;  694 devices++;
695 695
696 /* tell the caller that we are not using any resource */ 696 /* tell the caller that we are not using any resource */
697 ia->ia_nio = 0; 697 ia->ia_nio = 0;
698 ia->ia_niomem = 0; 698 ia->ia_niomem = 0;
699 ia->ia_nirq = 0; 699 ia->ia_nirq = 0;
700 ia->ia_ndrq = 0; 700 ia->ia_ndrq = 0;
701 rv = 1; 701 rv = 1;
702 702
703 703
704 KERN_DEBUG (scrdebug, SCRPROBE_DEBUG_INFO,("scrprobe: successful \n")); 704 KERN_DEBUG (scrdebug, SCRPROBE_DEBUG_INFO,("scrprobe: successful \n"));
705 705
706 }  706 }
707 707
708 708
709 return (rv); 709 return (rv);
710 710
711} /* End scrprobe() */ 711} /* End scrprobe() */
712 712
713 713
714/* 714/*
715**++ 715**++
716** FUNCTIONAL DESCRIPTION: 716** FUNCTIONAL DESCRIPTION:
717** 717**
718** scrattach 718** scrattach
719** 719**
720** Initialize the clock and state machines  720** Initialize the clock and state machines
721** 721**
722** FORMAL PARAMETERS: 722** FORMAL PARAMETERS:
723** 723**
724** parent - input : pointer to my parents device structure. 724** parent - input : pointer to my parents device structure.
725** self - output : pointer to my softc with device structure at front. 725** self - output : pointer to my softc with device structure at front.
726** aux - input : pointer to the isa_attach_args structure. 726** aux - input : pointer to the isa_attach_args structure.
727** 727**
728** IMPLICIT INPUTS: 728** IMPLICIT INPUTS:
729** 729**
730** nill 730** nill
731** 731**
732** IMPLICIT OUTPUTS: 732** IMPLICIT OUTPUTS:
733** 733**
734** scrconsinit - clock callout functions set 734** scrconsinit - clock callout functions set
735** state machines all at idle  735** state machines all at idle
736** 736**
737** FUNCTION VALUE: 737** FUNCTION VALUE:
738** 738**
739** none. 739** none.
740** 740**
741** SIDE EFFECTS: 741** SIDE EFFECTS:
742** 742**
743** none. 743** none.
744**-- 744**--
745*/ 745*/
746void 746void
747scrattach(device_t parent, device_t self, void *aux) 747scrattach(device_t parent, device_t self, void *aux)
748{ 748{
749 struct scr_softc *sc = (void *)self; 749 struct scr_softc *sc = (void *)self;
750 750
751 printf("\n"); 751 printf("\n");
752 if (device_is_a(parent, "ofisascr")) 752 if (device_is_a(parent, "ofisascr"))
753 { 753 {
754 KERN_DEBUG (scrdebug, SCRATTACH_DEBUG_INFO,("scrattach: called \n")); 754 KERN_DEBUG (scrdebug, SCRATTACH_DEBUG_INFO,("scrattach: called \n"));
755 755
756 /* set initial state machine values */ 756 /* set initial state machine values */
757 scrClkInit(); 757 scrClkInit();
758 initStates(sc); 758 initStates(sc);
759 sc->open = false; 759 sc->open = false;
760 }  760 }
761 761
762 else 762 else
763 { 763 {
764 panic("scrattach: not on an ISA bus, attach impossible"); 764 panic("scrattach: not on an ISA bus, attach impossible");
765 } /* End else we aren't on ISA and we can't handle it */ 765 } /* End else we aren't on ISA and we can't handle it */
766 766
767 767
768 return; 768 return;
769} /* End scrattach() */ 769} /* End scrattach() */
770 770
771 771
772/* 772/*
773**++ 773**++
774** FUNCTIONAL DESCRIPTION: 774** FUNCTIONAL DESCRIPTION:
775** 775**
776** initStates 776** initStates
777** 777**
778** sets the state of all machines to idle 778** sets the state of all machines to idle
779** 779**
780** FORMAL PARAMETERS: 780** FORMAL PARAMETERS:
781** 781**
782** sc - Pointer to the softc structure. 782** sc - Pointer to the softc structure.
783** 783**
784** IMPLICIT INPUTS: 784** IMPLICIT INPUTS:
785** 785**
786** nill 786** nill
787** 787**
788** IMPLICIT OUTPUTS: 788** IMPLICIT OUTPUTS:
789** 789**
790** nill 790** nill
791** 791**
792** FUNCTION VALUE: 792** FUNCTION VALUE:
793** 793**
794** nill 794** nill
795** 795**
796** SIDE EFFECTS: 796** SIDE EFFECTS:
797** 797**
798** nill 798** nill
799**-- 799**--
800*/ 800*/
801static void initStates(struct scr_softc * sc) 801static void initStates(struct scr_softc * sc)
802{ 802{
803 sc->masterS = msIdleOff;  803 sc->masterS = msIdleOff;
804 sc->t0RecvS = t0rsIdle;  804 sc->t0RecvS = t0rsIdle;
805 sc->t0SendS = t0ssIdle;  805 sc->t0SendS = t0ssIdle;
806 sc->coldResetS = crsIdle;  806 sc->coldResetS = crsIdle;
807 sc->ATRS = atrsIdle;  807 sc->ATRS = atrsIdle;
808 sc->t0RecvByteS = t0rbsIdle;  808 sc->t0RecvByteS = t0rbsIdle;
809 sc->t0SendByteS = t0sbsIdle;  809 sc->t0SendByteS = t0sbsIdle;
810} 810}
811 811
812 812
813 813
814/* 814/*
815**++ 815**++
816** FUNCTIONAL DESCRIPTION: 816** FUNCTIONAL DESCRIPTION:
817** 817**
818** scrOpen 818** scrOpen
819** 819**
820** Opens the driver. We only let the device be opened 820** Opens the driver. We only let the device be opened
821** once for security reasons 821** once for security reasons
822** 822**
823** FORMAL PARAMETERS: 823** FORMAL PARAMETERS:
824** 824**
825** dev - input : Device identifier consisting of major and minor numbers. 825** dev - input : Device identifier consisting of major and minor numbers.
826** flag - input : Indicates if this is a blocking I/O call. 826** flag - input : Indicates if this is a blocking I/O call.
827** mode - not used. 827** mode - not used.
828** l - input : Pointer to the lwp structure of the light weight process  828** l - input : Pointer to the lwp structure of the light weight process
829** performing the open.  829** performing the open.
830** 830**
831** IMPLICIT INPUTS: 831** IMPLICIT INPUTS:
832** 832**
833** none. 833** none.
834** 834**
835** IMPLICIT OUTPUTS: 835** IMPLICIT OUTPUTS:
836** 836**
837** none. 837** none.
838** 838**
839** FUNCTION VALUE: 839** FUNCTION VALUE:
840** 840**
841** ENXIO - invalid device specified for open. 841** ENXIO - invalid device specified for open.
842** EBUSY - The unit is already open 842** EBUSY - The unit is already open
843** 843**
844** SIDE EFFECTS: 844** SIDE EFFECTS:
845** 845**
846** none. 846** none.
847**-- 847**--
848*/ 848*/
849int scropen(dev_t dev, int flag, int mode, struct lwp *l) 849int scropen(dev_t dev, int flag, int mode, struct lwp *l)
850{ 850{
851 struct scr_softc *sc; 851 struct scr_softc *sc;
852 852
853 KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO, 853 KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,
854 ("scropen: called with minor device %d and flag 0x%x\n", 854 ("scropen: called with minor device %d and flag 0x%x\n",
855 SCRUNIT(dev), flag)); 855 SCRUNIT(dev), flag));
856 856
857 sc = device_lookup_private(&scr_cd, SCRUNIT(dev)); 857 sc = device_lookup_private(&scr_cd, SCRUNIT(dev));
858 if (!sc) 858 if (!sc)
859 { 859 {
860 KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,("\t scropen, return ENXIO\n")); 860 KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,("\t scropen, return ENXIO\n"));
861 return (ENXIO); 861 return (ENXIO);
862 } 862 }
863 863
864 864
865 // david,jim - remove ifdef this when NCI can cope with only 1 open 865 // david,jim - remove ifdef this when NCI can cope with only 1 open
866#if 0  866#if 0
867 if (sc->open) 867 if (sc->open)
868 { 868 {
869 869
870 KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,("\t scropen, return EBUSY\n")); 870 KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,("\t scropen, return EBUSY\n"));
871 return (EBUSY); 871 return (EBUSY);
872 } 872 }
873 873
874 874
875 /* set all initial conditions */ 875 /* set all initial conditions */
876 sc->open = true; 876 sc->open = true;
877#endif 877#endif
878 878
879 KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,("scropen: success \n")); 879 KERN_DEBUG (scrdebug, SCROPEN_DEBUG_INFO,("scropen: success \n"));
880 /* Now invoke the line discipline open routine  880 /* Now invoke the line discipline open routine
881 */ 881 */
882 882
883 return 0; 883 return 0;
884 884
885} /* End scropen() */ 885} /* End scropen() */
886 886
887 887
888/* 888/*
889**++ 889**++
890** FUNCTIONAL DESCRIPTION: 890** FUNCTIONAL DESCRIPTION:
891** 891**
892** This function closed the driver 892** This function closed the driver
893** 893**
894** FORMAL PARAMETERS: 894** FORMAL PARAMETERS:
895** 895**
896** dev - input : Device identifier consisting of major and minor numbers. 896** dev - input : Device identifier consisting of major and minor numbers.
897** flag - Not used. 897** flag - Not used.
898** mode - Not used. 898** mode - Not used.
899** p - Not used.  899** p - Not used.
900** 900**
901** IMPLICIT INPUTS: 901** IMPLICIT INPUTS:
902** 902**
903** scr_cd - used to locate the softc structure for the device unit 903** scr_cd - used to locate the softc structure for the device unit
904** identified by dev. 904** identified by dev.
905** 905**
906** IMPLICIT OUTPUTS: 906** IMPLICIT OUTPUTS:
907** 907**
908** The device is put into an idle state. 908** The device is put into an idle state.
909** 909**
910** FUNCTION VALUE: 910** FUNCTION VALUE:
911** 911**
912** 0 - Always returns success. 912** 0 - Always returns success.
913** 913**
914** SIDE EFFECTS: 914** SIDE EFFECTS:
915** 915**
916** none. 916** none.
917**-- 917**--
918*/ 918*/
919int scrclose(dev_t dev, int flag, int mode, struct lwp *l) 919int scrclose(dev_t dev, int flag, int mode, struct lwp *l)
920{ 920{
921#if 0 921#if 0
922 struct scr_softc *sc = device_lookup_private(&scr_cd, SCRUNIT(dev)); 922 struct scr_softc *sc = device_lookup_private(&scr_cd, SCRUNIT(dev));
923#endif 923#endif
924 924
925 KERN_DEBUG (scrdebug, SCRCLOSE_DEBUG_INFO, 925 KERN_DEBUG (scrdebug, SCRCLOSE_DEBUG_INFO,
926 ("scrclose: called for minor device %d flag 0x%x\n", 926 ("scrclose: called for minor device %d flag 0x%x\n",
927 SCRUNIT(dev), flag)); 927 SCRUNIT(dev), flag));
928 928
929 // david,jim - remove ifdef this when NCI can cope with only 1 open 929 // david,jim - remove ifdef this when NCI can cope with only 1 open
930#if 0  930#if 0
931 /* Check we are open in the first place 931 /* Check we are open in the first place
932 */ 932 */
933 if (sc->open) 933 if (sc->open)
934 { 934 {
935 /* put everything in the idle state */ 935 /* put everything in the idle state */
936 scrClkInit(); 936 scrClkInit();
937 initStates(sc); 937 initStates(sc);
938 sc->open = false; 938 sc->open = false;
939 939
940 }  940 }
941  941
942  942
943 else 943 else
944 { 944 {
945 KERN_DEBUG (scrdebug, SCRCLOSE_DEBUG_INFO,("\t scrclose, device not open\n")); 945 KERN_DEBUG (scrdebug, SCRCLOSE_DEBUG_INFO,("\t scrclose, device not open\n"));
946 } 946 }
947#endif 947#endif
948 948
949 KERN_DEBUG (scrdebug, SCRCLOSE_DEBUG_INFO,("scrclose exiting\n")); 949 KERN_DEBUG (scrdebug, SCRCLOSE_DEBUG_INFO,("scrclose exiting\n"));
950 return(0); 950 return(0);
951} 951}
952 952
953/* 953/*
954**++ 954**++
955** FUNCTIONAL DESCRIPTION: 955** FUNCTIONAL DESCRIPTION:
956** 956**
957** This routine is responsible for performing I/O controls. 957** This routine is responsible for performing I/O controls.
958** 958**
959** There are 4 commands. Status, On, T0 and Off.  959** There are 4 commands. Status, On, T0 and Off.
960** 960**
961** Status checks to see if the card is inserted. This command 961** Status checks to see if the card is inserted. This command
962** does not use the state machines 962** does not use the state machines
963** 963**
964** On turns the card on and gets the ATR sequence from the card.  964** On turns the card on and gets the ATR sequence from the card.
965** This command does use the state machines 965** This command does use the state machines
966** 966**
967** T0 is used to read and write the card. This command does use 967** T0 is used to read and write the card. This command does use
968** the state machines 968** the state machines
969**  969**
970** Off turns the card off. This command does not use the state 970** Off turns the card off. This command does not use the state
971** machines.  971** machines.
972** 972**
973**  973**
974** FORMAL PARAMETERS: 974** FORMAL PARAMETERS:
975** 975**
976** dev - input : Device identifier consisting of major and minor numbers. 976** dev - input : Device identifier consisting of major and minor numbers.
977** cmd - input : The requested IOCTL command to be performed.  977** cmd - input : The requested IOCTL command to be performed.
978** See scrio.h for details 978** See scrio.h for details
979** 979**
980** 980**
981** Bit Position { 3322222222221111111111 981** Bit Position { 3322222222221111111111
982** { 10987654321098765432109876543210  982** { 10987654321098765432109876543210
983** Meaning | DDDLLLLLLLLLLLLLGGGGGGGGCCCCCCCC 983** Meaning | DDDLLLLLLLLLLLLLGGGGGGGGCCCCCCCC
984** 984**
985** D - Command direction, in/out/both. 985** D - Command direction, in/out/both.
986** L - Command argument length. 986** L - Command argument length.
987** G - Command group, 't' used for tty. 987** G - Command group, 't' used for tty.
988** C - Actual command enumeration. 988** C - Actual command enumeration.
989**  989**
990** data - input/output : Direction depends on the command. 990** data - input/output : Direction depends on the command.
991** flag - input : Not used by us but passed to line discipline and ttioctl 991** flag - input : Not used by us but passed to line discipline and ttioctl
992** l - input : pointer to lwp structure of user. 992** l - input : pointer to lwp structure of user.
993**  993**
994** IMPLICIT INPUTS: 994** IMPLICIT INPUTS:
995** 995**
996** none. 996** none.
997** 997**
998** IMPLICIT OUTPUTS: 998** IMPLICIT OUTPUTS:
999** 999**
1000** sc->masterS state of master state machine  1000** sc->masterS state of master state machine
1001** 1001**
1002** 1002**
1003** FUNCTION VALUE: 1003** FUNCTION VALUE:
1004** 1004**
1005** ENOTTY if not correct ioctl 1005** ENOTTY if not correct ioctl
1006** 1006**
1007** 1007**
1008** SIDE EFFECTS: 1008** SIDE EFFECTS:
1009** 1009**
1010**-- 1010**--
1011*/ 1011*/
1012int 1012int
1013scrioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) 1013scrioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
1014{ 1014{
1015 struct scr_softc* sc = device_lookup_private(&scr_cd, SCRUNIT(dev)); 1015 struct scr_softc* sc = device_lookup_private(&scr_cd, SCRUNIT(dev));
1016  1016
1017 int error = 0; /* error value returned */ 1017 int error = 0; /* error value returned */
1018 int masterDoneRetries= 0; /* nuber of times we looked at masterDone */ 1018 int masterDoneRetries= 0; /* nuber of times we looked at masterDone */
1019 int done; /* local copy of masterDone */ 1019 int done; /* local copy of masterDone */
1020  1020
1021 ScrStatus * pIoctlStatus; /* pointer to status ioctl */ 1021 ScrStatus * pIoctlStatus; /* pointer to status ioctl */
1022 ScrOff * pIoctlOff; /* pointer to off ioctl */ 1022 ScrOff * pIoctlOff; /* pointer to off ioctl */
1023  1023
1024 u_int savedInts; /* saved interrupts */ 1024 u_int savedInts; /* saved interrupts */
1025 int s; /* saved spl value */ 1025 int s; /* saved spl value */
1026 1026
1027 1027
1028 1028
1029 KERN_DEBUG (scrdebug, SCRIOCTL_DEBUG_INFO, 1029 KERN_DEBUG (scrdebug, SCRIOCTL_DEBUG_INFO,
1030 ("scrioctl: called for device 0x%x, command 0x%lx, " 1030 ("scrioctl: called for device 0x%x, command 0x%lx, "
1031 "flag 0x%x\n", 1031 "flag 0x%x\n",
1032 SCRUNIT(dev), cmd, flag)); 1032 SCRUNIT(dev), cmd, flag));
1033 1033
1034 1034
1035 1035
1036 switch (cmd) 1036 switch (cmd)
1037 { 1037 {
1038 /*  1038 /*
1039 ** get the status of the card, ie is it in, in but off, in and on  1039 ** get the status of the card, ie is it in, in but off, in and on
1040 */ 1040 */
1041 case SCRIOSTATUS: 1041 case SCRIOSTATUS:
1042 pIoctlStatus = (ScrStatus*)data; 1042 pIoctlStatus = (ScrStatus*)data;
1043 if (scrGetDetect()) 1043 if (scrGetDetect())
1044 { 1044 {
1045 savedInts = disable_interrupts(I32_bit | F32_bit); 1045 savedInts = disable_interrupts(I32_bit | F32_bit);
1046 if (sc->masterS == msIdleOn) 1046 if (sc->masterS == msIdleOn)
1047 { 1047 {
1048 pIoctlStatus->status = CARD_ON;  1048 pIoctlStatus->status = CARD_ON;
1049 } 1049 }
1050 else 1050 else
1051 { 1051 {
1052 ASSERT(sc->masterS == msIdleOff); 1052 ASSERT(sc->masterS == msIdleOff);
1053 pIoctlStatus->status = CARD_INSERTED; 1053 pIoctlStatus->status = CARD_INSERTED;
1054 } 1054 }
1055 restore_interrupts(savedInts); 1055 restore_interrupts(savedInts);
1056 } 1056 }
1057 1057
1058 else 1058 else
1059 { 1059 {
1060 pIoctlStatus->status = CARD_REMOVED; 1060 pIoctlStatus->status = CARD_REMOVED;
1061 } 1061 }
1062 break; 1062 break;
1063 1063
1064 1064
1065 1065
1066 /*  1066 /*
1067 ** turn the card on and get the ATR sequence  1067 ** turn the card on and get the ATR sequence
1068 */ 1068 */
1069 case SCRIOON: 1069 case SCRIOON:
1070 sc->pIoctlOn = (ScrOn*)data; 1070 sc->pIoctlOn = (ScrOn*)data;
1071 // acquire the hat lock.  1071 // acquire the hat lock.
1072 while (1) 1072 while (1)
1073 { 1073 {
1074 s = splhigh(); 1074 s = splhigh();
1075 if(!hatLock) 1075 if(!hatLock)
1076 { 1076 {
1077 hatLock = true; 1077 hatLock = true;
1078 splx(s); 1078 splx(s);
1079 break; 1079 break;
1080 } 1080 }
1081 splx(s); 1081 splx(s);
1082  1082
1083 tsleep(&tsleepIdent ,PZERO,"hat", 1);  1083 tsleep(&tsleepIdent ,PZERO,"hat", 1);
1084 } 1084 }
1085  1085
1086  1086
1087 // check to see if the card is in 1087 // check to see if the card is in
1088 if(!scrGetDetect()) 1088 if(!scrGetDetect())
1089 { 1089 {
1090 initStates(sc); 1090 initStates(sc);
1091 cardOff(sc); 1091 cardOff(sc);
1092 // do not call scrClkInit() as it is idle already 1092 // do not call scrClkInit() as it is idle already
1093 sc->pIoctlOn->status = ERROR_CARD_REMOVED; 1093 sc->pIoctlOn->status = ERROR_CARD_REMOVED;
1094 } 1094 }
1095 1095
1096  1096
1097 // check to see if we are already on  1097 // check to see if we are already on
1098 else if(sc->masterS == msIdleOn) 1098 else if(sc->masterS == msIdleOn)
1099 { 1099 {
1100 sc->pIoctlOn->status = ERROR_CARD_ON; 1100 sc->pIoctlOn->status = ERROR_CARD_ON;
1101 } 1101 }
1102  1102
1103 // card was in, card is off, so lets start it  1103 // card was in, card is off, so lets start it
1104 else  1104 else
@@ -2694,1326 +2694,1328 @@ static void ATRSM (struct scr_softc * sc @@ -2694,1326 +2694,1328 @@ static void ATRSM (struct scr_softc * sc
2694 default: 2694 default:
2695 INVALID_STATE_CMD(sc,sc->ATRS,cmd); 2695 INVALID_STATE_CMD(sc,sc->ATRS,cmd);
2696 break; 2696 break;
2697 } 2697 }
2698 break; 2698 break;
2699 2699
2700 2700
2701 2701
2702 default: 2702 default:
2703 INVALID_STATE_CMD(sc,sc->ATRS,cmd); 2703 INVALID_STATE_CMD(sc,sc->ATRS,cmd);
2704 break; 2704 break;
2705 } 2705 }
2706} 2706}
2707 2707
2708 2708
2709 2709
2710/* 2710/*
2711**++ 2711**++
2712** FUNCTIONAL DESCRIPTION: 2712** FUNCTIONAL DESCRIPTION:
2713** 2713**
2714** t0RecvByteSM 2714** t0RecvByteSM
2715** 2715**
2716** This state machine attempts to read 1 byte from a card. 2716** This state machine attempts to read 1 byte from a card.
2717** It is a low level bit-bashing state machine. 2717** It is a low level bit-bashing state machine.
2718** 2718**
2719** Data from the card is async, so the machine scans at  2719** Data from the card is async, so the machine scans at
2720** 5 times the data rate looking for a state bit. Once  2720** 5 times the data rate looking for a state bit. Once
2721** a start bit has been found, it waits for the middle of  2721** a start bit has been found, it waits for the middle of
2722** the bit and starts sampling at the bit rate. 2722** the bit and starts sampling at the bit rate.
2723** 2723**
2724** Several mid level machines can use this machine, so the value 2724** Several mid level machines can use this machine, so the value
2725** sc->t0ByteParent is used to point to back to the mid level machine 2725** sc->t0ByteParent is used to point to back to the mid level machine
2726**  2726**
2727** 2727**
2728** FORMAL PARAMETERS: 2728** FORMAL PARAMETERS:
2729** 2729**
2730** sc - Pointer to the softc structure. 2730** sc - Pointer to the softc structure.
2731** cmd - command to this machine  2731** cmd - command to this machine
2732** 2732**
2733** IMPLICIT INPUTS: 2733** IMPLICIT INPUTS:
2734** 2734**
2735** sc->t0RecvByteS state of this machine  2735** sc->t0RecvByteS state of this machine
2736** sc->t0ByteParent mid level machine that started this machine 2736** sc->t0ByteParent mid level machine that started this machine
2737** 2737**
2738** IMPLICIT OUTPUTS: 2738** IMPLICIT OUTPUTS:
2739** 2739**
2740** sc->shiftByte byte read from the card  2740** sc->shiftByte byte read from the card
2741** sc->status error value if could not read byte 2741** sc->status error value if could not read byte
2742** 2742**
2743** FUNCTION VALUE: 2743** FUNCTION VALUE:
2744** 2744**
2745** nill 2745** nill
2746** 2746**
2747** SIDE EFFECTS: 2747** SIDE EFFECTS:
2748** 2748**
2749** nill 2749** nill
2750**-- 2750**--
2751*/ 2751*/
2752static void t0RecvByteSM(struct scr_softc* sc,int cmd) 2752static void t0RecvByteSM(struct scr_softc* sc,int cmd)
2753{ 2753{
2754 if (sc->bigTrouble) return; // david,jim , remove this when dust settles  2754 if (sc->bigTrouble) return; // david,jim , remove this when dust settles
2755 2755
2756 if (cmd == t0rbcAbort) 2756 if (cmd == t0rbcAbort)
2757 { 2757 {
2758 /* kill all the timers */ 2758 /* kill all the timers */
2759 scrUntimeout(t0RecvByteSM, sc,t0rbcTFindStartEdge); 2759 scrUntimeout(t0RecvByteSM, sc,t0rbcTFindStartEdge);
2760 scrUntimeout(t0RecvByteSM, sc,t0rbcTFindStartMid); 2760 scrUntimeout(t0RecvByteSM, sc,t0rbcTFindStartMid);
2761 scrUntimeout(t0RecvByteSM, sc,t0rbcTClockData); 2761 scrUntimeout(t0RecvByteSM, sc,t0rbcTClockData);
2762 scrUntimeout(t0RecvByteSM, sc,t0rbcTErrorStart); 2762 scrUntimeout(t0RecvByteSM, sc,t0rbcTErrorStart);
2763 scrUntimeout(t0RecvByteSM, sc,t0rbcTErrorStop); 2763 scrUntimeout(t0RecvByteSM, sc,t0rbcTErrorStop);
2764 2764
2765 scrSetDataHighZ(); 2765 scrSetDataHighZ();
2766 sc->t0RecvByteS = t0rbsIdle;  2766 sc->t0RecvByteS = t0rbsIdle;
2767 return; 2767 return;
2768 } 2768 }
2769 2769
2770 2770
2771 switch (sc->t0RecvByteS) 2771 switch (sc->t0RecvByteS)
2772 { 2772 {
2773 case t0rbsIdle: 2773 case t0rbsIdle:
2774 switch (cmd) 2774 switch (cmd)
2775 { 2775 {
2776 case t0rbcStart: 2776 case t0rbcStart:
2777 /* set initial conditions */ 2777 /* set initial conditions */
2778 sc->shiftBits = 0; 2778 sc->shiftBits = 0;
2779 sc->shiftByte = 0; 2779 sc->shiftByte = 0;
2780 sc->shiftParity = 0; 2780 sc->shiftParity = 0;
2781 sc->shiftParityCount = 0;  2781 sc->shiftParityCount = 0;
2782 scrClkAdj(sc->clkCountStartRecv); /* recv data clock running at 5 times */ 2782 scrClkAdj(sc->clkCountStartRecv); /* recv data clock running at 5 times */
2783 2783
2784 /* check if start bit is already here */ 2784 /* check if start bit is already here */
2785 //if (scrGetData()) 2785 //if (scrGetData())
2786 if (1) 2786 if (1)
2787 { 2787 {
2788 /* didn't find it, keep looking */ 2788 /* didn't find it, keep looking */
2789 scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,sc->clkCountStartRecv); 2789 scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,sc->clkCountStartRecv);
2790 sc->t0RecvByteS = t0rbsFindStartEdge; 2790 sc->t0RecvByteS = t0rbsFindStartEdge;
2791 } 2791 }
2792 else 2792 else
2793 { 2793 {
2794 /* found start bit, look for mid bit */ 2794 /* found start bit, look for mid bit */
2795 scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartMid,sc->clkCountStartRecv); 2795 scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartMid,sc->clkCountStartRecv);
2796 sc->t0RecvByteS = t0rbsFindStartMid; 2796 sc->t0RecvByteS = t0rbsFindStartMid;
2797 } 2797 }
2798 break; 2798 break;
2799 2799
2800 2800
2801 2801
2802 default: 2802 default:
2803 INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); 2803 INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd);
2804 break; 2804 break;
2805 } 2805 }
2806 break; 2806 break;
2807 2807
2808 2808
2809 case t0rbsFindStartEdge: 2809 case t0rbsFindStartEdge:
2810 switch (cmd) 2810 switch (cmd)
2811 { 2811 {
2812 case t0rbcTFindStartEdge: 2812 case t0rbcTFindStartEdge:
2813 if (scrGetData()) 2813 if (scrGetData())
2814 { 2814 {
2815 /* didn't find it, keep looking */ 2815 /* didn't find it, keep looking */
2816 scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,sc->clkCountStartRecv); 2816 scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,sc->clkCountStartRecv);
2817 } 2817 }
2818 else 2818 else
2819 { 2819 {
2820 /* found start bit, look for mid bit */ 2820 /* found start bit, look for mid bit */
2821 scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartMid,sc->clkCountStartRecv * 2);  2821 scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartMid,sc->clkCountStartRecv * 2);
2822 sc->t0RecvByteS = t0rbsFindStartMid; 2822 sc->t0RecvByteS = t0rbsFindStartMid;
2823 } 2823 }
2824 break; 2824 break;
2825 2825
2826 2826
2827 default: 2827 default:
2828 INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); 2828 INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd);
2829 break; 2829 break;
2830 } 2830 }
2831 break; 2831 break;
2832 2832
2833 case t0rbsFindStartMid: 2833 case t0rbsFindStartMid:
2834 switch (cmd) 2834 switch (cmd)
2835 { 2835 {
2836 case t0rbcTFindStartMid: 2836 case t0rbcTFindStartMid:
2837 if (scrGetData()) 2837 if (scrGetData())
2838 { 2838 {
2839 /* found glitch, so just go back to hunting */ 2839 /* found glitch, so just go back to hunting */
2840 scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,sc->clkCountStartRecv); 2840 scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,sc->clkCountStartRecv);
2841 sc->t0RecvByteS = t0rbsFindStartEdge; 2841 sc->t0RecvByteS = t0rbsFindStartEdge;
2842 } 2842 }
2843 else 2843 else
2844 { 2844 {
2845 /* found start bit, start clocking in data */ 2845 /* found start bit, start clocking in data */
2846 TOGGLE_TEST_PIN(); 2846 TOGGLE_TEST_PIN();
2847 scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,sc->clkCountDataRecv); 2847 scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,sc->clkCountDataRecv);
2848 sc->t0RecvByteS = t0rbsClockData; 2848 sc->t0RecvByteS = t0rbsClockData;
2849 } 2849 }
2850 break; 2850 break;
2851 2851
2852 2852
2853 default: 2853 default:
2854 INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); 2854 INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd);
2855 break; 2855 break;
2856 } 2856 }
2857 break; 2857 break;
2858 2858
2859 2859
2860 case t0rbsClockData:  2860 case t0rbsClockData:
2861 TOGGLE_TEST_PIN(); 2861 TOGGLE_TEST_PIN();
2862 switch (cmd) 2862 switch (cmd)
2863 { 2863 {
2864 case t0rbcTClockData: 2864 case t0rbcTClockData:
2865 if (sc->shiftBits < 8) 2865 if (sc->shiftBits < 8)
2866 { 2866 {
2867 if (sc->convention == CONVENTION_INVERSE ||  2867 if (sc->convention == CONVENTION_INVERSE ||
2868 sc->convention == CONVENTION_UNKNOWN) 2868 sc->convention == CONVENTION_UNKNOWN)
2869 { 2869 {
2870 /* logic 1 is low, msb is first */ 2870 /* logic 1 is low, msb is first */
2871 sc->shiftByte <<= 1; 2871 sc->shiftByte <<= 1;
2872 sc->shiftByte &= 0xfe; 2872 sc->shiftByte &= 0xfe;
2873 if (!scrGetData()) 2873 if (!scrGetData())
2874 { 2874 {
2875 sc->shiftByte |= 0x01; 2875 sc->shiftByte |= 0x01;
2876 sc->shiftParity++; 2876 sc->shiftParity++;
2877 } 2877 }
2878 } 2878 }
2879 else 2879 else
2880 { 2880 {
2881 ASSERT(sc->convention == CONVENTION_DIRECT); 2881 ASSERT(sc->convention == CONVENTION_DIRECT);
2882 /* logic 1 is high, lsb is first */ 2882 /* logic 1 is high, lsb is first */
2883 sc->shiftByte = sc->shiftByte >> 1; 2883 sc->shiftByte = sc->shiftByte >> 1;
2884 sc->shiftByte &= 0x7f; 2884 sc->shiftByte &= 0x7f;
2885 if (scrGetData()) 2885 if (scrGetData())
2886 { 2886 {
2887 sc->shiftParity++; 2887 sc->shiftParity++;
2888 sc->shiftByte |= 0x80; 2888 sc->shiftByte |= 0x80;
2889 } 2889 }
2890 } 2890 }
2891 sc->shiftBits++; 2891 sc->shiftBits++;
2892 2892
2893 2893
2894 /* in TS byte, check if we have a card that works at 1/2 freq */ 2894 /* in TS byte, check if we have a card that works at 1/2 freq */
2895 if (sc->convention == CONVENTION_UNKNOWN && /* in TS byte */ 2895 if (sc->convention == CONVENTION_UNKNOWN && /* in TS byte */
2896 sc->shiftBits == 3 && /* test at bit 3 in word */ 2896 sc->shiftBits == 3 && /* test at bit 3 in word */
2897 sc->shiftByte == 4 && /* check for 1/2 freq pattern */ 2897 sc->shiftByte == 4 && /* check for 1/2 freq pattern */
2898 sc->cardFreq == CARD_FREQ_DEF) /* only do this if at full freq */ 2898 sc->cardFreq == CARD_FREQ_DEF) /* only do this if at full freq */
2899 { 2899 {
2900 /* adjust counts down to 1/2 freq */ 2900 /* adjust counts down to 1/2 freq */
2901 sc->cardFreq = CARD_FREQ_DEF / 2; 2901 sc->cardFreq = CARD_FREQ_DEF / 2;
2902 sc->clkCountStartRecv = sc->clkCountStartRecv *2;  2902 sc->clkCountStartRecv = sc->clkCountStartRecv *2;
2903 sc->clkCountDataRecv = sc->clkCountDataRecv *2;  2903 sc->clkCountDataRecv = sc->clkCountDataRecv *2;
2904 sc->clkCountDataSend = sc->clkCountDataSend *2;  2904 sc->clkCountDataSend = sc->clkCountDataSend *2;
2905 2905
2906 2906
2907 /* adjust this so that we have clocked in only fist bit of TS */ 2907 /* adjust this so that we have clocked in only fist bit of TS */
2908 sc->shiftParity = 0; 2908 sc->shiftParity = 0;
2909 sc->shiftByte = 0; 2909 sc->shiftByte = 0;
2910 sc->shiftBits = 1; 2910 sc->shiftBits = 1;
2911 2911
2912 scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,(sc->clkCountDataRecv * 3) /4); 2912 scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,(sc->clkCountDataRecv * 3) /4);
2913 } 2913 }
2914 else 2914 else
2915 { 2915 {
2916 scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,sc->clkCountDataRecv); 2916 scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,sc->clkCountDataRecv);
2917 } 2917 }
2918 } 2918 }
2919 2919
2920 /* clock in parity bit */ 2920 /* clock in parity bit */
2921 else if (sc->shiftBits == 8) 2921 else if (sc->shiftBits == 8)
2922 { 2922 {
2923 if (sc->convention == CONVENTION_INVERSE) 2923 if (sc->convention == CONVENTION_INVERSE)
2924 { 2924 {
2925 if (!scrGetData()) 2925 if (!scrGetData())
2926 { 2926 {
2927 sc->shiftParity++; 2927 sc->shiftParity++;
2928 } 2928 }
2929 } 2929 }
2930 else if (sc->convention == CONVENTION_DIRECT) 2930 else if (sc->convention == CONVENTION_DIRECT)
2931 { 2931 {
2932 if (scrGetData()) 2932 if (scrGetData())
2933 { 2933 {
2934 sc->shiftParity++; 2934 sc->shiftParity++;
2935 } 2935 }
2936 } 2936 }
2937 2937
2938 2938
2939 else 2939 else
2940 { 2940 {
2941 /* sc->convention not set so sort it out */ 2941 /* sc->convention not set so sort it out */
2942 ASSERT(sc->convention == CONVENTION_UNKNOWN); 2942 ASSERT(sc->convention == CONVENTION_UNKNOWN);
2943 if (sc->shiftByte == CONVENIONT_INVERSE_ID && scrGetData()) 2943 if (sc->shiftByte == CONVENIONT_INVERSE_ID && scrGetData())
2944 { 2944 {
2945 sc->convention = CONVENTION_INVERSE; 2945 sc->convention = CONVENTION_INVERSE;
2946 sc->shiftParity = 0; /* force good parity */ 2946 sc->shiftParity = 0; /* force good parity */
2947 } 2947 }
2948 2948
2949 else if (sc->shiftByte == CONVENTION_DIRECT_ID && scrGetData()) 2949 else if (sc->shiftByte == CONVENTION_DIRECT_ID && scrGetData())
2950 { 2950 {
2951 sc->shiftByte = CONVENTION_DIRECT_FIX; 2951 sc->shiftByte = CONVENTION_DIRECT_FIX;
2952 sc->convention = CONVENTION_DIRECT; 2952 sc->convention = CONVENTION_DIRECT;
2953 sc->shiftParity = 0; /* force good parity */ 2953 sc->shiftParity = 0; /* force good parity */
2954 } 2954 }
2955 2955
2956 else 2956 else
2957 { 2957 {
2958 sc->shiftParity = 1; /* force bad parity */ 2958 sc->shiftParity = 1; /* force bad parity */
2959 } 2959 }
2960 } 2960 }
2961 2961
2962 2962
2963 if ((sc->shiftParity & 01) == 0) 2963 if ((sc->shiftParity & 01) == 0)
2964 { 2964 {
2965 sc->shiftBits++; 2965 sc->shiftBits++;
2966 scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,sc->clkCountDataRecv); 2966 scrTimeout(t0RecvByteSM,sc,t0rbcTClockData,sc->clkCountDataRecv);
2967 } 2967 }
2968 else 2968 else
2969 { 2969 {
2970 /* got parity error */ 2970 /* got parity error */
2971 if (sc->shiftParityCount < PARITY_ERROR_MAX) 2971 if (sc->shiftParityCount < PARITY_ERROR_MAX)
2972 { 2972 {
2973 sc->shiftParityCount++; 2973 sc->shiftParityCount++;
2974 scrTimeout(t0RecvByteSM,sc,t0rbcTErrorStart,sc->clkCountDataRecv); 2974 scrTimeout(t0RecvByteSM,sc,t0rbcTErrorStart,sc->clkCountDataRecv);
2975 sc->t0RecvByteS = t0rbsSendError; 2975 sc->t0RecvByteS = t0rbsSendError;
2976 } 2976 }
2977 else 2977 else
2978 2978
2979 { 2979 {
2980 /* too many parity errors, just give up on this sc->dataByte */ 2980 /* too many parity errors, just give up on this sc->dataByte */
2981 sc->status = ERROR_PARITY; 2981 sc->status = ERROR_PARITY;
2982 sc->t0RecvByteS = t0rbsIdle; 2982 sc->t0RecvByteS = t0rbsIdle;
2983 sc->t0ByteParent(sc,gcT0RecvByteErr); 2983 sc->t0ByteParent(sc,gcT0RecvByteErr);
2984 } 2984 }
2985 } 2985 }
2986 } 2986 }
2987 2987
2988 else 2988 else
2989 { 2989 {
2990 sc->dataByte = sc->shiftByte; 2990 sc->dataByte = sc->shiftByte;
2991 sc->t0RecvByteS = t0rbsIdle; 2991 sc->t0RecvByteS = t0rbsIdle;
2992 sc->t0ByteParent(sc,gcT0RecvByte); 2992 sc->t0ByteParent(sc,gcT0RecvByte);
2993 } 2993 }
2994 break; 2994 break;
2995 2995
2996 default: 2996 default:
2997 INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); 2997 INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd);
2998 break; 2998 break;
2999 } 2999 }
3000 break; 3000 break;
3001 3001
3002 3002
3003 case t0rbsSendError:  3003 case t0rbsSendError:
3004 TOGGLE_TEST_PIN(); 3004 TOGGLE_TEST_PIN();
3005 switch (cmd) 3005 switch (cmd)
3006 { 3006 {
3007 case t0rbcTErrorStart: 3007 case t0rbcTErrorStart:
3008 /* start sending error bit */ 3008 /* start sending error bit */
3009 scrSetData(false); 3009 scrSetData(false);
3010 scrTimeout(t0RecvByteSM,sc,t0rbcTErrorStop,sc->clkCountDataRecv * 2); 3010 scrTimeout(t0RecvByteSM,sc,t0rbcTErrorStop,sc->clkCountDataRecv * 2);
3011 break; 3011 break;
3012 3012
3013 case t0rbcTErrorStop: 3013 case t0rbcTErrorStop:
3014 /* stop sending parity error & reset information*/ 3014 /* stop sending parity error & reset information*/
3015 scrSetData(true); 3015 scrSetData(true);
3016 sc->shiftBits = 0; 3016 sc->shiftBits = 0;
3017 sc->shiftByte = 0; 3017 sc->shiftByte = 0;
3018 sc->shiftParity = 0; 3018 sc->shiftParity = 0;
3019 3019
3020 /* start looking for start bit */ 3020 /* start looking for start bit */
3021 scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,1); 3021 scrTimeout(t0RecvByteSM,sc,t0rbcTFindStartEdge,1);
3022 sc->t0RecvByteS = t0rbsFindStartEdge; 3022 sc->t0RecvByteS = t0rbsFindStartEdge;
3023 break; 3023 break;
3024 3024
3025 default: 3025 default:
3026 INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); 3026 INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd);
3027 break; 3027 break;
3028 } 3028 }
3029 break; 3029 break;
3030 3030
3031 3031
3032 default: 3032 default:
3033 INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd); 3033 INVALID_STATE_CMD(sc, sc->t0RecvByteS,cmd);
3034 break; 3034 break;
3035 } 3035 }
3036} 3036}
3037 3037
3038/* 3038/*
3039**++ 3039**++
3040** FUNCTIONAL DESCRIPTION: 3040** FUNCTIONAL DESCRIPTION:
3041** 3041**
3042** t0SendByteSM 3042** t0SendByteSM
3043** 3043**
3044** This state machine writes 1 byte to a card. 3044** This state machine writes 1 byte to a card.
3045** It is a low level bit-bashing state machine. 3045** It is a low level bit-bashing state machine.
3046** 3046**
3047** 3047**
3048** Several mid level machines can use this machine, so the value 3048** Several mid level machines can use this machine, so the value
3049** sc->t0ByteParent is used to point to back to the mid level machine 3049** sc->t0ByteParent is used to point to back to the mid level machine
3050** 3050**
3051** FORMAL PARAMETERS: 3051** FORMAL PARAMETERS:
3052** 3052**
3053** sc - Pointer to the softc structure. 3053** sc - Pointer to the softc structure.
3054** cmd - command to this machine  3054** cmd - command to this machine
3055** 3055**
3056** IMPLICIT INPUTS: 3056** IMPLICIT INPUTS:
3057** 3057**
3058** sc->t0SendByteS state of this machine  3058** sc->t0SendByteS state of this machine
3059** sc->shiftByte byte to write to the card  3059** sc->shiftByte byte to write to the card
3060** 3060**
3061** IMPLICIT OUTPUTS: 3061** IMPLICIT OUTPUTS:
3062** 3062**
3063** sc->status error value if could not read byte 3063** sc->status error value if could not read byte
3064** 3064**
3065** FUNCTION VALUE: 3065** FUNCTION VALUE:
3066** 3066**
3067** nill 3067** nill
3068** 3068**
3069** SIDE EFFECTS: 3069** SIDE EFFECTS:
3070** 3070**
3071** nill 3071** nill
3072**-- 3072**--
3073*/ 3073*/
3074//int bigTroubleTest = 0; 3074//int bigTroubleTest = 0;
3075static void t0SendByteSM (struct scr_softc * sc,int cmd) 3075static void t0SendByteSM (struct scr_softc * sc,int cmd)
3076{ 3076{
3077 //if(bigTroubleTest == 2000) 3077 //if(bigTroubleTest == 2000)
3078 //{ 3078 //{
3079 // INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); 3079 // INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd);
3080 // bigTroubleTest = 0; 3080 // bigTroubleTest = 0;
3081 //} 3081 //}
3082 // 3082 //
3083 //bigTroubleTest++; 3083 //bigTroubleTest++;
3084  3084
3085 if (sc->bigTrouble) return; // david,jim , remove this when dust settles  3085 if (sc->bigTrouble) return; // david,jim , remove this when dust settles
3086 3086
3087 if (cmd == t0sbcAbort) 3087 if (cmd == t0sbcAbort)
3088 { 3088 {
3089 /* kill all the timers */ 3089 /* kill all the timers */
3090 scrUntimeout(t0SendByteSM, sc, t0sbcTGuardTime); 3090 scrUntimeout(t0SendByteSM, sc, t0sbcTGuardTime);
3091 scrUntimeout(t0SendByteSM, sc, t0sbcTClockData); 3091 scrUntimeout(t0SendByteSM, sc, t0sbcTClockData);
3092 scrUntimeout(t0SendByteSM, sc, t0sbcTError); 3092 scrUntimeout(t0SendByteSM, sc, t0sbcTError);
3093 3093
3094 scrSetDataHighZ(); 3094 scrSetDataHighZ();
3095 return; 3095 return;
3096 } 3096 }
3097 3097
3098 3098
3099 switch (sc->t0SendByteS) 3099 switch (sc->t0SendByteS)
3100 { 3100 {
3101 case t0sbsIdle: 3101 case t0sbsIdle:
3102 switch (cmd) 3102 switch (cmd)
3103 { 3103 {
3104 case t0sbcStart: 3104 case t0sbcStart:
3105 /* set initial conditions */ 3105 /* set initial conditions */
3106 sc->shiftBits = 0; 3106 sc->shiftBits = 0;
3107 sc->shiftParity = 0; 3107 sc->shiftParity = 0;
3108 sc->shiftParityCount = 0; 3108 sc->shiftParityCount = 0;
3109 sc->shiftByte = sc->dataByte; 3109 sc->shiftByte = sc->dataByte;
3110 3110
3111 scrClkAdj(sc->clkCountDataSend); /* send data clock running at 1 ETU */ 3111 scrClkAdj(sc->clkCountDataSend); /* send data clock running at 1 ETU */
3112 3112
3113 /* check if we have to wait for guard time */ 3113 /* check if we have to wait for guard time */
3114 if (0) /* possible optimization here */ 3114 if (0) /* possible optimization here */
3115 { 3115 {
3116 /* can send start bit now */ 3116 /* can send start bit now */
3117 scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); 3117 scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend);
3118 scrSetData(false); 3118 scrSetData(false);
3119 sc->t0SendByteS = t0sbsClockData; 3119 sc->t0SendByteS = t0sbsClockData;
3120 } 3120 }
3121 else 3121 else
3122 { 3122 {
3123 /* need to wait for guard time */ 3123 /* need to wait for guard time */
3124 scrTimeout(t0SendByteSM,sc,t0sbcTGuardTime,sc->clkCountDataSend * (12 + sc->N)); 3124 scrTimeout(t0SendByteSM,sc,t0sbcTGuardTime,sc->clkCountDataSend * (12 + sc->N));
3125 sc->t0SendByteS = t0sbsWaitGuardTime; 3125 sc->t0SendByteS = t0sbsWaitGuardTime;
3126 3126
3127 } 3127 }
3128 break; 3128 break;
3129 3129
3130 default: 3130 default:
3131 INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); 3131 INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd);
3132 break; 3132 break;
3133 } 3133 }
3134 break; 3134 break;
3135 3135
3136 3136
3137 case t0sbsWaitGuardTime: 3137 case t0sbsWaitGuardTime:
3138 switch (cmd) 3138 switch (cmd)
3139 { 3139 {
3140 case t0sbcTGuardTime:  3140 case t0sbcTGuardTime:
3141 TOGGLE_TEST_PIN(); 3141 TOGGLE_TEST_PIN();
3142 /* set start bit */ 3142 /* set start bit */
3143 scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); 3143 scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend);
3144 scrSetData(false); 3144 scrSetData(false);
3145 sc->t0SendByteS = t0sbsClockData; 3145 sc->t0SendByteS = t0sbsClockData;
3146 break; 3146 break;
3147 3147
3148 default: 3148 default:
3149 INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); 3149 INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd);
3150 break; 3150 break;
3151 } 3151 }
3152 break; 3152 break;
3153 3153
3154 3154
3155 case t0sbsClockData: 3155 case t0sbsClockData:
3156 switch (cmd) 3156 switch (cmd)
3157 { 3157 {
3158 case t0sbcTClockData:  3158 case t0sbcTClockData:
3159 TOGGLE_TEST_PIN(); 3159 TOGGLE_TEST_PIN();
3160 /* clock out data bit */ 3160 /* clock out data bit */
3161 if (sc->shiftBits < 8) 3161 if (sc->shiftBits < 8)
3162 { 3162 {
3163 if (sc->convention == CONVENTION_INVERSE) 3163 if (sc->convention == CONVENTION_INVERSE)
3164 { 3164 {
3165 if (sc->shiftByte & 0x80) 3165 if (sc->shiftByte & 0x80)
3166 { 3166 {
3167 scrSetData(false); 3167 scrSetData(false);
3168 sc->shiftParity++; 3168 sc->shiftParity++;
3169 } 3169 }
3170 else 3170 else
3171 { 3171 {
3172 scrSetData(true); 3172 scrSetData(true);
3173 } 3173 }
3174 sc->shiftByte = sc->shiftByte << 1; 3174 sc->shiftByte = sc->shiftByte << 1;
3175 } 3175 }
3176 else 3176 else
3177 { 3177 {
3178 ASSERT(sc->convention == CONVENTION_DIRECT); 3178 ASSERT(sc->convention == CONVENTION_DIRECT);
3179 if (sc->shiftByte & 0x01) 3179 if (sc->shiftByte & 0x01)
3180 { 3180 {
3181 scrSetData(true); 3181 scrSetData(true);
3182 sc->shiftParity++; 3182 sc->shiftParity++;
3183 } 3183 }
3184 else 3184 else
3185 { 3185 {
3186 scrSetData(false); 3186 scrSetData(false);
3187 } 3187 }
3188 sc->shiftByte = sc->shiftByte >> 1; 3188 sc->shiftByte = sc->shiftByte >> 1;
3189 } 3189 }
3190 sc->shiftBits++; 3190 sc->shiftBits++;
3191 scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); 3191 scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend);
3192 } 3192 }
3193 3193
3194 /* clock out parity bit */ 3194 /* clock out parity bit */
3195 else if (sc->shiftBits == 8) 3195 else if (sc->shiftBits == 8)
3196 { 3196 {
3197 if ( ((sc->shiftParity & 0x01) && (sc->convention == CONVENTION_INVERSE)) || 3197 if ( ((sc->shiftParity & 0x01) && (sc->convention == CONVENTION_INVERSE)) ||
3198 (!(sc->shiftParity & 0x01) && (sc->convention == CONVENTION_DIRECT)) ) 3198 (!(sc->shiftParity & 0x01) && (sc->convention == CONVENTION_DIRECT)) )
3199 { 3199 {
3200 scrSetData(false); 3200 scrSetData(false);
3201 } 3201 }
3202 else 3202 else
3203 { 3203 {
3204 scrSetData(true); 3204 scrSetData(true);
3205 } 3205 }
3206 sc->shiftBits++; 3206 sc->shiftBits++;
3207 scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); 3207 scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend);
3208 } 3208 }
3209 3209
3210 /* all data shifted out, move onto next state */ 3210 /* all data shifted out, move onto next state */
3211 else 3211 else
3212 { 3212 {
3213 ASSERT(sc->shiftBits > 8); 3213 ASSERT(sc->shiftBits > 8);
3214 scrSetData(true); 3214 scrSetData(true);
3215 scrTimeout(t0SendByteSM,sc,t0sbcTError,sc->clkCountDataSend); 3215 scrTimeout(t0SendByteSM,sc,t0sbcTError,sc->clkCountDataSend);
3216 sc->t0SendByteS = t0sbsWaitError; 3216 sc->t0SendByteS = t0sbsWaitError;
3217 } 3217 }
3218 break; 3218 break;
3219 3219
3220 default: 3220 default:
3221 INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); 3221 INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd);
3222 break; 3222 break;
3223 } 3223 }
3224 break; 3224 break;
3225 3225
3226 case t0sbsWaitError: 3226 case t0sbsWaitError:
3227 switch (cmd) 3227 switch (cmd)
3228 { 3228 {
3229 case t0sbcTError:  3229 case t0sbcTError:
3230 /* no error indicated*/ 3230 /* no error indicated*/
3231 if (scrGetData()) 3231 if (scrGetData())
3232 { 3232 {
3233 sc->t0SendByteS = t0sbsIdle; 3233 sc->t0SendByteS = t0sbsIdle;
3234 sc->t0ByteParent(sc,gcT0SendByte); 3234 sc->t0ByteParent(sc,gcT0SendByte);
3235 } 3235 }
3236 3236
3237 /* got error */ 3237 /* got error */
3238 else 3238 else
3239 { 3239 {
3240 /* got parity error */ 3240 /* got parity error */
3241 if (sc->shiftParityCount < PARITY_ERROR_MAX) 3241 if (sc->shiftParityCount < PARITY_ERROR_MAX)
3242 { 3242 {
3243 sc->shiftParityCount++; 3243 sc->shiftParityCount++;
3244 scrTimeout(t0SendByteSM,sc,t0sbcTResend,sc->clkCountDataSend * 2); 3244 scrTimeout(t0SendByteSM,sc,t0sbcTResend,sc->clkCountDataSend * 2);
3245 sc->t0SendByteS = t0sbsWaitResend; 3245 sc->t0SendByteS = t0sbsWaitResend;
3246 } 3246 }
3247 else 3247 else
3248 { 3248 {
3249 /* too many parity errors, just give up on this sc->dataByte */ 3249 /* too many parity errors, just give up on this sc->dataByte */
3250 sc->status = ERROR_PARITY; 3250 sc->status = ERROR_PARITY;
3251 sc->t0SendByteS = t0sbsIdle; 3251 sc->t0SendByteS = t0sbsIdle;
3252 sc->t0ByteParent(sc,gcT0SendByteErr); 3252 sc->t0ByteParent(sc,gcT0SendByteErr);
3253 } 3253 }
3254 } 3254 }
3255 break; 3255 break;
3256 3256
3257 default: 3257 default:
3258 INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); 3258 INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd);
3259 break; 3259 break;
3260 } 3260 }
3261 break; 3261 break;
3262 3262
3263 case t0sbsWaitResend: 3263 case t0sbsWaitResend:
3264 switch (cmd) 3264 switch (cmd)
3265 { 3265 {
3266 case t0sbcTResend: 3266 case t0sbcTResend:
3267 sc->shiftBits = 0; 3267 sc->shiftBits = 0;
3268 sc->shiftParity = 0; 3268 sc->shiftParity = 0;
3269 sc->shiftByte = sc->dataByte; 3269 sc->shiftByte = sc->dataByte;
3270 /* set start bit */ 3270 /* set start bit */
3271 3271
3272 scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend); 3272 scrTimeout(t0SendByteSM,sc,t0sbcTClockData,sc->clkCountDataSend);
3273 scrSetData(false); 3273 scrSetData(false);
3274 sc->t0SendByteS = t0sbsClockData; 3274 sc->t0SendByteS = t0sbsClockData;
3275 break; 3275 break;
3276 3276
3277 default: 3277 default:
3278 INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); 3278 INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd);
3279 break; 3279 break;
3280 } 3280 }
3281 break; 3281 break;
3282 3282
3283 3283
3284 default: 3284 default:
3285 INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd); 3285 INVALID_STATE_CMD(sc, sc->t0SendByteS,cmd);
3286 break; 3286 break;
3287 } 3287 }
3288} 3288}
3289 3289
3290 3290
3291 3291
3292 3292
3293 3293
3294 3294
3295 3295
3296 3296
3297 3297
3298 3298
3299 3299
3300/* 3300/*
3301**++ 3301**++
3302** FUNCTIONAL DESCRIPTION: 3302** FUNCTIONAL DESCRIPTION:
3303** 3303**
3304** cardOff 3304** cardOff
3305** 3305**
3306** Turn all signals to the card off 3306** Turn all signals to the card off
3307** 3307**
3308** FORMAL PARAMETERS: 3308** FORMAL PARAMETERS:
3309** 3309**
3310** sc - Pointer to the softc structure. 3310** sc - Pointer to the softc structure.
3311** 3311**
3312** IMPLICIT INPUTS: 3312** IMPLICIT INPUTS:
3313** 3313**
3314** nill 3314** nill
3315** 3315**
3316** IMPLICIT OUTPUTS: 3316** IMPLICIT OUTPUTS:
3317** 3317**
3318** nill 3318** nill
3319** 3319**
3320** FUNCTION VALUE: 3320** FUNCTION VALUE:
3321** 3321**
3322** nill 3322** nill
3323** 3323**
3324** SIDE EFFECTS: 3324** SIDE EFFECTS:
3325** 3325**
3326** nill 3326** nill
3327**-- 3327**--
3328*/ 3328*/
3329static void cardOff (struct scr_softc * sc) 3329static void cardOff (struct scr_softc * sc)
3330{ 3330{
3331 scrSetReset(true); 3331 scrSetReset(true);
3332 scrSetDataHighZ(); 3332 scrSetDataHighZ();
3333 scrSetClock(false); 3333 scrSetClock(false);
3334 scrSetPower(false); 3334 scrSetPower(false);
3335} 3335}
3336 3336
3337 3337
3338 3338
3339 3339
3340/* 3340/*
3341** 3341**
3342** 3342**
3343** **************** timer routines *************** 3343** **************** timer routines ***************
3344** 3344**
3345*/ 3345*/
3346 3346
3347/* 3347/*
3348**++ 3348**++
3349** FUNCTIONAL DESCRIPTION: 3349** FUNCTIONAL DESCRIPTION:
3350** 3350**
3351** scrClkInit 3351** scrClkInit
3352** 3352**
3353** Init the callout queues. The callout queues are used  3353** Init the callout queues. The callout queues are used
3354** by the timeout/untimeout queues 3354** by the timeout/untimeout queues
3355** 3355**
3356** FORMAL PARAMETERS: 3356** FORMAL PARAMETERS:
3357** 3357**
3358** nill 3358** nill
3359** 3359**
3360** IMPLICIT INPUTS: 3360** IMPLICIT INPUTS:
3361** 3361**
3362** nill 3362** nill
3363** 3363**
3364** IMPLICIT OUTPUTS: 3364** IMPLICIT OUTPUTS:
3365** 3365**
3366** nill 3366** nill
3367** 3367**
3368** FUNCTION VALUE: 3368** FUNCTION VALUE:
3369** 3369**
3370** nill 3370** nill
3371** 3371**
3372** SIDE EFFECTS: 3372** SIDE EFFECTS:
3373** 3373**
3374** nill 3374** nill
3375**-- 3375**--
3376*/ 3376*/
3377static void scrClkInit(void) 3377static void scrClkInit(void)
3378{ 3378{
3379 3379
3380 int lc; 3380 int lc;
3381 Callout *c; 3381 Callout *c;
3382 Callout *new; 3382 Callout *new;
3383 3383
3384 scrClkCallTodo.c_next = NULL; 3384 scrClkCallTodo.c_next = NULL;
3385 scrClkCallFree = &scrClkCalloutArray[0]; 3385 scrClkCallFree = &scrClkCalloutArray[0];
3386 c = scrClkCallFree; 3386 c = scrClkCallFree;
3387 3387
3388 for (lc = 1; lc < SCR_CLK_CALLOUT_COUNT; lc++) 3388 for (lc = 1; lc < SCR_CLK_CALLOUT_COUNT; lc++)
3389 { 3389 {
3390 new = &scrClkCalloutArray[lc]; 3390 new = &scrClkCalloutArray[lc];
3391 c->c_next = new; 3391 c->c_next = new;
3392 c = new; 3392 c = new;
3393 } 3393 }
3394 3394
3395 c->c_next = NULL; 3395 c->c_next = NULL;
3396} 3396}
3397 3397
3398 3398
3399/* 3399/*
3400**++ 3400**++
3401** FUNCTIONAL DESCRIPTION: 3401** FUNCTIONAL DESCRIPTION:
3402** 3402**
3403** scrClkStart 3403** scrClkStart
3404** 3404**
3405** This function starts the clock running. The clock is reall the  3405** This function starts the clock running. The clock is reall the
3406** HAT clock (High Available Timer) that is using a FIQ (fast interrupt 3406** HAT clock (High Available Timer) that is using a FIQ (fast interrupt
3407** request).  3407** request).
3408** 3408**
3409** FORMAL PARAMETERS: 3409** FORMAL PARAMETERS:
3410** 3410**
3411** sc - Pointer to the softc structure. 3411** sc - Pointer to the softc structure.
3412** countPerTick - value for T2 timer that drives FIQ 3412** countPerTick - value for T2 timer that drives FIQ
3413** 3413**
3414** IMPLICIT INPUTS: 3414** IMPLICIT INPUTS:
3415** 3415**
3416** nill 3416** nill
3417** 3417**
3418** IMPLICIT OUTPUTS: 3418** IMPLICIT OUTPUTS:
3419** 3419**
3420** nill 3420** nill
3421** 3421**
3422** FUNCTION VALUE: 3422** FUNCTION VALUE:
3423** 3423**
3424** nill 3424** nill
3425** 3425**
3426** SIDE EFFECTS: 3426** SIDE EFFECTS:
3427** 3427**
3428** nill 3428** nill
3429**-- 3429**--
3430*/ 3430*/
3431static void scrClkStart(struct scr_softc * sc,int countPerTick) 3431static void scrClkStart(struct scr_softc * sc,int countPerTick)
3432{ 3432{
3433 u_int savedInts;  3433 u_int savedInts;
3434 3434
3435 savedInts = disable_interrupts(I32_bit | F32_bit); 3435 savedInts = disable_interrupts(I32_bit | F32_bit);
3436 3436
3437  3437
3438 3438
3439 ASSERT(scrClkCallTodo.c_next == NULL); 3439 ASSERT(scrClkCallTodo.c_next == NULL);
3440 ASSERT(!scrClkEnable); 3440 ASSERT(!scrClkEnable);
3441 scrClkEnable = 1; 3441 scrClkEnable = 1;
3442 scrClkCount = countPerTick; 3442 scrClkCount = countPerTick;
3443 3443
3444 hatClkOn(countPerTick, 3444 hatClkOn(countPerTick,
3445 hatClkIrq, 3445 hatClkIrq,
3446 0xdeadbeef, 3446 0xdeadbeef,
3447 hatStack + HATSTACKSIZE - sizeof(unsigned), 3447 hatStack + HATSTACKSIZE - sizeof(unsigned),
3448 myHatWedge); 3448 myHatWedge);
3449 3449
3450 restore_interrupts(savedInts); 3450 restore_interrupts(savedInts);
3451} 3451}
3452 3452
3453/* 3453/*
3454**++ 3454**++
3455** FUNCTIONAL DESCRIPTION: 3455** FUNCTIONAL DESCRIPTION:
3456** 3456**
3457** scrClkAdj 3457** scrClkAdj
3458** 3458**
3459** Adjusts the frequence of the clock 3459** Adjusts the frequence of the clock
3460** 3460**
3461** FORMAL PARAMETERS: 3461** FORMAL PARAMETERS:
3462** 3462**
3463** count - new value for T2 timer that drives FIQ 3463** count - new value for T2 timer that drives FIQ
3464** 3464**
3465** IMPLICIT INPUTS: 3465** IMPLICIT INPUTS:
3466** 3466**
3467** nill 3467** nill
3468** 3468**
3469** IMPLICIT OUTPUTS: 3469** IMPLICIT OUTPUTS:
3470** 3470**
3471** nill 3471** nill
3472** 3472**
3473** FUNCTION VALUE: 3473** FUNCTION VALUE:
3474** 3474**
3475** nill 3475** nill
3476** 3476**
3477** SIDE EFFECTS: 3477** SIDE EFFECTS:
3478** 3478**
3479** nill 3479** nill
3480**-- 3480**--
3481*/ 3481*/
3482static void scrClkAdj (int count) 3482static void scrClkAdj (int count)
3483{  3483{
3484 u_int savedInts;  3484 u_int savedInts;
3485 3485
3486 if (count != scrClkCount) 3486 if (count != scrClkCount)
3487 { 3487 {
3488 savedInts = disable_interrupts(I32_bit | F32_bit); 3488 savedInts = disable_interrupts(I32_bit | F32_bit);
3489 3489
3490 ASSERT(scrClkEnable); 3490 ASSERT(scrClkEnable);
3491 3491
3492 scrClkCount = count; 3492 scrClkCount = count;
3493 hatClkAdjust(count); 3493 hatClkAdjust(count);
3494 3494
3495 restore_interrupts(savedInts); 3495 restore_interrupts(savedInts);
3496 } 3496 }
3497} 3497}
3498 3498
3499/* 3499/*
3500**++ 3500**++
3501** FUNCTIONAL DESCRIPTION: 3501** FUNCTIONAL DESCRIPTION:
3502** 3502**
3503** scrClkStop 3503** scrClkStop
3504** 3504**
3505** Stops the clock 3505** Stops the clock
3506** 3506**
3507** FORMAL PARAMETERS: 3507** FORMAL PARAMETERS:
3508** 3508**
3509** nill 3509** nill
3510**  3510**
3511** 3511**
3512** IMPLICIT INPUTS: 3512** IMPLICIT INPUTS:
3513** 3513**
3514** nill 3514** nill
3515** 3515**
3516** IMPLICIT OUTPUTS: 3516** IMPLICIT OUTPUTS:
3517** 3517**
3518** nill 3518** nill
3519** 3519**
3520** FUNCTION VALUE: 3520** FUNCTION VALUE:
3521** 3521**
3522** nill 3522** nill
3523** 3523**
3524** SIDE EFFECTS: 3524** SIDE EFFECTS:
3525** 3525**
3526** nill 3526** nill
3527**-- 3527**--
3528*/ 3528*/
3529static void scrClkStop(void) 3529static void scrClkStop(void)
3530{ 3530{
3531 u_int savedInts;  3531 u_int savedInts;
3532 savedInts = disable_interrupts(I32_bit | F32_bit); 3532 savedInts = disable_interrupts(I32_bit | F32_bit);
3533 3533
3534 ASSERT(scrClkEnable); 3534 ASSERT(scrClkEnable);
3535 scrClkEnable = 0; 3535 scrClkEnable = 0;
3536 ASSERT(scrClkCallTodo.c_next == NULL); 3536 ASSERT(scrClkCallTodo.c_next == NULL);
3537 hatClkOff(); 3537 hatClkOff();
3538 3538
3539 restore_interrupts(savedInts); 3539 restore_interrupts(savedInts);
3540} 3540}
3541 3541
3542 3542
3543 3543
3544/* 3544/*
3545**++ 3545**++
3546** FUNCTIONAL DESCRIPTION: 3546** FUNCTIONAL DESCRIPTION:
3547** 3547**
3548** hatClkIrq 3548** hatClkIrq
3549** 3549**
3550** This is what the HAT clock calls. This call drives 3550** This is what the HAT clock calls. This call drives
3551** the timeout queues, which in turn drive the state machines  3551** the timeout queues, which in turn drive the state machines
3552**  3552**
3553** Be very carefully when calling a timeout as the function 3553** Be very carefully when calling a timeout as the function
3554** that is called may in turn do timeout/untimeout calls  3554** that is called may in turn do timeout/untimeout calls
3555** before returning  3555** before returning
3556** 3556**
3557** FORMAL PARAMETERS: 3557** FORMAL PARAMETERS:
3558** 3558**
3559** int x - not used  3559** int x - not used
3560** 3560**
3561** IMPLICIT INPUTS: 3561** IMPLICIT INPUTS:
3562** 3562**
3563** nill 3563** nill
3564** 3564**
3565** IMPLICIT OUTPUTS: 3565** IMPLICIT OUTPUTS:
3566** 3566**
3567** nill 3567** nill
3568** 3568**
3569** FUNCTION VALUE: 3569** FUNCTION VALUE:
3570** 3570**
3571** nill 3571** nill
3572** 3572**
3573** SIDE EFFECTS: 3573** SIDE EFFECTS:
3574** 3574**
3575** a timeout may be called if it is due 3575** a timeout may be called if it is due
3576**-- 3576**--
3577*/ 3577*/
3578static void hatClkIrq(int x) 3578static void hatClkIrq(int x)
3579{ 3579{
3580 register Callout *p1; 3580 register Callout *p1;
3581 register int needsoft =0; 3581 register int needsoft =0;
3582 register Callout *c; 3582 register Callout *c;
3583 register int arg; 3583 register int arg;
3584 register void (*func)(struct scr_softc*,int); 3584 register void (*func)(struct scr_softc*,int);
3585 struct scr_softc * sc; 3585 struct scr_softc * sc;
3586 3586
3587 ASSERT(scrClkEnable); 3587 ASSERT(scrClkEnable);
3588 for (p1 = scrClkCallTodo.c_next; p1 != NULL; p1 = p1->c_next) 3588 for (p1 = scrClkCallTodo.c_next; p1 != NULL; p1 = p1->c_next)
3589 { 3589 {
3590 p1->c_time -= scrClkCount; 3590 p1->c_time -= scrClkCount;
3591 3591
3592 if (p1->c_time > 0) 3592 if (p1->c_time > 0)
3593 { 3593 {
3594 break; 3594 break;
3595 } 3595 }
3596 needsoft = 1; 3596 needsoft = 1;
3597 if (p1->c_time == 0) 3597 if (p1->c_time == 0)
3598 { 3598 {
3599 break; 3599 break;
3600 } 3600 }
3601 } 3601 }
3602 3602
3603 3603
3604 if (needsoft) 3604 if (needsoft)
3605 { 3605 {
3606 while ((c = scrClkCallTodo.c_next) != NULL && c->c_time <= 0) 3606 while ((c = scrClkCallTodo.c_next) != NULL && c->c_time <= 0)
3607 { 3607 {
3608 func = c->c_func; 3608 func = c->c_func;
3609 sc = c->c_sc; 3609 sc = c->c_sc;
3610 arg = c->c_arg; 3610 arg = c->c_arg;
3611 scrClkCallTodo.c_next = c->c_next; 3611 scrClkCallTodo.c_next = c->c_next;
3612 c->c_next = scrClkCallFree; 3612 c->c_next = scrClkCallFree;
3613 scrClkCallFree = c; 3613 scrClkCallFree = c;
3614 (*func)(sc,arg); 3614 (*func)(sc,arg);
3615 } 3615 }
3616 } 3616 }
3617} 3617}
3618 3618
3619/* 3619/*
3620**++ 3620**++
3621** FUNCTIONAL DESCRIPTION: 3621** FUNCTIONAL DESCRIPTION:
3622** 3622**
3623** myHatWedge 3623** myHatWedge
3624** 3624**
3625** Called if the HAT timer becomes clogged/wedged. Not 3625** Called if the HAT timer becomes clogged/wedged. Not
3626** used by this driver, we let upper layers recover 3626** used by this driver, we let upper layers recover
3627** from this condition 3627** from this condition
3628** 3628**
3629** FORMAL PARAMETERS: 3629** FORMAL PARAMETERS:
3630** 3630**
3631** int nFIQs - not used 3631** int nFIQs - not used
3632** 3632**
3633** IMPLICIT INPUTS: 3633** IMPLICIT INPUTS:
3634** 3634**
3635** nill 3635** nill
3636** 3636**
3637** IMPLICIT OUTPUTS: 3637** IMPLICIT OUTPUTS:
3638** 3638**
3639** nill 3639** nill
3640** 3640**
3641** FUNCTION VALUE: 3641** FUNCTION VALUE:
3642** 3642**
3643** nill 3643** nill
3644** 3644**
3645** SIDE EFFECTS: 3645** SIDE EFFECTS:
3646** 3646**
3647** nill 3647** nill
3648**-- 3648**--
3649*/ 3649*/
3650static void myHatWedge(int nFIQs) 3650static void myHatWedge(int nFIQs)
3651{ 3651{
3652 #ifdef DEBUG 3652 #ifdef DEBUG
3653 printf("myHatWedge: nFIQ = %d\n",nFIQs); 3653 printf("myHatWedge: nFIQ = %d\n",nFIQs);
3654 #endif  3654 #endif
3655} 3655}
3656 3656
3657 3657
3658 3658
3659/* 3659/*
3660**++ 3660**++
3661** FUNCTIONAL DESCRIPTION: 3661** FUNCTIONAL DESCRIPTION:
3662** 3662**
3663** scrTimeout 3663** scrTimeout
3664** 3664**
3665** Execute a function after a specified length of time. 3665** Execute a function after a specified length of time.
3666** 3666**
3667** 3667**
3668** FORMAL PARAMETERS: 3668** FORMAL PARAMETERS:
3669** 3669**
3670** ftn - function to execute 3670** ftn - function to execute
3671** sc - pointer to soft c 3671** sc - pointer to soft c
3672** arg - argument passed to function 3672** arg - argument passed to function
3673** count - number of T2 counts for timeout 3673** count - number of T2 counts for timeout
3674** 3674**
3675** IMPLICIT INPUTS: 3675** IMPLICIT INPUTS:
3676** 3676**
3677** nill 3677** nill
3678** 3678**
3679** IMPLICIT OUTPUTS: 3679** IMPLICIT OUTPUTS:
3680** 3680**
3681** nill 3681** nill
3682** 3682**
3683** FUNCTION VALUE: 3683** FUNCTION VALUE:
3684** 3684**
3685** nill 3685** nill
3686** 3686**
3687** SIDE EFFECTS: 3687** SIDE EFFECTS:
3688** 3688**
3689** nill 3689** nill
3690**-- 3690**--
3691*/ 3691*/
3692 3692
3693static void scrTimeout(ftn, sc, arg, count) 3693static void
3694 void (*ftn)(struct scr_softc*,int); 3694scrTimeout(
3695 struct scr_softc* sc; 3695 void (*ftn)(struct scr_softc*,int),
3696 int arg; 3696 struct scr_softc* sc,
3697 register int count; 3697 int arg,
 3698 int count)
3698{ 3699{
3699 3700
3700 register Callout *new, *p, *t; 3701 register Callout *new, *p, *t;
3701 ASSERT(scrClkEnable); 3702 ASSERT(scrClkEnable);
3702 3703
3703 3704
3704 if (count <= 0) 3705 if (count <= 0)
3705 { 3706 {
3706 count = 1; 3707 count = 1;
3707 } 3708 }
3708 3709
3709 3710
3710 /* Fill in the next free fcallout structure. */ 3711 /* Fill in the next free fcallout structure. */
3711 if (scrClkCallFree == NULL) 3712 if (scrClkCallFree == NULL)
3712 { 3713 {
3713 panic("timeout table full"); 3714 panic("timeout table full");
3714 } 3715 }
3715 3716
3716 new = scrClkCallFree; 3717 new = scrClkCallFree;
3717 scrClkCallFree = new->c_next; 3718 scrClkCallFree = new->c_next;
3718 new->c_sc = sc; 3719 new->c_sc = sc;
3719 new->c_arg = arg; 3720 new->c_arg = arg;
3720 new->c_func = ftn; 3721 new->c_func = ftn;
3721 3722
3722 /* 3723 /*
3723 * The time for each event is stored as a difference from the time 3724 * The time for each event is stored as a difference from the time
3724 * of the previous event on the queue. Walk the queue, correcting 3725 * of the previous event on the queue. Walk the queue, correcting
3725 * the counts argument for queue entries passed. Correct the counts 3726 * the counts argument for queue entries passed. Correct the counts
3726 * value for the queue entry immediately after the insertion point 3727 * value for the queue entry immediately after the insertion point
3727 * as well. Watch out for negative c_time values; these represent 3728 * as well. Watch out for negative c_time values; these represent
3728 * overdue events. 3729 * overdue events.
3729 */ 3730 */
3730 for (p = &scrClkCallTodo; (t = p->c_next) != NULL && count > t->c_time; p = t) 3731 for (p = &scrClkCallTodo; (t = p->c_next) != NULL && count > t->c_time; p = t)
3731 { 3732 {
3732 if (t->c_time > 0) 3733 if (t->c_time > 0)
3733 { 3734 {
3734 count -= t->c_time; 3735 count -= t->c_time;
3735 } 3736 }
3736 } 3737 }
3737 3738
3738 3739
3739 new->c_time = count; 3740 new->c_time = count;
3740 if (t != NULL) 3741 if (t != NULL)
3741 { 3742 {
3742 t->c_time -= count; 3743 t->c_time -= count;
3743 } 3744 }
3744 3745
3745 /* Insert the new entry into the queue. */ 3746 /* Insert the new entry into the queue. */
3746 p->c_next = new; 3747 p->c_next = new;
3747 new->c_next = t; 3748 new->c_next = t;
3748} 3749}
3749 3750
3750/* 3751/*
3751**++ 3752**++
3752** FUNCTIONAL DESCRIPTION: 3753** FUNCTIONAL DESCRIPTION:
3753** 3754**
3754** scrUntimeout 3755** scrUntimeout
3755** 3756**
3756** Cancel previous timeout function call. 3757** Cancel previous timeout function call.
3757** 3758**
3758** FORMAL PARAMETERS: 3759** FORMAL PARAMETERS:
3759** 3760**
3760** ftn - function of timeout to cancel 3761** ftn - function of timeout to cancel
3761** sc - sc of timeout to cancel 3762** sc - sc of timeout to cancel
3762** arg - arg of timeout to cancel 3763** arg - arg of timeout to cancel
3763** 3764**
3764** IMPLICIT INPUTS: 3765** IMPLICIT INPUTS:
3765** 3766**
3766** nill 3767** nill
3767** 3768**
3768** IMPLICIT OUTPUTS: 3769** IMPLICIT OUTPUTS:
3769** 3770**
3770** nill 3771** nill
3771** 3772**
3772** FUNCTION VALUE: 3773** FUNCTION VALUE:
3773** 3774**
3774** nill 3775** nill
3775** 3776**
3776** SIDE EFFECTS: 3777** SIDE EFFECTS:
3777** 3778**
3778** nill 3779** nill
3779**-- 3780**--
3780*/ 3781*/
3781static void scrUntimeout(ftn, sc, arg) 3782static void
3782void (*ftn)(struct scr_softc*,int); 3783scrUntimeout(
3783struct scr_softc* sc; 3784 void (*ftn)(struct scr_softc*, int),
3784int arg; 3785 struct scr_softc* sc,
 3786 int arg)
3785{ 3787{
3786 register Callout *p, *t; 3788 register Callout *p, *t;
3787 ASSERT(scrClkEnable); 3789 ASSERT(scrClkEnable);
3788 3790
3789 for (p = &scrClkCallTodo; (t = p->c_next) != NULL; p = t) 3791 for (p = &scrClkCallTodo; (t = p->c_next) != NULL; p = t)
3790 { 3792 {
3791 if (t->c_func == ftn && t->c_sc == sc && t->c_arg == arg) 3793 if (t->c_func == ftn && t->c_sc == sc && t->c_arg == arg)
3792 { 3794 {
3793 /* Increment next entry's count. */ 3795 /* Increment next entry's count. */
3794 if (t->c_next && t->c_time > 0) 3796 if (t->c_next && t->c_time > 0)
3795 { 3797 {
3796 t->c_next->c_time += t->c_time; 3798 t->c_next->c_time += t->c_time;
3797 } 3799 }
3798 3800
3799 /* Move entry from fcallout queue to scrClkCallFree queue. */ 3801 /* Move entry from fcallout queue to scrClkCallFree queue. */
3800 p->c_next = t->c_next; 3802 p->c_next = t->c_next;
3801 t->c_next = scrClkCallFree; 3803 t->c_next = scrClkCallFree;
3802 scrClkCallFree = t; 3804 scrClkCallFree = t;
3803 break; 3805 break;
3804 } 3806 }
3805 } 3807 }
3806} 3808}
3807 3809
3808 3810
3809 3811
3810 3812
3811 3813
3812 3814
3813 3815
3814 3816
3815 3817
3816 3818
3817 3819
3818 3820
3819 3821
3820 3822
3821 3823
3822/******************* routines used only during debugging */ 3824/******************* routines used only during debugging */
3823#ifdef SCR_DEBUG 3825#ifdef SCR_DEBUG
3824 3826
3825/* 3827/*
3826**++ 3828**++
3827** FUNCTIONAL DESCRIPTION: 3829** FUNCTIONAL DESCRIPTION:
3828** 3830**
3829** invalidStateCmd 3831** invalidStateCmd
3830** 3832**
3831** Debugging function. Printout information about problem 3833** Debugging function. Printout information about problem
3832** and then kick in the debugger or panic 3834** and then kick in the debugger or panic
3833** 3835**
3834** FORMAL PARAMETERS: 3836** FORMAL PARAMETERS:
3835** 3837**
3836** sc - pointer to soft c 3838** sc - pointer to soft c
3837** state - state of machine  3839** state - state of machine
3838** cmd - command of machine 3840** cmd - command of machine
3839** line - line that problem was detected 3841** line - line that problem was detected
3840** 3842**
3841** 3843**
3842** IMPLICIT INPUTS: 3844** IMPLICIT INPUTS:
3843** 3845**
3844** nill 3846** nill
3845** 3847**
3846** IMPLICIT OUTPUTS: 3848** IMPLICIT OUTPUTS:
3847** 3849**
3848** nill 3850** nill
3849** 3851**
3850** FUNCTION VALUE: 3852** FUNCTION VALUE:
3851** 3853**
3852** nill 3854** nill
3853** 3855**
3854** SIDE EFFECTS: 3856** SIDE EFFECTS:
3855** 3857**
3856** nill 3858** nill
3857**-- 3859**--
3858*/ 3860*/
3859void invalidStateCmd (struct scr_softc* sc,int state,int cmd,int line) 3861void invalidStateCmd (struct scr_softc* sc,int state,int cmd,int line)
3860{ 3862{
3861 printf("INVALID_STATE_CMD: sc = %X, state = %X, cmd = %X, line = %d\n",sc,state,cmd,line); 3863 printf("INVALID_STATE_CMD: sc = %X, state = %X, cmd = %X, line = %d\n",sc,state,cmd,line);
3862 DEBUGGER; 3864 DEBUGGER;
3863} 3865}
3864 3866
3865/* 3867/*
3866**++ 3868**++
3867** FUNCTIONAL DESCRIPTION: 3869** FUNCTIONAL DESCRIPTION:
3868** 3870**
3869** getText 3871** getText
3870** 3872**
3871** Get text representation of state or command 3873** Get text representation of state or command
3872** 3874**
3873** FORMAL PARAMETERS: 3875** FORMAL PARAMETERS:
3874** 3876**
3875** x - state or command 3877** x - state or command
3876** 3878**
3877** IMPLICIT INPUTS: 3879** IMPLICIT INPUTS:
3878** 3880**
3879** nill 3881** nill
3880** 3882**
3881** IMPLICIT OUTPUTS: 3883** IMPLICIT OUTPUTS:
3882** 3884**
3883** nill 3885** nill
3884** 3886**
3885** FUNCTION VALUE: 3887** FUNCTION VALUE:
3886** 3888**
3887** nill 3889** nill
3888** 3890**
3889** SIDE EFFECTS: 3891** SIDE EFFECTS:
3890** 3892**
3891** nill 3893** nill
3892**-- 3894**--
3893*/ 3895*/
3894char * getText(int x) 3896char * getText(int x)
3895{ 3897{
3896 switch (x) 3898 switch (x)
3897 { 3899 {
3898 /* commands to Master State Machine (mc = Master Command )*/ 3900 /* commands to Master State Machine (mc = Master Command )*/
3899 case mcOn: return "mcOn"; 3901 case mcOn: return "mcOn";
3900 case mcT0DataSend: return "mcT0DataSend"; 3902 case mcT0DataSend: return "mcT0DataSend";
3901 case mcT0DataRecv: return "mcT0DataRecv"; 3903 case mcT0DataRecv: return "mcT0DataRecv";
3902 case mcColdReset: return "mcColdReset"; 3904 case mcColdReset: return "mcColdReset";
3903 case mcATR: return "mcATR"; 3905 case mcATR: return "mcATR";
3904 case mcT0Send: return "mcT0Send"; 3906 case mcT0Send: return "mcT0Send";
3905 case mcT0Recv: return "mcT0Recv"; 3907 case mcT0Recv: return "mcT0Recv";
3906 3908
3907 /* states in Master state machine (ms = Master State) */ 3909 /* states in Master state machine (ms = Master State) */
3908 case msIdleOff: return "msIdleOff"; 3910 case msIdleOff: return "msIdleOff";
3909 case msColdReset: return "msColdReset"; 3911 case msColdReset: return "msColdReset";
3910 case msATR: return "msATR"; 3912 case msATR: return "msATR";
3911 case msIdleOn: return "msIdleOn"; 3913 case msIdleOn: return "msIdleOn";
3912 case msT0Send: return "msT0Send"; 3914 case msT0Send: return "msT0Send";
3913 case msT0Recv: return "msT0Recv"; 3915 case msT0Recv: return "msT0Recv";
3914 3916
3915 3917
3916 3918
3917 /* commands to T0 send state machine */ 3919 /* commands to T0 send state machine */
3918 case t0scStart: return "t0scStart"; 3920 case t0scStart: return "t0scStart";
3919 case t0scTWorkWaiting: return "t0scTWorkWaiting"; 3921 case t0scTWorkWaiting: return "t0scTWorkWaiting";
3920 3922
3921 3923
3922 /* states in T0 send state machine */ 3924 /* states in T0 send state machine */
3923 case t0ssIdle: return "t0ssIdle"; 3925 case t0ssIdle: return "t0ssIdle";
3924 case t0ssSendHeader: return "t0ssSendHeader"; 3926 case t0ssSendHeader: return "t0ssSendHeader";
3925 case t0ssRecvProcedure: return "t0ssRecvProcedu"; 3927 case t0ssRecvProcedure: return "t0ssRecvProcedu";
3926 case t0ssSendByte: return "t0ssSendByte"; 3928 case t0ssSendByte: return "t0ssSendByte";
3927 case t0ssSendData: return "t0ssSendData"; 3929 case t0ssSendData: return "t0ssSendData";
3928 case t0ssRecvSW1: return "t0ssRecvSW1"; 3930 case t0ssRecvSW1: return "t0ssRecvSW1";
3929 case t0ssRecvSW2: return "t0ssRecvSW2"; 3931 case t0ssRecvSW2: return "t0ssRecvSW2";
3930 3932
3931 3933
3932 /* commands to T0 recv state machine */ 3934 /* commands to T0 recv state machine */
3933 case t0rcStart: return "t0rcStart"; 3935 case t0rcStart: return "t0rcStart";
3934 case t0rcTWorkWaiting: return "t0rcTWorkWaiting"; 3936 case t0rcTWorkWaiting: return "t0rcTWorkWaiting";
3935 3937
3936 /* states in T0 recv state machine */ 3938 /* states in T0 recv state machine */
3937 case t0rsIdle: return "t0rsIdle"; 3939 case t0rsIdle: return "t0rsIdle";
3938 case t0rsSendHeader: return "t0rsSendHeader"; 3940 case t0rsSendHeader: return "t0rsSendHeader";
3939 case t0rsRecvProcedure: return "t0rsRecvProcedure"; 3941 case t0rsRecvProcedure: return "t0rsRecvProcedure";
3940 case t0rsRecvByte: return "t0rsRecvByte"; 3942 case t0rsRecvByte: return "t0rsRecvByte";
3941 case t0rsRecvData: return "t0rsRecvData"; 3943 case t0rsRecvData: return "t0rsRecvData";
3942 case t0rsRecvSW1: return "t0rsRecvSW1"; 3944 case t0rsRecvSW1: return "t0rsRecvSW1";
3943 case t0rsRecvSW2: return "t0rsRecvSW2"; 3945 case t0rsRecvSW2: return "t0rsRecvSW2";
3944 3946
3945 3947
3946 3948
3947 3949
3948 3950
3949 /* commands to Answer To Reset (ATR) state machine */ 3951 /* commands to Answer To Reset (ATR) state machine */
3950 case atrcStart: return "atrcStart"; 3952 case atrcStart: return "atrcStart";
3951 case atrcT3: return "0x0b04"; 3953 case atrcT3: return "0x0b04";
3952 case atrcTWorkWaiting: return "atrcTWorkWaiting"; 3954 case atrcTWorkWaiting: return "atrcTWorkWaiting";
3953 3955
3954 3956
3955 /* states in in Anser To Reset (ATR) state machine */ 3957 /* states in in Anser To Reset (ATR) state machine */
3956 case atrsIdle: return "atrsIdle"; 3958 case atrsIdle: return "atrsIdle";
3957 case atrsTS: return "atrsTS"; 3959 case atrsTS: return "atrsTS";
3958 case atrsT0: return "atrsT0"; 3960 case atrsT0: return "atrsT0";
3959 case atrsTABCD: return "atrsTABCD"; 3961 case atrsTABCD: return "atrsTABCD";
3960 case atrsTK: return "atrsTK"; 3962 case atrsTK: return "atrsTK";
3961 case atrsTCK: return "atrsTCK"; 3963 case atrsTCK: return "atrsTCK";
3962 3964
3963 3965
3964 3966
3965 /* commands to T0 Recv Byte state machine */ 3967 /* commands to T0 Recv Byte state machine */
3966 case t0rbcStart: return "t0rbcStart"; 3968 case t0rbcStart: return "t0rbcStart";
3967 case t0rbcAbort: return "t0rbcAbort"; 3969 case t0rbcAbort: return "t0rbcAbort";
3968 3970
3969 case t0rbcTFindStartEdge:return "t0rbcTFindStartEdge"; 3971 case t0rbcTFindStartEdge:return "t0rbcTFindStartEdge";
3970 case t0rbcTFindStartMid: return "t0rbcTFindStartMid"; 3972 case t0rbcTFindStartMid: return "t0rbcTFindStartMid";
3971 case t0rbcTClockData: return "t0rbcTClockData"; 3973 case t0rbcTClockData: return "t0rbcTClockData";
3972 case t0rbcTErrorStart: return "t0rbcTErrorStart"; 3974 case t0rbcTErrorStart: return "t0rbcTErrorStart";
3973 case t0rbcTErrorStop: return "t0rbcTErrorStop"; 3975 case t0rbcTErrorStop: return "t0rbcTErrorStop";
3974 3976
3975 /* states in in TO Recv Byte state machine */ 3977 /* states in in TO Recv Byte state machine */
3976 case t0rbsIdle: return "t0rbsIdle"; 3978 case t0rbsIdle: return "t0rbsIdle";
3977 case t0rbsFindStartEdge: return "t0rbcFindStartEdge";  3979 case t0rbsFindStartEdge: return "t0rbcFindStartEdge";
3978 case t0rbsFindStartMid: return "t0rbcFindStartMid";  3980 case t0rbsFindStartMid: return "t0rbcFindStartMid";
3979 case t0rbsClockData: return "t0rbcClockData";  3981 case t0rbsClockData: return "t0rbcClockData";
3980 case t0rbsSendError: return "t0rbcSendError";  3982 case t0rbsSendError: return "t0rbcSendError";
3981 3983
3982 3984
3983 /* commands to T0 Send Byte state machine */ 3985 /* commands to T0 Send Byte state machine */
3984 case t0sbcStart: return "t0sbcStart"; 3986 case t0sbcStart: return "t0sbcStart";
3985 case t0sbcAbort: return "t0sbcAbort"; 3987 case t0sbcAbort: return "t0sbcAbort";
3986 case t0sbcTGuardTime: return "t0sbcTGuardTime"; 3988 case t0sbcTGuardTime: return "t0sbcTGuardTime";
3987 case t0sbcTClockData: return "t0sbcTClockData"; 3989 case t0sbcTClockData: return "t0sbcTClockData";
3988 case t0sbcTError: return "t0sbcTError"; 3990 case t0sbcTError: return "t0sbcTError";
3989 case t0sbcTResend: return "t0sbcTResend"; 3991 case t0sbcTResend: return "t0sbcTResend";
3990 3992
3991 /* states in in T0 Send Byte state machine */ 3993 /* states in in T0 Send Byte state machine */
3992 case t0sbsIdle: return "t0sbsIdle"; 3994 case t0sbsIdle: return "t0sbsIdle";
3993 case t0sbsClockData: return "t0sbsClockData"; 3995 case t0sbsClockData: return "t0sbsClockData";
3994 case t0sbsWaitError: return "t0sbsWaitError"; 3996 case t0sbsWaitError: return "t0sbsWaitError";
3995 case t0sbsWaitResend: return "t0sbsWaitResend"; 3997 case t0sbsWaitResend: return "t0sbsWaitResend";
3996 case t0sbsWaitGuardTime: return "t0sbsWaitGuardTime"; 3998 case t0sbsWaitGuardTime: return "t0sbsWaitGuardTime";
3997 3999
3998 4000
3999 case gcT0RecvByte: return "gcT0RecvByte"; 4001 case gcT0RecvByte: return "gcT0RecvByte";
4000 case gcT0RecvByteErr: return "gcT0RecvByteErr"; 4002 case gcT0RecvByteErr: return "gcT0RecvByteErr";
4001 case gcT0SendByte: return "gcT0SendByte"; 4003 case gcT0SendByte: return "gcT0SendByte";
4002 case gcT0SendByteErr: return "gcT0SendByteErr"; 4004 case gcT0SendByteErr: return "gcT0SendByteErr";
4003 4005
4004 4006
4005 case crcStart: return "crcStart"; 4007 case crcStart: return "crcStart";
4006 case crcT2: return "crcT2"; 4008 case crcT2: return "crcT2";
4007 4009
4008 4010
4009 default: 4011 default:
4010 printf("unknown case, %x\n",x); 4012 printf("unknown case, %x\n",x);
4011 break; 4013 break;
4012 } 4014 }
4013 return "???"; 4015 return "???";
4014} 4016}
4015 4017
4016#endif /* SCR_DEBUG */ 4018#endif /* SCR_DEBUG */
4017 4019
4018 4020
4019 4021