1 /*-
2 * Copyright (c) 2006 Oleksandr Tymoshenko.
3 * Copyright (c) KATO Takenori, 1999.
4 *
5 * All rights reserved. Unpublished rights reserved under the copyright
6 * laws of Japan.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer as
14 * the first lines of this file unmodified.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * $FreeBSD: releng/8.0/sys/mips/include/bus_octeon.h 178172 2008-04-13 07:27:37Z imp $
33 */
34
35 /* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */
36
37 /*-
38 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
39 * All rights reserved.
40 *
41 * This code is derived from software contributed to The NetBSD Foundation
42 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
43 * NASA Ames Research Center.
44 *
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
47 * are met:
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by the NetBSD
56 * Foundation, Inc. and its contributors.
57 * 4. Neither the name of The NetBSD Foundation nor the names of its
58 * contributors may be used to endorse or promote products derived
59 * from this software without specific prior written permission.
60 *
61 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
62 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
63 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
64 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
65 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
66 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
67 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
68 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
69 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
70 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
71 * POSSIBILITY OF SUCH DAMAGE.
72 */
73
74 /*-
75 * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
76 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
77 *
78 * Redistribution and use in source and binary forms, with or without
79 * modification, are permitted provided that the following conditions
80 * are met:
81 * 1. Redistributions of source code must retain the above copyright
82 * notice, this list of conditions and the following disclaimer.
83 * 2. Redistributions in binary form must reproduce the above copyright
84 * notice, this list of conditions and the following disclaimer in the
85 * documentation and/or other materials provided with the distribution.
86 * 3. All advertising materials mentioning features or use of this software
87 * must display the following acknowledgement:
88 * This product includes software developed by Christopher G. Demetriou
89 * for the NetBSD Project.
90 * 4. The name of the author may not be used to endorse or promote products
91 * derived from this software without specific prior written permission
92 *
93 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
94 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
95 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
96 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
97 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
99 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
100 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
101 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
102 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
103 */
104
105 #ifndef _MIPS_BUS_OCTEON_H_
106 #define _MIPS_BUS_OCTEON_H_
107
108 #include "../../mips32/octeon32/octeon_pcmap_regs.h"
109 #include <machine/_bus_octeon.h>
110 #include <machine/cpufunc.h>
111
112 /*
113 * Values for the mips64 bus space tag, not to be used directly by MI code.
114 */
115 #define MIPS_BUS_SPACE_IO 0 /* space is i/o space */
116 #define MIPS_BUS_SPACE_MEM 1 /* space is mem space */
117
118 #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
119 #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
120 #define BUS_SPACE_MAXSIZE 0xFFFFFFFF
121 #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
122 #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
123 #define BUS_SPACE_MAXADDR 0xFFFFFFFF
124
125 #define BUS_SPACE_UNRESTRICTED (~0)
126
127 /*
128 * Map a region of device bus space into CPU virtual address space.
129 */
130
131 static __inline int bus_space_map(bus_space_tag_t t, bus_addr_t addr,
132 bus_size_t size, int flags,
133 bus_space_handle_t *bshp);
134
135 static __inline int
136 bus_space_map(bus_space_tag_t t __unused, bus_addr_t addr,
137 bus_size_t size __unused, int flags __unused,
138 bus_space_handle_t *bshp)
139 {
140
141 *bshp = addr;
142 return (0);
143 }
144
145 /*
146 * Unmap a region of device bus space.
147 */
148
149 static __inline void bus_space_unmap(bus_space_tag_t t, bus_space_handle_t bsh,
150 bus_size_t size);
151
152 static __inline void
153 bus_space_unmap(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused,
154 bus_size_t size __unused)
155 {
156 }
157
158 /*
159 * Get a new handle for a subregion of an already-mapped area of bus space.
160 */
161
162 static __inline int bus_space_subregion(bus_space_tag_t t,
163 bus_space_handle_t bsh,
164 bus_size_t offset, bus_size_t size,
165 bus_space_handle_t *nbshp);
166
167 static __inline int
168 bus_space_subregion(bus_space_tag_t t __unused, bus_space_handle_t bsh,
169 bus_size_t offset, bus_size_t size __unused,
170 bus_space_handle_t *nbshp)
171 {
172 *nbshp = bsh + offset;
173 return (0);
174 }
175
176 /*
177 * Allocate a region of memory that is accessible to devices in bus space.
178 */
179
180 int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
181 bus_addr_t rend, bus_size_t size, bus_size_t align,
182 bus_size_t boundary, int flags, bus_addr_t *addrp,
183 bus_space_handle_t *bshp);
184
185 /*
186 * Free a region of bus space accessible memory.
187 */
188
189 static __inline void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
190 bus_size_t size);
191
192 static __inline void
193 bus_space_free(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused,
194 bus_size_t size __unused)
195 {
196 }
197
198
199 /*
200 * Read a 1, 2, 4, or 8 byte quantity from bus space
201 * described by tag/handle/offset.
202 */
203 static __inline u_int8_t bus_space_read_1(bus_space_tag_t tag,
204 bus_space_handle_t handle,
205 bus_size_t offset);
206
207 static __inline u_int16_t bus_space_read_2(bus_space_tag_t tag,
208 bus_space_handle_t handle,
209 bus_size_t offset);
210
211 static __inline u_int32_t bus_space_read_4(bus_space_tag_t tag,
212 bus_space_handle_t handle,
213 bus_size_t offset);
214
215 static __inline u_int8_t
216 bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle,
217 bus_size_t offset)
218 {
219 uint64_t ret_val;
220 uint64_t oct64_addr;
221
222 oct64_addr = handle + offset;
223 ret_val = oct_read8(oct64_addr);
224 return ((u_int8_t) ret_val);
225 }
226
227 static __inline u_int16_t
228 bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle,
229 bus_size_t offset)
230 {
231 uint64_t ret_val;
232 uint64_t oct64_addr;
233
234 oct64_addr = handle + offset;
235 ret_val = oct_read16(oct64_addr);
236 return ((u_int16_t) ret_val);
237 }
238
239 static __inline u_int32_t
240 bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle,
241 bus_size_t offset)
242 {
243 uint64_t ret_val;
244 uint64_t oct64_addr;
245
246 oct64_addr = handle + offset;
247 ret_val = oct_read32(oct64_addr);
248 return ((u_int32_t) ret_val);
249 }
250
251
252 static __inline u_int64_t
253 bus_space_read_8(bus_space_tag_t tag, bus_space_handle_t handle,
254 bus_size_t offset)
255 {
256 uint64_t ret_val;
257 uint64_t oct64_addr;
258
259 oct64_addr = handle + offset;
260 ret_val = oct_read64(oct64_addr);
261 return (ret_val);
262 }
263
264
265 /*
266 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
267 * described by tag/handle/offset and copy into buffer provided.
268 */
269 static __inline void bus_space_read_region_1(bus_space_tag_t tag,
270 bus_space_handle_t bsh,
271 bus_size_t offset, u_int8_t *addr,
272 size_t count);
273
274 static __inline void bus_space_read_region_2(bus_space_tag_t tag,
275 bus_space_handle_t bsh,
276 bus_size_t offset, u_int16_t *addr,
277 size_t count);
278
279 static __inline void bus_space_read_region_4(bus_space_tag_t tag,
280 bus_space_handle_t bsh,
281 bus_size_t offset, u_int32_t *addr,
282 size_t count);
283
284 static __inline void
285 bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
286 bus_size_t offset, u_int8_t *addr, size_t count)
287 {
288 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
289
290 for(; count > 0; count--, addr++, ptr++) {
291 *addr = oct_read8(ptr);
292 }
293 }
294
295 static __inline void
296 bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
297 bus_size_t offset, u_int16_t *addr, size_t count)
298 {
299 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
300
301 for(; count > 0; count--, addr++, ptr+=2) {
302 *addr = oct_read16(ptr);
303 }
304 }
305
306 static __inline void
307 bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
308 bus_size_t offset, u_int32_t *addr, size_t count)
309 {
310 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
311
312 for(; count > 0; count--, addr++, ptr+=4) {
313 *addr = oct_read32(ptr);
314 }
315 }
316
317 static __inline void
318 bus_space_read_region_8(bus_space_tag_t tag, bus_space_handle_t bsh,
319 bus_size_t offset, u_int64_t *addr, size_t count)
320 {
321 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
322
323 for(; count > 0; count--, addr++, ptr+=4) {
324 *addr = oct_read64(ptr);
325 }
326 }
327
328 /*
329 * Read `count' 1, 2, 4, or 8 byte quantities from bus space
330 * described by tag/handle and starting at `offset' and copy into
331 * buffer provided.
332 */
333 static __inline void bus_space_read_multi_1(bus_space_tag_t tag,
334 bus_space_handle_t bsh,
335 bus_size_t offset, u_int8_t *addr,
336 size_t count);
337
338 static __inline void bus_space_read_multi_2(bus_space_tag_t tag,
339 bus_space_handle_t bsh,
340 bus_size_t offset, u_int16_t *addr,
341 size_t count);
342
343 static __inline void bus_space_read_multi_4(bus_space_tag_t tag,
344 bus_space_handle_t bsh,
345 bus_size_t offset, u_int32_t *addr,
346 size_t count);
347
348
349 static __inline void
350 bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
351 bus_size_t offset, u_int8_t *addr, size_t count)
352 {
353 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
354
355 for(; count > 0; count--, addr++) {
356 *addr = oct_read8(ptr);
357 }
358 }
359
360 static __inline void
361 bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
362 bus_size_t offset, u_int16_t *addr, size_t count)
363 {
364 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
365
366 for(; count > 0; count--, addr++) {
367 *addr = oct_read16(ptr);
368 }
369 }
370
371 static __inline void
372 bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
373 bus_size_t offset, u_int32_t *addr, size_t count)
374 {
375 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
376
377 for(; count > 0; count--, addr++) {
378 *addr = oct_read32(ptr);
379 }
380 }
381
382 static __inline void
383 bus_space_read_multi_8(bus_space_tag_t tag, bus_space_handle_t bsh,
384 bus_size_t offset, u_int64_t *addr, size_t count)
385 {
386 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
387
388 for(; count > 0; count--, addr++) {
389 *addr = oct_read64(ptr);
390 }
391 }
392
393
394 /*
395 * Write the 1, 2, 4, or 8 byte value `value' to bus space
396 * described by tag/handle/offset.
397 */
398
399 static __inline void bus_space_write_1(bus_space_tag_t tag,
400 bus_space_handle_t bsh,
401 bus_size_t offset, u_int8_t value);
402
403 static __inline void bus_space_write_2(bus_space_tag_t tag,
404 bus_space_handle_t bsh,
405 bus_size_t offset, u_int16_t value);
406
407 static __inline void bus_space_write_4(bus_space_tag_t tag,
408 bus_space_handle_t bsh,
409 bus_size_t offset, u_int32_t value);
410
411 static __inline void
412 bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh,
413 bus_size_t offset, u_int8_t value)
414 {
415 oct_write8(bsh+offset, value);
416 }
417
418 static __inline void
419 bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t bsh,
420 bus_size_t offset, u_int16_t value)
421 {
422 oct_write16(bsh+offset, value);
423 }
424
425 static __inline void
426 bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh,
427 bus_size_t offset, u_int32_t value)
428 {
429 oct_write32(bsh+offset, value);
430 }
431
432 static __inline void
433 bus_space_write_8(bus_space_tag_t tag, bus_space_handle_t bsh,
434 bus_size_t offset, u_int64_t value)
435 {
436 oct_write64(bsh+offset, value);
437 }
438
439 /*
440 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
441 * provided to bus space described by tag/handle/offset.
442 */
443
444 static __inline void bus_space_write_region_1(bus_space_tag_t tag,
445 bus_space_handle_t bsh,
446 bus_size_t offset,
447 const u_int8_t *addr,
448 size_t count);
449 static __inline void bus_space_write_region_2(bus_space_tag_t tag,
450 bus_space_handle_t bsh,
451 bus_size_t offset,
452 const u_int16_t *addr,
453 size_t count);
454
455 static __inline void bus_space_write_region_4(bus_space_tag_t tag,
456 bus_space_handle_t bsh,
457 bus_size_t offset,
458 const u_int32_t *addr,
459 size_t count);
460
461 static __inline void
462 bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
463 bus_size_t offset, const u_int8_t *addr, size_t count)
464 {
465 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
466
467 for(; count > 0; count--, addr++, ptr++) {
468 oct_write8(ptr, *addr);
469 }
470 }
471
472 static __inline void
473 bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
474 bus_size_t offset, const u_int16_t *addr, size_t count)
475 {
476 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
477
478 for(; count > 0; count--, addr++, ptr++) {
479 oct_write16(ptr, *addr);
480 }
481 }
482
483 static __inline void
484 bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
485 bus_size_t offset, const u_int32_t *addr, size_t count)
486 {
487 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
488
489 for(; count > 0; count--, addr++, ptr++) {
490 oct_write32(ptr, *addr);
491 }
492 }
493
494 static __inline void
495 bus_space_write_region_8(bus_space_tag_t tag, bus_space_handle_t bsh,
496 bus_size_t offset, const u_int64_t *addr, size_t count)
497 {
498 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
499
500 for(; count > 0; count--, addr++, ptr++) {
501 oct_write64(ptr, *addr);
502 }
503 }
504
505 /*
506 * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
507 * to bus space described by tag/handle starting at `offset'.
508 */
509
510 static __inline void bus_space_write_multi_1(bus_space_tag_t tag,
511 bus_space_handle_t bsh,
512 bus_size_t offset,
513 const u_int8_t *addr,
514 size_t count);
515 static __inline void bus_space_write_multi_2(bus_space_tag_t tag,
516 bus_space_handle_t bsh,
517 bus_size_t offset,
518 const u_int16_t *addr,
519 size_t count);
520 static __inline void bus_space_write_multi_4(bus_space_tag_t tag,
521 bus_space_handle_t bsh,
522 bus_size_t offset,
523 const u_int32_t *addr,
524 size_t count);
525
526 static __inline void
527 bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
528 bus_size_t offset, const u_int8_t *addr, size_t count)
529 {
530 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
531
532 for(; count > 0; count--, addr++) {
533 oct_write8(ptr, *addr);
534 }
535 }
536
537 static __inline void
538 bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
539 bus_size_t offset, const u_int16_t *addr, size_t count)
540 {
541 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
542
543 for(; count > 0; count--, addr++) {
544 oct_write16(ptr, *addr);
545 }
546 }
547
548 static __inline void
549 bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
550 bus_size_t offset, const u_int32_t *addr, size_t count)
551 {
552 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
553
554 for(; count > 0; count--, addr++) {
555 oct_write32(ptr, *addr);
556 }
557 }
558
559 static __inline void
560 bus_space_write_multi_8(bus_space_tag_t tag, bus_space_handle_t bsh,
561 bus_size_t offset, const u_int64_t *addr, size_t count)
562 {
563 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
564
565 for(; count > 0; count--, addr++) {
566 oct_write64(ptr, *addr);
567 }
568 }
569
570 /*
571 * Write the 1, 2, 4, or 8 byte value `val' to bus space described
572 * by tag/handle/offset `count' times.
573 */
574
575 static __inline void bus_space_set_multi_1(bus_space_tag_t tag,
576 bus_space_handle_t bsh,
577 bus_size_t offset,
578 u_int8_t value, size_t count);
579 static __inline void bus_space_set_multi_2(bus_space_tag_t tag,
580 bus_space_handle_t bsh,
581 bus_size_t offset,
582 u_int16_t value, size_t count);
583 static __inline void bus_space_set_multi_4(bus_space_tag_t tag,
584 bus_space_handle_t bsh,
585 bus_size_t offset,
586 u_int32_t value, size_t count);
587
588 static __inline void
589 bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
590 bus_size_t offset, u_int8_t value, size_t count)
591 {
592 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
593
594 for(; count > 0; count--) {
595 oct_write8(ptr, value);
596 }
597 }
598
599 static __inline void
600 bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
601 bus_size_t offset, u_int16_t value, size_t count)
602 {
603 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
604
605 for(; count > 0; count--) {
606 oct_write16(ptr, value);
607 }
608 }
609
610 static __inline void
611 bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
612 bus_size_t offset, u_int32_t value, size_t count)
613 {
614 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
615
616 for(; count > 0; count--) {
617 oct_write32(ptr, value);
618 }
619 }
620
621 static __inline void
622 bus_space_set_multi_8(bus_space_tag_t tag, bus_space_handle_t bsh,
623 bus_size_t offset, u_int64_t value, size_t count)
624 {
625 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
626
627 for(; count > 0; count--) {
628 oct_write64(ptr, value);
629 }
630 }
631
632 /*
633 * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
634 * by tag/handle starting at `offset'.
635 */
636
637 static __inline void bus_space_set_region_1(bus_space_tag_t tag,
638 bus_space_handle_t bsh,
639 bus_size_t offset, u_int8_t value,
640 size_t count);
641 static __inline void bus_space_set_region_2(bus_space_tag_t tag,
642 bus_space_handle_t bsh,
643 bus_size_t offset, u_int16_t value,
644 size_t count);
645 static __inline void bus_space_set_region_4(bus_space_tag_t tag,
646 bus_space_handle_t bsh,
647 bus_size_t offset, u_int32_t value,
648 size_t count);
649
650 static __inline void
651 bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
652 bus_size_t offset, u_int8_t value, size_t count)
653 {
654 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
655
656 for(; count > 0; count--, ptr++) {
657 oct_write8(ptr, value);
658 }
659 }
660
661 static __inline void
662 bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
663 bus_size_t offset, u_int16_t value, size_t count)
664 {
665 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
666
667 for(; count > 0; count--, ptr++) {
668 oct_write16(ptr, value);
669 }
670 }
671
672 static __inline void
673 bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
674 bus_size_t offset, u_int32_t value, size_t count)
675 {
676 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
677
678 for(; count > 0; count--, ptr++) {
679 oct_write32(ptr, value);
680 }
681 }
682
683 static __inline void
684 bus_space_set_region_8(bus_space_tag_t tag, bus_space_handle_t bsh,
685 bus_size_t offset, u_int64_t value, size_t count)
686 {
687 uint64_t ptr = ((uint64_t) bsh + (uint64_t) offset);
688
689 for(; count > 0; count--, ptr++) {
690 oct_write64(ptr, value);
691 }
692 }
693
694 /*
695 * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
696 * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
697 */
698
699 static __inline void bus_space_copy_region_1(bus_space_tag_t tag,
700 bus_space_handle_t bsh1,
701 bus_size_t off1,
702 bus_space_handle_t bsh2,
703 bus_size_t off2, size_t count);
704
705 static __inline void bus_space_copy_region_2(bus_space_tag_t tag,
706 bus_space_handle_t bsh1,
707 bus_size_t off1,
708 bus_space_handle_t bsh2,
709 bus_size_t off2, size_t count);
710
711 static __inline void bus_space_copy_region_4(bus_space_tag_t tag,
712 bus_space_handle_t bsh1,
713 bus_size_t off1,
714 bus_space_handle_t bsh2,
715 bus_size_t off2, size_t count);
716
717 static __inline void
718 bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsh1,
719 bus_size_t off1, bus_space_handle_t bsh2,
720 bus_size_t off2, size_t count)
721 {
722 uint64_t ptr1 = ((uint64_t) bsh1 + (uint64_t) off1);
723 uint64_t ptr2 = ((uint64_t) bsh2 + (uint64_t) off2);
724 uint8_t val;
725
726 for(; count > 0; count--, ptr1++, ptr2++) {
727 val = oct_read8(ptr1);
728 oct_write8(ptr2, val);
729 }
730 }
731
732 static __inline void
733 bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsh1,
734 bus_size_t off1, bus_space_handle_t bsh2,
735 bus_size_t off2, size_t count)
736 {
737 uint64_t ptr1 = ((uint64_t) bsh1 + (uint64_t) off1);
738 uint64_t ptr2 = ((uint64_t) bsh2 + (uint64_t) off2);
739 uint16_t val;
740
741 for(; count > 0; count--, ptr1++, ptr2++) {
742 val = oct_read16(ptr1);
743 oct_write16(ptr2, val);
744 }
745 }
746
747 static __inline void
748 bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1,
749 bus_size_t off1, bus_space_handle_t bsh2,
750 bus_size_t off2, size_t count)
751 {
752 uint64_t ptr1 = ((uint64_t) bsh1 + (uint64_t) off1);
753 uint64_t ptr2 = ((uint64_t) bsh2 + (uint64_t) off2);
754 uint32_t val;
755
756 for(; count > 0; count--, ptr1++, ptr2++) {
757 val = oct_read32(ptr1);
758 oct_write32(ptr2, val);
759 }
760 }
761
762 static __inline void
763 bus_space_copy_region_8(bus_space_tag_t tag, bus_space_handle_t bsh1,
764 bus_size_t off1, bus_space_handle_t bsh2,
765 bus_size_t off2, size_t count)
766 {
767 uint64_t ptr1 = ((uint64_t) bsh1 + (uint64_t) off1);
768 uint64_t ptr2 = ((uint64_t) bsh2 + (uint64_t) off2);
769 uint64_t val;
770
771 for(; count > 0; count--, ptr1++, ptr2++) {
772 val = oct_read64(ptr1);
773 oct_write64(ptr2, val);
774 }
775 }
776
777 /*
778 * Bus read/write barrier methods.
779 *
780 * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
781 * bus_size_t offset, bus_size_t len, int flags);
782 *
783 *
784 * Note that BUS_SPACE_BARRIER_WRITE doesn't do anything other than
785 * prevent reordering by the compiler; all Intel x86 processors currently
786 * retire operations outside the CPU in program order.
787 */
788 #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
789 #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
790
791 static __inline void
792 bus_space_barrier(bus_space_tag_t tag __unused, bus_space_handle_t bsh __unused,
793 bus_size_t offset __unused, bus_size_t len __unused, int flags)
794 {
795 #if 0
796 #ifdef __GNUCLIKE_ASM
797 if (flags & BUS_SPACE_BARRIER_READ)
798 __asm __volatile("lock; addl $0,0(%%rsp)" : : : "memory");
799 else
800 __asm __volatile("" : : : "memory");
801 #endif
802 #endif
803 oct_read64(OCTEON_MIO_BOOT_BIST_STAT);
804 }
805
806 #ifdef BUS_SPACE_NO_LEGACY
807 #undef inb
808 #undef outb
809 #define inb(a) compiler_error
810 #define inw(a) compiler_error
811 #define inl(a) compiler_error
812 #define outb(a, b) compiler_error
813 #define outw(a, b) compiler_error
814 #define outl(a, b) compiler_error
815 #endif
816
817 #include <machine/bus_dma.h>
818
819 /*
820 * Stream accesses are the same as normal accesses on amd64; there are no
821 * supported bus systems with an endianess different from the host one.
822 */
823 #define bus_space_read_stream_1(t, h, o) bus_space_read_1((t), (h), (o))
824 #define bus_space_read_stream_2(t, h, o) bus_space_read_2((t), (h), (o))
825 #define bus_space_read_stream_4(t, h, o) bus_space_read_4((t), (h), (o))
826
827 #define bus_space_read_multi_stream_1(t, h, o, a, c) \
828 bus_space_read_multi_1((t), (h), (o), (a), (c))
829 #define bus_space_read_multi_stream_2(t, h, o, a, c) \
830 bus_space_read_multi_2((t), (h), (o), (a), (c))
831 #define bus_space_read_multi_stream_4(t, h, o, a, c) \
832 bus_space_read_multi_4((t), (h), (o), (a), (c))
833
834 #define bus_space_write_stream_1(t, h, o, v) \
835 bus_space_write_1((t), (h), (o), (v))
836 #define bus_space_write_stream_2(t, h, o, v) \
837 bus_space_write_2((t), (h), (o), (v))
838 #define bus_space_write_stream_4(t, h, o, v) \
839 bus_space_write_4((t), (h), (o), (v))
840
841 #define bus_space_write_multi_stream_1(t, h, o, a, c) \
842 bus_space_write_multi_1((t), (h), (o), (a), (c))
843 #define bus_space_write_multi_stream_2(t, h, o, a, c) \
844 bus_space_write_multi_2((t), (h), (o), (a), (c))
845 #define bus_space_write_multi_stream_4(t, h, o, a, c) \
846 bus_space_write_multi_4((t), (h), (o), (a), (c))
847
848 #define bus_space_set_multi_stream_1(t, h, o, v, c) \
849 bus_space_set_multi_1((t), (h), (o), (v), (c))
850 #define bus_space_set_multi_stream_2(t, h, o, v, c) \
851 bus_space_set_multi_2((t), (h), (o), (v), (c))
852 #define bus_space_set_multi_stream_4(t, h, o, v, c) \
853 bus_space_set_multi_4((t), (h), (o), (v), (c))
854
855 #define bus_space_read_region_stream_1(t, h, o, a, c) \
856 bus_space_read_region_1((t), (h), (o), (a), (c))
857 #define bus_space_read_region_stream_2(t, h, o, a, c) \
858 bus_space_read_region_2((t), (h), (o), (a), (c))
859 #define bus_space_read_region_stream_4(t, h, o, a, c) \
860 bus_space_read_region_4((t), (h), (o), (a), (c))
861
862 #define bus_space_write_region_stream_1(t, h, o, a, c) \
863 bus_space_write_region_1((t), (h), (o), (a), (c))
864 #define bus_space_write_region_stream_2(t, h, o, a, c) \
865 bus_space_write_region_2((t), (h), (o), (a), (c))
866 #define bus_space_write_region_stream_4(t, h, o, a, c) \
867 bus_space_write_region_4((t), (h), (o), (a), (c))
868
869 #define bus_space_set_region_stream_1(t, h, o, v, c) \
870 bus_space_set_region_1((t), (h), (o), (v), (c))
871 #define bus_space_set_region_stream_2(t, h, o, v, c) \
872 bus_space_set_region_2((t), (h), (o), (v), (c))
873 #define bus_space_set_region_stream_4(t, h, o, v, c) \
874 bus_space_set_region_4((t), (h), (o), (v), (c))
875
876 #define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \
877 bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
878 #define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \
879 bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c))
880 #define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \
881 bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c))
882
883 #endif /* _MIPS_BUS_OCTEON_H_ */
Cache object: dae0ce1ca3fac62fec24cdfb6a2f99c7
|