source: rtems-libbsd/rtemsbsd/include/machine/bus.h @ f0aaa04

55-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since f0aaa04 was b168f69, checked in by Sebastian Huber <sebastian.huber@…>, on 09/29/15 at 09:00:58

BUS_SPACE(9): Use FreeBSD files for i386 arch

  • Property mode set to 100644
File size: 23.8 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup rtems_bsd_machine
5 *
6 * @brief TODO.
7 *
8 * File origin from FreeBSD 'sys/amd64/include/bus.h'.
9 */
10
11/*-
12 * Copyright (c) 2009, 2015 embedded brains GmbH.  All rights reserved.
13 *
14 *  embedded brains GmbH
15 *  Dornierstr. 4
16 *  82178 Puchheim
17 *  Germany
18 *  <rtems@embedded-brains.de>
19 *
20 * Copyright (c) KATO Takenori, 1999.
21 *
22 * All rights reserved.  Unpublished rights reserved under the copyright
23 * laws of Japan.
24 *
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
27 * are met:
28 *
29 * 1. Redistributions of source code must retain the above copyright
30 *    notice, this list of conditions and the following disclaimer as
31 *    the first lines of this file unmodified.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 *    notice, this list of conditions and the following disclaimer in the
34 *    documentation and/or other materials provided with the distribution.
35 * 3. The name of the author may not be used to endorse or promote products
36 *    derived from this software without specific prior written permission.
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
39 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
41 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
42 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
47 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 */
49
50/*-
51 * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
52 * All rights reserved.
53 *
54 * This code is derived from software contributed to The NetBSD Foundation
55 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
56 * NASA Ames Research Center.
57 *
58 * Redistribution and use in source and binary forms, with or without
59 * modification, are permitted provided that the following conditions
60 * are met:
61 * 1. Redistributions of source code must retain the above copyright
62 *    notice, this list of conditions and the following disclaimer.
63 * 2. Redistributions in binary form must reproduce the above copyright
64 *    notice, this list of conditions and the following disclaimer in the
65 *    documentation and/or other materials provided with the distribution.
66 * 3. All advertising materials mentioning features or use of this software
67 *    must display the following acknowledgement:
68 *      This product includes software developed by the NetBSD
69 *      Foundation, Inc. and its contributors.
70 * 4. Neither the name of The NetBSD Foundation nor the names of its
71 *    contributors may be used to endorse or promote products derived
72 *    from this software without specific prior written permission.
73 *
74 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
75 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
76 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
77 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
78 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
79 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
80 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
81 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
82 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
83 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
84 * POSSIBILITY OF SUCH DAMAGE.
85 */
86
87/*-
88 * Copyright (c) 1996 Charles M. Hannum.  All rights reserved.
89 * Copyright (c) 1996 Christopher G. Demetriou.  All rights reserved.
90 *
91 * Redistribution and use in source and binary forms, with or without
92 * modification, are permitted provided that the following conditions
93 * are met:
94 * 1. Redistributions of source code must retain the above copyright
95 *    notice, this list of conditions and the following disclaimer.
96 * 2. Redistributions in binary form must reproduce the above copyright
97 *    notice, this list of conditions and the following disclaimer in the
98 *    documentation and/or other materials provided with the distribution.
99 * 3. All advertising materials mentioning features or use of this software
100 *    must display the following acknowledgement:
101 *      This product includes software developed by Christopher G. Demetriou
102 *      for the NetBSD Project.
103 * 4. The name of the author may not be used to endorse or promote products
104 *    derived from this software without specific prior written permission
105 *
106 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
107 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
108 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
109 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
110 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
111 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
112 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
113 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
114 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
115 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
116 */
117
118#ifndef _RTEMS_BSD_MACHINE_BUS_H_
119#define _RTEMS_BSD_MACHINE_BUS_H_
120
121#ifndef _RTEMS_BSD_MACHINE_RTEMS_BSD_KERNEL_SPACE_H_
122#error "the header file <machine/rtems-bsd-kernel-space.h> must be included first"
123#endif
124
125#ifdef __i386__
126  #error "your include paths are wrong"
127#endif
128
129/*
130 * Bus address alignment.
131 */
132#define BUS_SPACE_ALIGNED_POINTER(p, t) ALIGNED_POINTER(p, t)
133
134/*
135 * Bus address maxima.
136 */
137#define BUS_SPACE_MAXADDR_24BIT 0xffffffU
138#define BUS_SPACE_MAXADDR_32BIT 0xffffffffU
139#define BUS_SPACE_MAXADDR       0xffffffffU
140#define BUS_SPACE_MAXSIZE_24BIT 0xffffffU
141#define BUS_SPACE_MAXSIZE_32BIT 0xffffffffU
142#define BUS_SPACE_MAXSIZE       0xffffffffU
143
144/*
145 * Bus access.
146 */
147#define BUS_SPACE_UNRESTRICTED  (~0U)
148
149/*
150 * Bus read/write barrier method.
151 */
152#define BUS_SPACE_BARRIER_READ  0x01            /* force read barrier */
153#define BUS_SPACE_BARRIER_WRITE 0x02            /* force write barrier */
154
155/*
156 * Bus address and size types
157 */
158typedef unsigned int bus_addr_t;
159typedef unsigned int bus_size_t;
160
161/*
162 * Access methods for bus resources and address space.
163 */
164typedef int bus_space_tag_t;
165typedef unsigned int bus_space_handle_t;
166
167/*
168 * Map a region of device bus space into CPU virtual address space.
169 */
170
171static __inline int
172bus_space_map(bus_space_tag_t t __unused, bus_addr_t addr,
173              bus_size_t size __unused, int flags __unused,
174              bus_space_handle_t *bshp)
175{
176        *bshp = addr;
177        return (0);
178}
179
180/*
181 * Unmap a region of device bus space.
182 */
183static __inline void
184bus_space_unmap(bus_space_tag_t bst __unused, bus_space_handle_t bsh __unused,
185    bus_size_t size __unused)
186{
187        /* Do nothing */
188}
189
190
191/*
192 * Get a new handle for a subregion of an already-mapped area of bus space.
193 */
194static __inline int
195bus_space_subregion(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
196    bus_size_t ofs, bus_size_t size, bus_space_handle_t *nbshp)
197{
198        *nbshp = bsh + ofs;
199        return (0);
200}
201
202
203/*
204 * Allocate a region of memory that is accessible to devices in bus space.
205 */
206int
207bus_space_alloc(bus_space_tag_t bst __unused, bus_addr_t rstart, bus_addr_t rend,
208    bus_size_t size, bus_size_t align, bus_size_t boundary, int flags,
209    bus_addr_t *addrp, bus_space_handle_t *bshp);
210
211
212/*
213 * Free a region of bus space accessible memory.
214 */
215void
216bus_space_free(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t size);
217
218static __inline void
219bus_space_barrier(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs,
220    bus_size_t size, int flags)
221{
222        /* Do nothing */
223}
224
225/*
226 * Read 1 unit of data from bus space described by the tag, handle and ofs
227 * tuple. A unit of data can be 1 byte, 2 bytes, 4 bytes or 8 bytes. The
228 * data is returned.
229 */
230static __inline uint8_t
231bus_space_read_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs)
232{
233        uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
234        return (*bsp);
235}
236
237static __inline uint16_t
238bus_space_read_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs)
239{
240        uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
241        return (*bsp);
242}
243
244static __inline uint32_t
245bus_space_read_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs)
246{
247        uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
248        return (*bsp);
249}
250
251static __inline uint64_t
252bus_space_read_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs)
253{
254        uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
255        return (*bsp);
256}
257
258
259/*
260 * Write 1 unit of data to bus space described by the tag, handle and ofs
261 * tuple. A unit of data can be 1 byte, 2 bytes, 4 bytes or 8 bytes. The
262 * data is passed by value.
263 */
264static __inline void
265bus_space_write_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs,
266    uint8_t val)
267{
268        uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
269        *bsp = val;
270}
271
272static __inline void
273bus_space_write_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs,
274    uint16_t val)
275{
276        uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
277        *bsp = val;
278}
279
280static __inline void
281bus_space_write_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs,
282    uint32_t val)
283{
284        uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
285        *bsp = val;
286}
287
288static __inline void
289bus_space_write_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh, bus_size_t ofs,
290    uint64_t val)
291{
292        uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
293        *bsp = val;
294}
295
296
297/*
298 * Read count units of data from bus space described by the tag, handle and
299 * ofs tuple. A unit of data can be 1 byte, 2 bytes, 4 bytes or 8 bytes. The
300 * data is returned in the buffer passed by reference.
301 */
302static __inline void
303bus_space_read_multi_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
304    bus_size_t ofs, uint8_t *bufp, bus_size_t count)
305{
306        uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
307        while (count-- > 0) {
308                *bufp++ = *bsp;
309        }
310}
311
312static __inline void
313bus_space_read_multi_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
314    bus_size_t ofs, uint16_t *bufp, bus_size_t count)
315{
316        uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
317        while (count-- > 0) {
318                *bufp++ = *bsp;
319        }
320}
321
322static __inline void
323bus_space_read_multi_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
324    bus_size_t ofs, uint32_t *bufp, bus_size_t count)
325{
326        uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
327        while (count-- > 0) {
328                *bufp++ = *bsp;
329        }
330}
331
332static __inline void
333bus_space_read_multi_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
334    bus_size_t ofs, uint64_t *bufp, bus_size_t count)
335{
336        uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
337        while (count-- > 0) {
338                *bufp++ = *bsp;
339        }
340}
341
342
343/*
344 * Write count units of data to bus space described by the tag, handle and
345 * ofs tuple. A unit of data can be 1 byte, 2 bytes, 4 bytes or 8 bytes. The
346 * data is read from the buffer passed by reference.
347 */
348static __inline void
349bus_space_write_multi_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
350    bus_size_t ofs, const uint8_t *bufp, bus_size_t count)
351{
352        uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
353        while (count-- > 0) {
354                *bsp = *bufp++;
355        }
356}
357
358static __inline void
359bus_space_write_multi_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
360    bus_size_t ofs, const uint16_t *bufp, bus_size_t count)
361{
362        uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
363        while (count-- > 0) {
364                *bsp = *bufp++;
365        }
366}
367
368static __inline void
369bus_space_write_multi_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
370    bus_size_t ofs, const uint32_t *bufp, bus_size_t count)
371{
372        uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
373        while (count-- > 0) {
374                *bsp = *bufp++;
375        }
376}
377
378static __inline void
379bus_space_write_multi_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
380    bus_size_t ofs, const uint64_t *bufp, bus_size_t count)
381{
382        uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
383        while (count-- > 0) {
384                *bsp = *bufp++;
385        }
386}
387
388
389/*
390 * Read count units of data from bus space described by the tag, handle and
391 * ofs tuple. A unit of data can be 1 byte, 2 bytes, 4 bytes or 8 bytes. The
392 * data is written to the buffer passed by reference and read from successive
393 * bus space addresses. Access is unordered.
394 */
395static __inline void
396bus_space_read_region_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
397    bus_size_t ofs, uint8_t *bufp, bus_size_t count)
398{
399        while (count-- > 0) {
400                uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
401                *bufp++ = *bsp;
402                ofs += 1;
403        }
404}
405
406static __inline void
407bus_space_read_region_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
408    bus_size_t ofs, uint16_t *bufp, bus_size_t count)
409{
410        while (count-- > 0) {
411                uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
412                *bufp++ = *bsp;
413                ofs += 2;
414        }
415}
416
417static __inline void
418bus_space_read_region_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
419    bus_size_t ofs, uint32_t *bufp, bus_size_t count)
420{
421        while (count-- > 0) {
422                uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
423                *bufp++ = *bsp;
424                ofs += 4;
425        }
426}
427
428static __inline void
429bus_space_read_region_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
430    bus_size_t ofs, uint64_t *bufp, bus_size_t count)
431{
432        while (count-- > 0) {
433                uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
434                *bufp++ = *bsp;
435                ofs += 8;
436        }
437}
438
439
440/*
441 * Write count units of data from bus space described by the tag, handle and
442 * ofs tuple. A unit of data can be 1 byte, 2 bytes, 4 bytes or 8 bytes. The
443 * data is read from the buffer passed by reference and written to successive
444 * bus space addresses. Access is unordered.
445 */
446static __inline void
447bus_space_write_region_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
448    bus_size_t ofs, const uint8_t *bufp, bus_size_t count)
449{
450        while (count-- > 0) {
451                uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
452                *bsp = *bufp++;
453                ofs += 1;
454        }
455}
456
457static __inline void
458bus_space_write_region_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
459    bus_size_t ofs, const uint16_t *bufp, bus_size_t count)
460{
461        while (count-- > 0) {
462                uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
463                *bsp = *bufp++;
464                ofs += 2;
465        }
466}
467
468static __inline void
469bus_space_write_region_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
470    bus_size_t ofs, const uint32_t *bufp, bus_size_t count)
471{
472        while (count-- > 0) {
473                uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
474                *bsp = *bufp++;
475                ofs += 4;
476        }
477}
478
479static __inline void
480bus_space_write_region_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
481    bus_size_t ofs, const uint64_t *bufp, bus_size_t count)
482{
483        while (count-- > 0) {
484                uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
485                *bsp = *bufp++;
486                ofs += 8;
487        }
488}
489
490
491/*
492 * Write count units of data from bus space described by the tag, handle and
493 * ofs tuple. A unit of data can be 1 byte, 2 bytes, 4 bytes or 8 bytes. The
494 * data is passed by value. Writes are unordered.
495 */
496static __inline void
497bus_space_set_multi_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
498    bus_size_t ofs, uint8_t val, bus_size_t count)
499{
500        uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
501        while (count-- > 0) {
502                *bsp = val;
503        }
504}
505
506static __inline void
507bus_space_set_multi_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
508    bus_size_t ofs, uint16_t val, bus_size_t count)
509{
510        uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
511        while (count-- > 0) {
512                *bsp = val;
513        }
514}
515
516static __inline void
517bus_space_set_multi_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
518    bus_size_t ofs, uint32_t val, bus_size_t count)
519{
520        uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
521        while (count-- > 0) {
522                *bsp = val;
523        }
524}
525
526static __inline void
527bus_space_set_multi_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
528    bus_size_t ofs, uint64_t val, bus_size_t count)
529{
530        uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
531        while (count-- > 0) {
532                *bsp = val;
533        }
534}
535
536
537/*
538 * Write count units of data from bus space described by the tag, handle and
539 * ofs tuple. A unit of data can be 1 byte, 2 bytes, 4 bytes or 8 bytes. The
540 * data is passed by value and written to successive bus space addresses.
541 * Writes are unordered.
542 */
543static __inline void
544bus_space_set_region_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
545    bus_size_t ofs, uint8_t val, bus_size_t count)
546{
547        while (count-- > 0) {
548                uint8_t __volatile *bsp = (uint8_t __volatile *)(bsh + ofs);
549                *bsp = val;
550                ofs += 1;
551        }
552}
553
554static __inline void
555bus_space_set_region_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
556    bus_size_t ofs, uint16_t val, bus_size_t count)
557{
558        while (count-- > 0) {
559                uint16_t __volatile *bsp = (uint16_t __volatile *)(bsh + ofs);
560                *bsp = val;
561                ofs += 2;
562        }
563}
564
565static __inline void
566bus_space_set_region_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
567    bus_size_t ofs, uint32_t val, bus_size_t count)
568{
569        while (count-- > 0) {
570                uint32_t __volatile *bsp = (uint32_t __volatile *)(bsh + ofs);
571                *bsp = val;
572                ofs += 4;
573        }
574}
575
576static __inline void
577bus_space_set_region_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh,
578    bus_size_t ofs, uint64_t val, bus_size_t count)
579{
580        while (count-- > 0) {
581                uint64_t __volatile *bsp = (uint64_t __volatile *)(bsh + ofs);
582                *bsp = val;
583                ofs += 8;
584        }
585}
586
587
588/*
589 * Copy count units of data from bus space described by the tag and the first
590 * handle and ofs pair to bus space described by the tag and the second handle
591 * and ofs pair. A unit of data can be 1 byte, 2 bytes, 4 bytes or 8 bytes.
592 * The data is read from successive bus space addresses and also written to
593 * successive bus space addresses. Both reads and writes are unordered.
594 */
595static __inline void
596bus_space_copy_region_1(bus_space_tag_t bst __unused, bus_space_handle_t bsh1,
597    bus_size_t ofs1, bus_space_handle_t bsh2, bus_size_t ofs2, bus_size_t count)
598{
599        bus_addr_t dst = bsh1 + ofs1;
600        bus_addr_t src = bsh2 + ofs2;
601        uint8_t __volatile *dstp = (uint8_t __volatile *) dst;
602        uint8_t __volatile *srcp = (uint8_t __volatile *) src;
603        if (dst > src) {
604                src += count - 1;
605                dst += count - 1;
606                while (count-- > 0) {
607                        *dstp = *srcp;
608                        src -= 1;
609                        dst -= 1;
610                }
611        } else {
612                while (count-- > 0) {
613                        *dstp = *srcp;
614                        src += 1;
615                        dst += 1;
616                }
617        }
618}
619
620static __inline void
621bus_space_copy_region_2(bus_space_tag_t bst __unused, bus_space_handle_t bsh1,
622    bus_size_t ofs1, bus_space_handle_t bsh2, bus_size_t ofs2, bus_size_t count)
623{
624        bus_addr_t dst = bsh1 + ofs1;
625        bus_addr_t src = bsh2 + ofs2;
626        uint16_t __volatile *dstp = (uint16_t __volatile *) dst;
627        uint16_t __volatile *srcp = (uint16_t __volatile *) src;
628        if (dst > src) {
629                src += (count - 1) << 1;
630                dst += (count - 1) << 1;
631                while (count-- > 0) {
632                        *dstp = *srcp;
633                        src -= 2;
634                        dst -= 2;
635                }
636        } else {
637                while (count-- > 0) {
638                        *dstp = *srcp;
639                        src += 2;
640                        dst += 2;
641                }
642        }
643}
644
645static __inline void
646bus_space_copy_region_4(bus_space_tag_t bst __unused, bus_space_handle_t bsh1,
647    bus_size_t ofs1, bus_space_handle_t bsh2, bus_size_t ofs2, bus_size_t count)
648{
649        bus_addr_t dst = bsh1 + ofs1;
650        bus_addr_t src = bsh2 + ofs2;
651        uint32_t __volatile *dstp = (uint32_t __volatile *) dst;
652        uint32_t __volatile *srcp = (uint32_t __volatile *) src;
653        if (dst > src) {
654                src += (count - 1) << 2;
655                dst += (count - 1) << 2;
656                while (count-- > 0) {
657                        *dstp = *srcp;
658                        src -= 4;
659                        dst -= 4;
660                }
661        } else {
662                while (count-- > 0) {
663                        *dstp = *srcp;
664                        src += 4;
665                        dst += 4;
666                }
667        }
668}
669
670static __inline void
671bus_space_copy_region_8(bus_space_tag_t bst __unused, bus_space_handle_t bsh1,
672    bus_size_t ofs1, bus_space_handle_t bsh2, bus_size_t ofs2, bus_size_t count)
673{
674        bus_addr_t dst = bsh1 + ofs1;
675        bus_addr_t src = bsh2 + ofs2;
676        uint64_t __volatile *dstp = (uint64_t __volatile *) dst;
677        uint64_t __volatile *srcp = (uint64_t __volatile *) src;
678        if (dst > src) {
679                src += (count - 1) << 3;
680                dst += (count - 1) << 3;
681                while (count-- > 0) {
682                        *dstp = *srcp;
683                        src -= 8;
684                        dst -= 8;
685                }
686        } else {
687                while (count-- > 0) {
688                        *dstp = *srcp;
689                        src += 8;
690                        dst += 8;
691                }
692        }
693}
694
695
696/*
697 * Stream accesses are the same as normal accesses on RTEMS; there are no
698 * supported bus systems with an endianess different from the host one.
699 */
700#define bus_space_read_stream_1(t, h, o)        \
701        bus_space_read_1(t, h, o)
702#define bus_space_read_stream_2(t, h, o)        \
703        bus_space_read_2(t, h, o)
704#define bus_space_read_stream_4(t, h, o)        \
705        bus_space_read_4(t, h, o)
706#define bus_space_read_stream_8(t, h, o)        \
707        bus_space_read_8(t, h, o)
708
709#define bus_space_read_multi_stream_1(t, h, o, a, c)    \
710        bus_space_read_multi_1(t, h, o, a, c)
711#define bus_space_read_multi_stream_2(t, h, o, a, c)    \
712        bus_space_read_multi_2(t, h, o, a, c)
713#define bus_space_read_multi_stream_4(t, h, o, a, c)    \
714        bus_space_read_multi_4(t, h, o, a, c)
715#define bus_space_read_multi_stream_8(t, h, o, a, c)    \
716        bus_space_read_multi_8(t, h, o, a, c)
717
718#define bus_space_write_stream_1(t, h, o, v)    \
719        bus_space_write_1(t, h, o, v)
720#define bus_space_write_stream_2(t, h, o, v)    \
721        bus_space_write_2(t, h, o, v)
722#define bus_space_write_stream_4(t, h, o, v)    \
723        bus_space_write_4(t, h, o, v)
724#define bus_space_write_stream_8(t, h, o, v)    \
725        bus_space_write_8(t, h, o, v)
726
727#define bus_space_write_multi_stream_1(t, h, o, a, c)   \
728        bus_space_write_multi_1(t, h, o, a, c)
729#define bus_space_write_multi_stream_2(t, h, o, a, c)   \
730        bus_space_write_multi_2(t, h, o, a, c)
731#define bus_space_write_multi_stream_4(t, h, o, a, c)   \
732        bus_space_write_multi_4(t, h, o, a, c)
733#define bus_space_write_multi_stream_8(t, h, o, a, c)   \
734        bus_space_write_multi_8(t, h, o, a, c)
735
736#define bus_space_set_multi_stream_1(t, h, o, v, c)     \
737        bus_space_set_multi_1(t, h, o, v, c)
738#define bus_space_set_multi_stream_2(t, h, o, v, c)     \
739        bus_space_set_multi_2(t, h, o, v, c)
740#define bus_space_set_multi_stream_4(t, h, o, v, c)     \
741        bus_space_set_multi_4(t, h, o, v, c)
742#define bus_space_set_multi_stream_8(t, h, o, v, c)     \
743        bus_space_set_multi_8(t, h, o, v, c)
744
745#define bus_space_read_region_stream_1(t, h, o, a, c)   \
746        bus_space_read_region_1(t, h, o, a, c)
747#define bus_space_read_region_stream_2(t, h, o, a, c)   \
748        bus_space_read_region_2(t, h, o, a, c)
749#define bus_space_read_region_stream_4(t, h, o, a, c)   \
750        bus_space_read_region_4(t, h, o, a, c)
751#define bus_space_read_region_stream_8(t, h, o, a, c)   \
752        bus_space_read_region_8(t, h, o, a, c)
753
754#define bus_space_write_region_stream_1(t, h, o, a, c)  \
755        bus_space_write_region_1(t, h, o, a, c)
756#define bus_space_write_region_stream_2(t, h, o, a, c)  \
757        bus_space_write_region_2(t, h, o, a, c)
758#define bus_space_write_region_stream_4(t, h, o, a, c)  \
759        bus_space_write_region_4(t, h, o, a, c)
760#define bus_space_write_region_stream_8(t, h, o, a, c)  \
761        bus_space_write_region_8(t, h, o, a, c)
762
763#define bus_space_set_region_stream_1(t, h, o, v, c)    \
764        bus_space_set_region_1(t, h, o, v, c)
765#define bus_space_set_region_stream_2(t, h, o, v, c)    \
766        bus_space_set_region_2(t, h, o, v, c)
767#define bus_space_set_region_stream_4(t, h, o, v, c)    \
768        bus_space_set_region_4(t, h, o, v, c)
769#define bus_space_set_region_stream_8(t, h, o, v, c)    \
770        bus_space_set_region_8(t, h, o, v, c)
771
772#define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c)    \
773        bus_space_copy_region_1(t, h1, o1, h2, o2, c)
774#define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c)    \
775        bus_space_copy_region_2(t, h1, o1, h2, o2, c)
776#define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c)    \
777        bus_space_copy_region_4(t, h1, o1, h2, o2, c)
778#define bus_space_copy_region_stream_8(t, h1, o1, h2, o2, c)    \
779        bus_space_copy_region_8(t, h1, o1, h2, o2, c)
780
781#include <machine/bus_dma.h>
782
783#endif /* _RTEMS_BSD_MACHINE_BUS_H_ */
Note: See TracBrowser for help on using the repository browser.