181bd5041STijl Coosemans /*-
2*b2f4d9b6SLi-Wen Hsu * SPDX-License-Identifier: BSD-3-Clause AND BSD-2-Clause
3ebf5747bSPedro F. Giffuni *
481bd5041STijl Coosemans * Copyright (c) KATO Takenori, 1999.
581bd5041STijl Coosemans *
681bd5041STijl Coosemans * All rights reserved. Unpublished rights reserved under the copyright
781bd5041STijl Coosemans * laws of Japan.
881bd5041STijl Coosemans *
981bd5041STijl Coosemans * Redistribution and use in source and binary forms, with or without
1081bd5041STijl Coosemans * modification, are permitted provided that the following conditions
1181bd5041STijl Coosemans * are met:
1281bd5041STijl Coosemans *
1381bd5041STijl Coosemans * 1. Redistributions of source code must retain the above copyright
1481bd5041STijl Coosemans * notice, this list of conditions and the following disclaimer as
1581bd5041STijl Coosemans * the first lines of this file unmodified.
1681bd5041STijl Coosemans * 2. Redistributions in binary form must reproduce the above copyright
1781bd5041STijl Coosemans * notice, this list of conditions and the following disclaimer in the
1881bd5041STijl Coosemans * documentation and/or other materials provided with the distribution.
1981bd5041STijl Coosemans * 3. The name of the author may not be used to endorse or promote products
2081bd5041STijl Coosemans * derived from this software without specific prior written permission.
2181bd5041STijl Coosemans *
2281bd5041STijl Coosemans * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2381bd5041STijl Coosemans * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2481bd5041STijl Coosemans * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2581bd5041STijl Coosemans * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2681bd5041STijl Coosemans * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2781bd5041STijl Coosemans * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2881bd5041STijl Coosemans * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2981bd5041STijl Coosemans * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3081bd5041STijl Coosemans * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3181bd5041STijl Coosemans * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3281bd5041STijl Coosemans */
3381bd5041STijl Coosemans
3481bd5041STijl Coosemans /* $NetBSD: bus.h,v 1.12 1997/10/01 08:25:15 fvdl Exp $ */
3581bd5041STijl Coosemans
3681bd5041STijl Coosemans /*-
3781bd5041STijl Coosemans * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
3881bd5041STijl Coosemans * All rights reserved.
3981bd5041STijl Coosemans *
4081bd5041STijl Coosemans * This code is derived from software contributed to The NetBSD Foundation
4181bd5041STijl Coosemans * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
4281bd5041STijl Coosemans * NASA Ames Research Center.
4381bd5041STijl Coosemans *
4481bd5041STijl Coosemans * Redistribution and use in source and binary forms, with or without
4581bd5041STijl Coosemans * modification, are permitted provided that the following conditions
4681bd5041STijl Coosemans * are met:
4781bd5041STijl Coosemans * 1. Redistributions of source code must retain the above copyright
4881bd5041STijl Coosemans * notice, this list of conditions and the following disclaimer.
4981bd5041STijl Coosemans * 2. Redistributions in binary form must reproduce the above copyright
5081bd5041STijl Coosemans * notice, this list of conditions and the following disclaimer in the
5181bd5041STijl Coosemans * documentation and/or other materials provided with the distribution.
5281bd5041STijl Coosemans *
5381bd5041STijl Coosemans * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
5481bd5041STijl Coosemans * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
5581bd5041STijl Coosemans * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
5681bd5041STijl Coosemans * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
5781bd5041STijl Coosemans * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
5881bd5041STijl Coosemans * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
5981bd5041STijl Coosemans * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
6081bd5041STijl Coosemans * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
6181bd5041STijl Coosemans * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
6281bd5041STijl Coosemans * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
6381bd5041STijl Coosemans * POSSIBILITY OF SUCH DAMAGE.
6481bd5041STijl Coosemans */
6581bd5041STijl Coosemans
6681bd5041STijl Coosemans /*-
6781bd5041STijl Coosemans * Copyright (c) 1996 Charles M. Hannum. All rights reserved.
6881bd5041STijl Coosemans * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
6981bd5041STijl Coosemans *
7081bd5041STijl Coosemans * Redistribution and use in source and binary forms, with or without
7181bd5041STijl Coosemans * modification, are permitted provided that the following conditions
7281bd5041STijl Coosemans * are met:
7381bd5041STijl Coosemans * 1. Redistributions of source code must retain the above copyright
7481bd5041STijl Coosemans * notice, this list of conditions and the following disclaimer.
7581bd5041STijl Coosemans * 2. Redistributions in binary form must reproduce the above copyright
7681bd5041STijl Coosemans * notice, this list of conditions and the following disclaimer in the
7781bd5041STijl Coosemans * documentation and/or other materials provided with the distribution.
7881bd5041STijl Coosemans * 3. All advertising materials mentioning features or use of this software
7981bd5041STijl Coosemans * must display the following acknowledgement:
8081bd5041STijl Coosemans * This product includes software developed by Christopher G. Demetriou
8181bd5041STijl Coosemans * for the NetBSD Project.
8281bd5041STijl Coosemans * 4. The name of the author may not be used to endorse or promote products
8381bd5041STijl Coosemans * derived from this software without specific prior written permission
8481bd5041STijl Coosemans *
8581bd5041STijl Coosemans * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
8681bd5041STijl Coosemans * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8781bd5041STijl Coosemans * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
8881bd5041STijl Coosemans * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
8981bd5041STijl Coosemans * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
9081bd5041STijl Coosemans * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
9181bd5041STijl Coosemans * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
9281bd5041STijl Coosemans * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
9381bd5041STijl Coosemans * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
9481bd5041STijl Coosemans * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9581bd5041STijl Coosemans */
9681bd5041STijl Coosemans
973ead6023SMark Johnston #ifndef _MACHINE_BUS_H_
983ead6023SMark Johnston #define _MACHINE_BUS_H_
9981bd5041STijl Coosemans
10081bd5041STijl Coosemans #include <machine/_bus.h>
10181bd5041STijl Coosemans #include <machine/cpufunc.h>
102849aef49SAndrew Turner #include <machine/bus_dma.h>
10381bd5041STijl Coosemans
10481bd5041STijl Coosemans /*
10581bd5041STijl Coosemans * Values for the x86 bus space tag, not to be used directly by MI code.
10681bd5041STijl Coosemans */
10781bd5041STijl Coosemans #define X86_BUS_SPACE_IO 0 /* space is i/o space */
10881bd5041STijl Coosemans #define X86_BUS_SPACE_MEM 1 /* space is mem space */
10981bd5041STijl Coosemans
11081bd5041STijl Coosemans #define BUS_SPACE_MAXSIZE_24BIT 0xFFFFFF
11181bd5041STijl Coosemans #define BUS_SPACE_MAXSIZE_32BIT 0xFFFFFFFF
112078116a6SKonstantin Belousov #if defined(__amd64__)
113078116a6SKonstantin Belousov #define BUS_SPACE_MAXSIZE 0xFFFFFFFFFFFFFFFFULL
114078116a6SKonstantin Belousov #else
11581bd5041STijl Coosemans #define BUS_SPACE_MAXSIZE 0xFFFFFFFF
116078116a6SKonstantin Belousov #endif
11781bd5041STijl Coosemans #define BUS_SPACE_MAXADDR_24BIT 0xFFFFFF
11881bd5041STijl Coosemans #define BUS_SPACE_MAXADDR_32BIT 0xFFFFFFFF
11981bd5041STijl Coosemans #if defined(__amd64__) || defined(PAE)
120233933cbSConrad Meyer #define BUS_SPACE_MAXADDR_48BIT 0xFFFFFFFFFFFFULL
12181bd5041STijl Coosemans #define BUS_SPACE_MAXADDR 0xFFFFFFFFFFFFFFFFULL
12281bd5041STijl Coosemans #else
12381bd5041STijl Coosemans #define BUS_SPACE_MAXADDR 0xFFFFFFFF
12481bd5041STijl Coosemans #endif
12581bd5041STijl Coosemans
1267b332f20SJim Harris #define BUS_SPACE_INVALID_DATA (~0)
12781bd5041STijl Coosemans #define BUS_SPACE_UNRESTRICTED (~0)
12881bd5041STijl Coosemans
129849aef49SAndrew Turner #define BUS_SPACE_BARRIER_READ 0x01 /* force read barrier */
130849aef49SAndrew Turner #define BUS_SPACE_BARRIER_WRITE 0x02 /* force write barrier */
131849aef49SAndrew Turner
132a90d053bSMark Johnston #if defined(SAN_NEEDS_INTERCEPTORS) && !defined(SAN_RUNTIME)
133435c7cfbSMark Johnston #include <sys/bus_san.h>
134849aef49SAndrew Turner #else
135849aef49SAndrew Turner
13681bd5041STijl Coosemans /*
13781bd5041STijl Coosemans * Map a region of device bus space into CPU virtual address space.
13881bd5041STijl Coosemans */
13981bd5041STijl Coosemans
1407ef5e8bcSMarcel Moolenaar int bus_space_map(bus_space_tag_t tag, bus_addr_t addr, bus_size_t size,
1417ef5e8bcSMarcel Moolenaar int flags, bus_space_handle_t *bshp);
14281bd5041STijl Coosemans
14381bd5041STijl Coosemans /*
14481bd5041STijl Coosemans * Unmap a region of device bus space.
14581bd5041STijl Coosemans */
14681bd5041STijl Coosemans
1477ef5e8bcSMarcel Moolenaar void bus_space_unmap(bus_space_tag_t tag, bus_space_handle_t bsh,
14881bd5041STijl Coosemans bus_size_t size);
14981bd5041STijl Coosemans
15081bd5041STijl Coosemans /*
15181bd5041STijl Coosemans * Get a new handle for a subregion of an already-mapped area of bus space.
15281bd5041STijl Coosemans */
15381bd5041STijl Coosemans
15481bd5041STijl Coosemans static __inline int bus_space_subregion(bus_space_tag_t t,
15581bd5041STijl Coosemans bus_space_handle_t bsh,
15681bd5041STijl Coosemans bus_size_t offset, bus_size_t size,
15781bd5041STijl Coosemans bus_space_handle_t *nbshp);
15881bd5041STijl Coosemans
15981bd5041STijl Coosemans static __inline int
bus_space_subregion(bus_space_tag_t t __unused,bus_space_handle_t bsh,bus_size_t offset,bus_size_t size __unused,bus_space_handle_t * nbshp)16081bd5041STijl Coosemans bus_space_subregion(bus_space_tag_t t __unused, bus_space_handle_t bsh,
16181bd5041STijl Coosemans bus_size_t offset, bus_size_t size __unused,
16281bd5041STijl Coosemans bus_space_handle_t *nbshp)
16381bd5041STijl Coosemans {
16481bd5041STijl Coosemans
16581bd5041STijl Coosemans *nbshp = bsh + offset;
16681bd5041STijl Coosemans return (0);
16781bd5041STijl Coosemans }
16881bd5041STijl Coosemans
16981bd5041STijl Coosemans /*
17081bd5041STijl Coosemans * Allocate a region of memory that is accessible to devices in bus space.
17181bd5041STijl Coosemans */
17281bd5041STijl Coosemans
17381bd5041STijl Coosemans int bus_space_alloc(bus_space_tag_t t, bus_addr_t rstart,
17481bd5041STijl Coosemans bus_addr_t rend, bus_size_t size, bus_size_t align,
17581bd5041STijl Coosemans bus_size_t boundary, int flags, bus_addr_t *addrp,
17681bd5041STijl Coosemans bus_space_handle_t *bshp);
17781bd5041STijl Coosemans
17881bd5041STijl Coosemans /*
17981bd5041STijl Coosemans * Free a region of bus space accessible memory.
18081bd5041STijl Coosemans */
18181bd5041STijl Coosemans
18281bd5041STijl Coosemans static __inline void bus_space_free(bus_space_tag_t t, bus_space_handle_t bsh,
18381bd5041STijl Coosemans bus_size_t size);
18481bd5041STijl Coosemans
18581bd5041STijl Coosemans static __inline void
bus_space_free(bus_space_tag_t t __unused,bus_space_handle_t bsh __unused,bus_size_t size __unused)18681bd5041STijl Coosemans bus_space_free(bus_space_tag_t t __unused, bus_space_handle_t bsh __unused,
18781bd5041STijl Coosemans bus_size_t size __unused)
18881bd5041STijl Coosemans {
18981bd5041STijl Coosemans }
19081bd5041STijl Coosemans
19181bd5041STijl Coosemans /*
19281bd5041STijl Coosemans * Read a 1, 2, 4, or 8 byte quantity from bus space
19381bd5041STijl Coosemans * described by tag/handle/offset.
19481bd5041STijl Coosemans */
19581bd5041STijl Coosemans static __inline u_int8_t bus_space_read_1(bus_space_tag_t tag,
19681bd5041STijl Coosemans bus_space_handle_t handle,
19781bd5041STijl Coosemans bus_size_t offset);
19881bd5041STijl Coosemans
19981bd5041STijl Coosemans static __inline u_int16_t bus_space_read_2(bus_space_tag_t tag,
20081bd5041STijl Coosemans bus_space_handle_t handle,
20181bd5041STijl Coosemans bus_size_t offset);
20281bd5041STijl Coosemans
20381bd5041STijl Coosemans static __inline u_int32_t bus_space_read_4(bus_space_tag_t tag,
20481bd5041STijl Coosemans bus_space_handle_t handle,
20581bd5041STijl Coosemans bus_size_t offset);
20681bd5041STijl Coosemans
2077b332f20SJim Harris #ifdef __amd64__
2087b332f20SJim Harris static __inline uint64_t bus_space_read_8(bus_space_tag_t tag,
2097b332f20SJim Harris bus_space_handle_t handle,
2107b332f20SJim Harris bus_size_t offset);
2117b332f20SJim Harris #endif
2127b332f20SJim Harris
21381bd5041STijl Coosemans static __inline u_int8_t
bus_space_read_1(bus_space_tag_t tag,bus_space_handle_t handle,bus_size_t offset)21481bd5041STijl Coosemans bus_space_read_1(bus_space_tag_t tag, bus_space_handle_t handle,
21581bd5041STijl Coosemans bus_size_t offset)
21681bd5041STijl Coosemans {
21781bd5041STijl Coosemans
21881bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
21981bd5041STijl Coosemans return (inb(handle + offset));
22081bd5041STijl Coosemans return (*(volatile u_int8_t *)(handle + offset));
22181bd5041STijl Coosemans }
22281bd5041STijl Coosemans
22381bd5041STijl Coosemans static __inline u_int16_t
bus_space_read_2(bus_space_tag_t tag,bus_space_handle_t handle,bus_size_t offset)22481bd5041STijl Coosemans bus_space_read_2(bus_space_tag_t tag, bus_space_handle_t handle,
22581bd5041STijl Coosemans bus_size_t offset)
22681bd5041STijl Coosemans {
22781bd5041STijl Coosemans
22881bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
22981bd5041STijl Coosemans return (inw(handle + offset));
23081bd5041STijl Coosemans return (*(volatile u_int16_t *)(handle + offset));
23181bd5041STijl Coosemans }
23281bd5041STijl Coosemans
23381bd5041STijl Coosemans static __inline u_int32_t
bus_space_read_4(bus_space_tag_t tag,bus_space_handle_t handle,bus_size_t offset)23481bd5041STijl Coosemans bus_space_read_4(bus_space_tag_t tag, bus_space_handle_t handle,
23581bd5041STijl Coosemans bus_size_t offset)
23681bd5041STijl Coosemans {
23781bd5041STijl Coosemans
23881bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
23981bd5041STijl Coosemans return (inl(handle + offset));
24081bd5041STijl Coosemans return (*(volatile u_int32_t *)(handle + offset));
24181bd5041STijl Coosemans }
24281bd5041STijl Coosemans
2437b332f20SJim Harris #ifdef __amd64__
2447b332f20SJim Harris static __inline uint64_t
bus_space_read_8(bus_space_tag_t tag,bus_space_handle_t handle,bus_size_t offset)2457b332f20SJim Harris bus_space_read_8(bus_space_tag_t tag, bus_space_handle_t handle,
2467b332f20SJim Harris bus_size_t offset)
2477b332f20SJim Harris {
2487b332f20SJim Harris
2497b332f20SJim Harris if (tag == X86_BUS_SPACE_IO) /* No 8 byte IO space access on x86 */
2507b332f20SJim Harris return (BUS_SPACE_INVALID_DATA);
2517b332f20SJim Harris return (*(volatile uint64_t *)(handle + offset));
2527b332f20SJim Harris }
253f2fcc434SJim Harris #endif
254f2fcc434SJim Harris
25581bd5041STijl Coosemans /*
25681bd5041STijl Coosemans * Read `count' 1, 2, 4, or 8 byte quantities from bus space
25781bd5041STijl Coosemans * described by tag/handle/offset and copy into buffer provided.
25881bd5041STijl Coosemans */
25981bd5041STijl Coosemans static __inline void bus_space_read_multi_1(bus_space_tag_t tag,
26081bd5041STijl Coosemans bus_space_handle_t bsh,
26181bd5041STijl Coosemans bus_size_t offset, u_int8_t *addr,
26281bd5041STijl Coosemans size_t count);
26381bd5041STijl Coosemans
26481bd5041STijl Coosemans static __inline void bus_space_read_multi_2(bus_space_tag_t tag,
26581bd5041STijl Coosemans bus_space_handle_t bsh,
26681bd5041STijl Coosemans bus_size_t offset, u_int16_t *addr,
26781bd5041STijl Coosemans size_t count);
26881bd5041STijl Coosemans
26981bd5041STijl Coosemans static __inline void bus_space_read_multi_4(bus_space_tag_t tag,
27081bd5041STijl Coosemans bus_space_handle_t bsh,
27181bd5041STijl Coosemans bus_size_t offset, u_int32_t *addr,
27281bd5041STijl Coosemans size_t count);
27381bd5041STijl Coosemans
27481bd5041STijl Coosemans static __inline void
bus_space_read_multi_1(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int8_t * addr,size_t count)27581bd5041STijl Coosemans bus_space_read_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
27681bd5041STijl Coosemans bus_size_t offset, u_int8_t *addr, size_t count)
27781bd5041STijl Coosemans {
27881bd5041STijl Coosemans
27981bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
28081bd5041STijl Coosemans insb(bsh + offset, addr, count);
28181bd5041STijl Coosemans else {
28281bd5041STijl Coosemans __asm __volatile(" \n\
28381bd5041STijl Coosemans 1: movb (%2),%%al \n\
28481bd5041STijl Coosemans stosb \n\
28581bd5041STijl Coosemans loop 1b" :
28681bd5041STijl Coosemans "=D" (addr), "=c" (count) :
28781bd5041STijl Coosemans "r" (bsh + offset), "0" (addr), "1" (count) :
28881bd5041STijl Coosemans "%eax", "memory");
28981bd5041STijl Coosemans }
29081bd5041STijl Coosemans }
29181bd5041STijl Coosemans
29281bd5041STijl Coosemans static __inline void
bus_space_read_multi_2(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int16_t * addr,size_t count)29381bd5041STijl Coosemans bus_space_read_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
29481bd5041STijl Coosemans bus_size_t offset, u_int16_t *addr, size_t count)
29581bd5041STijl Coosemans {
29681bd5041STijl Coosemans
29781bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
29881bd5041STijl Coosemans insw(bsh + offset, addr, count);
29981bd5041STijl Coosemans else {
30081bd5041STijl Coosemans __asm __volatile(" \n\
30181bd5041STijl Coosemans 1: movw (%2),%%ax \n\
30281bd5041STijl Coosemans stosw \n\
30381bd5041STijl Coosemans loop 1b" :
30481bd5041STijl Coosemans "=D" (addr), "=c" (count) :
30581bd5041STijl Coosemans "r" (bsh + offset), "0" (addr), "1" (count) :
30681bd5041STijl Coosemans "%eax", "memory");
30781bd5041STijl Coosemans }
30881bd5041STijl Coosemans }
30981bd5041STijl Coosemans
31081bd5041STijl Coosemans static __inline void
bus_space_read_multi_4(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int32_t * addr,size_t count)31181bd5041STijl Coosemans bus_space_read_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
31281bd5041STijl Coosemans bus_size_t offset, u_int32_t *addr, size_t count)
31381bd5041STijl Coosemans {
31481bd5041STijl Coosemans
31581bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
31681bd5041STijl Coosemans insl(bsh + offset, addr, count);
31781bd5041STijl Coosemans else {
31881bd5041STijl Coosemans __asm __volatile(" \n\
31981bd5041STijl Coosemans 1: movl (%2),%%eax \n\
32081bd5041STijl Coosemans stosl \n\
32181bd5041STijl Coosemans loop 1b" :
32281bd5041STijl Coosemans "=D" (addr), "=c" (count) :
32381bd5041STijl Coosemans "r" (bsh + offset), "0" (addr), "1" (count) :
32481bd5041STijl Coosemans "%eax", "memory");
32581bd5041STijl Coosemans }
32681bd5041STijl Coosemans }
32781bd5041STijl Coosemans
328f2fcc434SJim Harris #if 0 /* Cause a link error for bus_space_read_multi_8 */
329f2fcc434SJim Harris #define bus_space_read_multi_8 !!! bus_space_read_multi_8 unimplemented !!!
330f2fcc434SJim Harris #endif
331f2fcc434SJim Harris
33281bd5041STijl Coosemans /*
33381bd5041STijl Coosemans * Read `count' 1, 2, 4, or 8 byte quantities from bus space
33481bd5041STijl Coosemans * described by tag/handle and starting at `offset' and copy into
33581bd5041STijl Coosemans * buffer provided.
33681bd5041STijl Coosemans */
33781bd5041STijl Coosemans static __inline void bus_space_read_region_1(bus_space_tag_t tag,
33881bd5041STijl Coosemans bus_space_handle_t bsh,
33981bd5041STijl Coosemans bus_size_t offset, u_int8_t *addr,
34081bd5041STijl Coosemans size_t count);
34181bd5041STijl Coosemans
34281bd5041STijl Coosemans static __inline void bus_space_read_region_2(bus_space_tag_t tag,
34381bd5041STijl Coosemans bus_space_handle_t bsh,
34481bd5041STijl Coosemans bus_size_t offset, u_int16_t *addr,
34581bd5041STijl Coosemans size_t count);
34681bd5041STijl Coosemans
34781bd5041STijl Coosemans static __inline void bus_space_read_region_4(bus_space_tag_t tag,
34881bd5041STijl Coosemans bus_space_handle_t bsh,
34981bd5041STijl Coosemans bus_size_t offset, u_int32_t *addr,
35081bd5041STijl Coosemans size_t count);
35181bd5041STijl Coosemans
35281bd5041STijl Coosemans static __inline void
bus_space_read_region_1(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int8_t * addr,size_t count)35381bd5041STijl Coosemans bus_space_read_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
35481bd5041STijl Coosemans bus_size_t offset, u_int8_t *addr, size_t count)
35581bd5041STijl Coosemans {
35681bd5041STijl Coosemans
35781bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO) {
35881bd5041STijl Coosemans int _port_ = bsh + offset;
35981bd5041STijl Coosemans __asm __volatile(" \n\
36081bd5041STijl Coosemans 1: inb %w2,%%al \n\
36181bd5041STijl Coosemans stosb \n\
36281bd5041STijl Coosemans incl %2 \n\
36381bd5041STijl Coosemans loop 1b" :
36481bd5041STijl Coosemans "=D" (addr), "=c" (count), "=d" (_port_) :
36581bd5041STijl Coosemans "0" (addr), "1" (count), "2" (_port_) :
36681bd5041STijl Coosemans "%eax", "memory", "cc");
36781bd5041STijl Coosemans } else {
36881bd5041STijl Coosemans bus_space_handle_t _port_ = bsh + offset;
36981bd5041STijl Coosemans __asm __volatile(" \n\
37081bd5041STijl Coosemans repne \n\
37181bd5041STijl Coosemans movsb" :
37281bd5041STijl Coosemans "=D" (addr), "=c" (count), "=S" (_port_) :
37381bd5041STijl Coosemans "0" (addr), "1" (count), "2" (_port_) :
37481bd5041STijl Coosemans "memory", "cc");
37581bd5041STijl Coosemans }
37681bd5041STijl Coosemans }
37781bd5041STijl Coosemans
37881bd5041STijl Coosemans static __inline void
bus_space_read_region_2(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int16_t * addr,size_t count)37981bd5041STijl Coosemans bus_space_read_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
38081bd5041STijl Coosemans bus_size_t offset, u_int16_t *addr, size_t count)
38181bd5041STijl Coosemans {
38281bd5041STijl Coosemans
38381bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO) {
38481bd5041STijl Coosemans int _port_ = bsh + offset;
38581bd5041STijl Coosemans __asm __volatile(" \n\
38681bd5041STijl Coosemans 1: inw %w2,%%ax \n\
38781bd5041STijl Coosemans stosw \n\
38881bd5041STijl Coosemans addl $2,%2 \n\
38981bd5041STijl Coosemans loop 1b" :
39081bd5041STijl Coosemans "=D" (addr), "=c" (count), "=d" (_port_) :
39181bd5041STijl Coosemans "0" (addr), "1" (count), "2" (_port_) :
39281bd5041STijl Coosemans "%eax", "memory", "cc");
39381bd5041STijl Coosemans } else {
39481bd5041STijl Coosemans bus_space_handle_t _port_ = bsh + offset;
39581bd5041STijl Coosemans __asm __volatile(" \n\
39681bd5041STijl Coosemans repne \n\
39781bd5041STijl Coosemans movsw" :
39881bd5041STijl Coosemans "=D" (addr), "=c" (count), "=S" (_port_) :
39981bd5041STijl Coosemans "0" (addr), "1" (count), "2" (_port_) :
40081bd5041STijl Coosemans "memory", "cc");
40181bd5041STijl Coosemans }
40281bd5041STijl Coosemans }
40381bd5041STijl Coosemans
40481bd5041STijl Coosemans static __inline void
bus_space_read_region_4(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int32_t * addr,size_t count)40581bd5041STijl Coosemans bus_space_read_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
40681bd5041STijl Coosemans bus_size_t offset, u_int32_t *addr, size_t count)
40781bd5041STijl Coosemans {
40881bd5041STijl Coosemans
40981bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO) {
41081bd5041STijl Coosemans int _port_ = bsh + offset;
41181bd5041STijl Coosemans __asm __volatile(" \n\
41281bd5041STijl Coosemans 1: inl %w2,%%eax \n\
41381bd5041STijl Coosemans stosl \n\
41481bd5041STijl Coosemans addl $4,%2 \n\
41581bd5041STijl Coosemans loop 1b" :
41681bd5041STijl Coosemans "=D" (addr), "=c" (count), "=d" (_port_) :
41781bd5041STijl Coosemans "0" (addr), "1" (count), "2" (_port_) :
41881bd5041STijl Coosemans "%eax", "memory", "cc");
41981bd5041STijl Coosemans } else {
42081bd5041STijl Coosemans bus_space_handle_t _port_ = bsh + offset;
42181bd5041STijl Coosemans __asm __volatile(" \n\
42281bd5041STijl Coosemans repne \n\
42381bd5041STijl Coosemans movsl" :
42481bd5041STijl Coosemans "=D" (addr), "=c" (count), "=S" (_port_) :
42581bd5041STijl Coosemans "0" (addr), "1" (count), "2" (_port_) :
42681bd5041STijl Coosemans "memory", "cc");
42781bd5041STijl Coosemans }
42881bd5041STijl Coosemans }
42981bd5041STijl Coosemans
430f2fcc434SJim Harris #if 0 /* Cause a link error for bus_space_read_region_8 */
431f2fcc434SJim Harris #define bus_space_read_region_8 !!! bus_space_read_region_8 unimplemented !!!
432f2fcc434SJim Harris #endif
433f2fcc434SJim Harris
43481bd5041STijl Coosemans /*
43581bd5041STijl Coosemans * Write the 1, 2, 4, or 8 byte value `value' to bus space
43681bd5041STijl Coosemans * described by tag/handle/offset.
43781bd5041STijl Coosemans */
43881bd5041STijl Coosemans
43981bd5041STijl Coosemans static __inline void bus_space_write_1(bus_space_tag_t tag,
44081bd5041STijl Coosemans bus_space_handle_t bsh,
44181bd5041STijl Coosemans bus_size_t offset, u_int8_t value);
44281bd5041STijl Coosemans
44381bd5041STijl Coosemans static __inline void bus_space_write_2(bus_space_tag_t tag,
44481bd5041STijl Coosemans bus_space_handle_t bsh,
44581bd5041STijl Coosemans bus_size_t offset, u_int16_t value);
44681bd5041STijl Coosemans
44781bd5041STijl Coosemans static __inline void bus_space_write_4(bus_space_tag_t tag,
44881bd5041STijl Coosemans bus_space_handle_t bsh,
44981bd5041STijl Coosemans bus_size_t offset, u_int32_t value);
45081bd5041STijl Coosemans
4517b332f20SJim Harris #ifdef __amd64__
4527b332f20SJim Harris static __inline void bus_space_write_8(bus_space_tag_t tag,
4537b332f20SJim Harris bus_space_handle_t bsh,
4547b332f20SJim Harris bus_size_t offset, uint64_t value);
4557b332f20SJim Harris #endif
4567b332f20SJim Harris
45781bd5041STijl Coosemans static __inline void
bus_space_write_1(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int8_t value)45881bd5041STijl Coosemans bus_space_write_1(bus_space_tag_t tag, bus_space_handle_t bsh,
45981bd5041STijl Coosemans bus_size_t offset, u_int8_t value)
46081bd5041STijl Coosemans {
46181bd5041STijl Coosemans
46281bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
46381bd5041STijl Coosemans outb(bsh + offset, value);
46481bd5041STijl Coosemans else
46581bd5041STijl Coosemans *(volatile u_int8_t *)(bsh + offset) = value;
46681bd5041STijl Coosemans }
46781bd5041STijl Coosemans
46881bd5041STijl Coosemans static __inline void
bus_space_write_2(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int16_t value)46981bd5041STijl Coosemans bus_space_write_2(bus_space_tag_t tag, bus_space_handle_t bsh,
47081bd5041STijl Coosemans bus_size_t offset, u_int16_t value)
47181bd5041STijl Coosemans {
47281bd5041STijl Coosemans
47381bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
47481bd5041STijl Coosemans outw(bsh + offset, value);
47581bd5041STijl Coosemans else
47681bd5041STijl Coosemans *(volatile u_int16_t *)(bsh + offset) = value;
47781bd5041STijl Coosemans }
47881bd5041STijl Coosemans
47981bd5041STijl Coosemans static __inline void
bus_space_write_4(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int32_t value)48081bd5041STijl Coosemans bus_space_write_4(bus_space_tag_t tag, bus_space_handle_t bsh,
48181bd5041STijl Coosemans bus_size_t offset, u_int32_t value)
48281bd5041STijl Coosemans {
48381bd5041STijl Coosemans
48481bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
48581bd5041STijl Coosemans outl(bsh + offset, value);
48681bd5041STijl Coosemans else
48781bd5041STijl Coosemans *(volatile u_int32_t *)(bsh + offset) = value;
48881bd5041STijl Coosemans }
48981bd5041STijl Coosemans
4907b332f20SJim Harris #ifdef __amd64__
4917b332f20SJim Harris static __inline void
bus_space_write_8(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,uint64_t value)4927b332f20SJim Harris bus_space_write_8(bus_space_tag_t tag, bus_space_handle_t bsh,
4937b332f20SJim Harris bus_size_t offset, uint64_t value)
4947b332f20SJim Harris {
4957b332f20SJim Harris
4967b332f20SJim Harris if (tag == X86_BUS_SPACE_IO) /* No 8 byte IO space access on x86 */
4977b332f20SJim Harris return;
4987b332f20SJim Harris else
4997b332f20SJim Harris *(volatile uint64_t *)(bsh + offset) = value;
5007b332f20SJim Harris }
501f2fcc434SJim Harris #endif
502f2fcc434SJim Harris
50381bd5041STijl Coosemans /*
50481bd5041STijl Coosemans * Write `count' 1, 2, 4, or 8 byte quantities from the buffer
50581bd5041STijl Coosemans * provided to bus space described by tag/handle/offset.
50681bd5041STijl Coosemans */
50781bd5041STijl Coosemans
50881bd5041STijl Coosemans static __inline void bus_space_write_multi_1(bus_space_tag_t tag,
50981bd5041STijl Coosemans bus_space_handle_t bsh,
51081bd5041STijl Coosemans bus_size_t offset,
51181bd5041STijl Coosemans const u_int8_t *addr,
51281bd5041STijl Coosemans size_t count);
51381bd5041STijl Coosemans static __inline void bus_space_write_multi_2(bus_space_tag_t tag,
51481bd5041STijl Coosemans bus_space_handle_t bsh,
51581bd5041STijl Coosemans bus_size_t offset,
51681bd5041STijl Coosemans const u_int16_t *addr,
51781bd5041STijl Coosemans size_t count);
51881bd5041STijl Coosemans
51981bd5041STijl Coosemans static __inline void bus_space_write_multi_4(bus_space_tag_t tag,
52081bd5041STijl Coosemans bus_space_handle_t bsh,
52181bd5041STijl Coosemans bus_size_t offset,
52281bd5041STijl Coosemans const u_int32_t *addr,
52381bd5041STijl Coosemans size_t count);
52481bd5041STijl Coosemans
52581bd5041STijl Coosemans static __inline void
bus_space_write_multi_1(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,const u_int8_t * addr,size_t count)52681bd5041STijl Coosemans bus_space_write_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
52781bd5041STijl Coosemans bus_size_t offset, const u_int8_t *addr, size_t count)
52881bd5041STijl Coosemans {
52981bd5041STijl Coosemans
53081bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
53181bd5041STijl Coosemans outsb(bsh + offset, addr, count);
53281bd5041STijl Coosemans else {
53381bd5041STijl Coosemans __asm __volatile(" \n\
53481bd5041STijl Coosemans 1: lodsb \n\
53581bd5041STijl Coosemans movb %%al,(%2) \n\
53681bd5041STijl Coosemans loop 1b" :
53781bd5041STijl Coosemans "=S" (addr), "=c" (count) :
53881bd5041STijl Coosemans "r" (bsh + offset), "0" (addr), "1" (count) :
53981bd5041STijl Coosemans "%eax", "memory", "cc");
54081bd5041STijl Coosemans }
54181bd5041STijl Coosemans }
54281bd5041STijl Coosemans
54381bd5041STijl Coosemans static __inline void
bus_space_write_multi_2(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,const u_int16_t * addr,size_t count)54481bd5041STijl Coosemans bus_space_write_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
54581bd5041STijl Coosemans bus_size_t offset, const u_int16_t *addr, size_t count)
54681bd5041STijl Coosemans {
54781bd5041STijl Coosemans
54881bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
54981bd5041STijl Coosemans outsw(bsh + offset, addr, count);
55081bd5041STijl Coosemans else {
55181bd5041STijl Coosemans __asm __volatile(" \n\
55281bd5041STijl Coosemans 1: lodsw \n\
55381bd5041STijl Coosemans movw %%ax,(%2) \n\
55481bd5041STijl Coosemans loop 1b" :
55581bd5041STijl Coosemans "=S" (addr), "=c" (count) :
55681bd5041STijl Coosemans "r" (bsh + offset), "0" (addr), "1" (count) :
55781bd5041STijl Coosemans "%eax", "memory", "cc");
55881bd5041STijl Coosemans }
55981bd5041STijl Coosemans }
56081bd5041STijl Coosemans
56181bd5041STijl Coosemans static __inline void
bus_space_write_multi_4(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,const u_int32_t * addr,size_t count)56281bd5041STijl Coosemans bus_space_write_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
56381bd5041STijl Coosemans bus_size_t offset, const u_int32_t *addr, size_t count)
56481bd5041STijl Coosemans {
56581bd5041STijl Coosemans
56681bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
56781bd5041STijl Coosemans outsl(bsh + offset, addr, count);
56881bd5041STijl Coosemans else {
56981bd5041STijl Coosemans __asm __volatile(" \n\
57081bd5041STijl Coosemans 1: lodsl \n\
57181bd5041STijl Coosemans movl %%eax,(%2) \n\
57281bd5041STijl Coosemans loop 1b" :
57381bd5041STijl Coosemans "=S" (addr), "=c" (count) :
57481bd5041STijl Coosemans "r" (bsh + offset), "0" (addr), "1" (count) :
57581bd5041STijl Coosemans "%eax", "memory", "cc");
57681bd5041STijl Coosemans }
57781bd5041STijl Coosemans }
57881bd5041STijl Coosemans
579f2fcc434SJim Harris #if 0 /* Cause a link error for bus_space_write_multi_8 */
580f2fcc434SJim Harris #define bus_space_write_multi_8(t, h, o, a, c) \
581f2fcc434SJim Harris !!! bus_space_write_multi_8 unimplemented !!!
582f2fcc434SJim Harris #endif
583f2fcc434SJim Harris
58481bd5041STijl Coosemans /*
58581bd5041STijl Coosemans * Write `count' 1, 2, 4, or 8 byte quantities from the buffer provided
58681bd5041STijl Coosemans * to bus space described by tag/handle starting at `offset'.
58781bd5041STijl Coosemans */
58881bd5041STijl Coosemans
58981bd5041STijl Coosemans static __inline void bus_space_write_region_1(bus_space_tag_t tag,
59081bd5041STijl Coosemans bus_space_handle_t bsh,
59181bd5041STijl Coosemans bus_size_t offset,
59281bd5041STijl Coosemans const u_int8_t *addr,
59381bd5041STijl Coosemans size_t count);
59481bd5041STijl Coosemans static __inline void bus_space_write_region_2(bus_space_tag_t tag,
59581bd5041STijl Coosemans bus_space_handle_t bsh,
59681bd5041STijl Coosemans bus_size_t offset,
59781bd5041STijl Coosemans const u_int16_t *addr,
59881bd5041STijl Coosemans size_t count);
59981bd5041STijl Coosemans static __inline void bus_space_write_region_4(bus_space_tag_t tag,
60081bd5041STijl Coosemans bus_space_handle_t bsh,
60181bd5041STijl Coosemans bus_size_t offset,
60281bd5041STijl Coosemans const u_int32_t *addr,
60381bd5041STijl Coosemans size_t count);
60481bd5041STijl Coosemans
60581bd5041STijl Coosemans static __inline void
bus_space_write_region_1(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,const u_int8_t * addr,size_t count)60681bd5041STijl Coosemans bus_space_write_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
60781bd5041STijl Coosemans bus_size_t offset, const u_int8_t *addr, size_t count)
60881bd5041STijl Coosemans {
60981bd5041STijl Coosemans
61081bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO) {
61181bd5041STijl Coosemans int _port_ = bsh + offset;
61281bd5041STijl Coosemans __asm __volatile(" \n\
61381bd5041STijl Coosemans 1: lodsb \n\
61481bd5041STijl Coosemans outb %%al,%w0 \n\
61581bd5041STijl Coosemans incl %0 \n\
61681bd5041STijl Coosemans loop 1b" :
61781bd5041STijl Coosemans "=d" (_port_), "=S" (addr), "=c" (count) :
61881bd5041STijl Coosemans "0" (_port_), "1" (addr), "2" (count) :
61981bd5041STijl Coosemans "%eax", "memory", "cc");
62081bd5041STijl Coosemans } else {
62181bd5041STijl Coosemans bus_space_handle_t _port_ = bsh + offset;
62281bd5041STijl Coosemans __asm __volatile(" \n\
62381bd5041STijl Coosemans repne \n\
62481bd5041STijl Coosemans movsb" :
62581bd5041STijl Coosemans "=D" (_port_), "=S" (addr), "=c" (count) :
62681bd5041STijl Coosemans "0" (_port_), "1" (addr), "2" (count) :
62781bd5041STijl Coosemans "memory", "cc");
62881bd5041STijl Coosemans }
62981bd5041STijl Coosemans }
63081bd5041STijl Coosemans
63181bd5041STijl Coosemans static __inline void
bus_space_write_region_2(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,const u_int16_t * addr,size_t count)63281bd5041STijl Coosemans bus_space_write_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
63381bd5041STijl Coosemans bus_size_t offset, const u_int16_t *addr, size_t count)
63481bd5041STijl Coosemans {
63581bd5041STijl Coosemans
63681bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO) {
63781bd5041STijl Coosemans int _port_ = bsh + offset;
63881bd5041STijl Coosemans __asm __volatile(" \n\
63981bd5041STijl Coosemans 1: lodsw \n\
64081bd5041STijl Coosemans outw %%ax,%w0 \n\
64181bd5041STijl Coosemans addl $2,%0 \n\
64281bd5041STijl Coosemans loop 1b" :
64381bd5041STijl Coosemans "=d" (_port_), "=S" (addr), "=c" (count) :
64481bd5041STijl Coosemans "0" (_port_), "1" (addr), "2" (count) :
64581bd5041STijl Coosemans "%eax", "memory", "cc");
64681bd5041STijl Coosemans } else {
64781bd5041STijl Coosemans bus_space_handle_t _port_ = bsh + offset;
64881bd5041STijl Coosemans __asm __volatile(" \n\
64981bd5041STijl Coosemans repne \n\
65081bd5041STijl Coosemans movsw" :
65181bd5041STijl Coosemans "=D" (_port_), "=S" (addr), "=c" (count) :
65281bd5041STijl Coosemans "0" (_port_), "1" (addr), "2" (count) :
65381bd5041STijl Coosemans "memory", "cc");
65481bd5041STijl Coosemans }
65581bd5041STijl Coosemans }
65681bd5041STijl Coosemans
65781bd5041STijl Coosemans static __inline void
bus_space_write_region_4(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,const u_int32_t * addr,size_t count)65881bd5041STijl Coosemans bus_space_write_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
65981bd5041STijl Coosemans bus_size_t offset, const u_int32_t *addr, size_t count)
66081bd5041STijl Coosemans {
66181bd5041STijl Coosemans
66281bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO) {
66381bd5041STijl Coosemans int _port_ = bsh + offset;
66481bd5041STijl Coosemans __asm __volatile(" \n\
66581bd5041STijl Coosemans 1: lodsl \n\
66681bd5041STijl Coosemans outl %%eax,%w0 \n\
66781bd5041STijl Coosemans addl $4,%0 \n\
66881bd5041STijl Coosemans loop 1b" :
66981bd5041STijl Coosemans "=d" (_port_), "=S" (addr), "=c" (count) :
67081bd5041STijl Coosemans "0" (_port_), "1" (addr), "2" (count) :
67181bd5041STijl Coosemans "%eax", "memory", "cc");
67281bd5041STijl Coosemans } else {
67381bd5041STijl Coosemans bus_space_handle_t _port_ = bsh + offset;
67481bd5041STijl Coosemans __asm __volatile(" \n\
67581bd5041STijl Coosemans repne \n\
67681bd5041STijl Coosemans movsl" :
67781bd5041STijl Coosemans "=D" (_port_), "=S" (addr), "=c" (count) :
67881bd5041STijl Coosemans "0" (_port_), "1" (addr), "2" (count) :
67981bd5041STijl Coosemans "memory", "cc");
68081bd5041STijl Coosemans }
68181bd5041STijl Coosemans }
68281bd5041STijl Coosemans
683f2fcc434SJim Harris #if 0 /* Cause a link error for bus_space_write_region_8 */
684f2fcc434SJim Harris #define bus_space_write_region_8 \
685f2fcc434SJim Harris !!! bus_space_write_region_8 unimplemented !!!
686f2fcc434SJim Harris #endif
687f2fcc434SJim Harris
68881bd5041STijl Coosemans /*
68981bd5041STijl Coosemans * Write the 1, 2, 4, or 8 byte value `val' to bus space described
69081bd5041STijl Coosemans * by tag/handle/offset `count' times.
69181bd5041STijl Coosemans */
69281bd5041STijl Coosemans
69381bd5041STijl Coosemans static __inline void bus_space_set_multi_1(bus_space_tag_t tag,
69481bd5041STijl Coosemans bus_space_handle_t bsh,
69581bd5041STijl Coosemans bus_size_t offset,
69681bd5041STijl Coosemans u_int8_t value, size_t count);
69781bd5041STijl Coosemans static __inline void bus_space_set_multi_2(bus_space_tag_t tag,
69881bd5041STijl Coosemans bus_space_handle_t bsh,
69981bd5041STijl Coosemans bus_size_t offset,
70081bd5041STijl Coosemans u_int16_t value, size_t count);
70181bd5041STijl Coosemans static __inline void bus_space_set_multi_4(bus_space_tag_t tag,
70281bd5041STijl Coosemans bus_space_handle_t bsh,
70381bd5041STijl Coosemans bus_size_t offset,
70481bd5041STijl Coosemans u_int32_t value, size_t count);
70581bd5041STijl Coosemans
70681bd5041STijl Coosemans static __inline void
bus_space_set_multi_1(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int8_t value,size_t count)70781bd5041STijl Coosemans bus_space_set_multi_1(bus_space_tag_t tag, bus_space_handle_t bsh,
70881bd5041STijl Coosemans bus_size_t offset, u_int8_t value, size_t count)
70981bd5041STijl Coosemans {
71081bd5041STijl Coosemans bus_space_handle_t addr = bsh + offset;
71181bd5041STijl Coosemans
71281bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
71381bd5041STijl Coosemans while (count--)
71481bd5041STijl Coosemans outb(addr, value);
71581bd5041STijl Coosemans else
71681bd5041STijl Coosemans while (count--)
71781bd5041STijl Coosemans *(volatile u_int8_t *)(addr) = value;
71881bd5041STijl Coosemans }
71981bd5041STijl Coosemans
72081bd5041STijl Coosemans static __inline void
bus_space_set_multi_2(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int16_t value,size_t count)72181bd5041STijl Coosemans bus_space_set_multi_2(bus_space_tag_t tag, bus_space_handle_t bsh,
72281bd5041STijl Coosemans bus_size_t offset, u_int16_t value, size_t count)
72381bd5041STijl Coosemans {
72481bd5041STijl Coosemans bus_space_handle_t addr = bsh + offset;
72581bd5041STijl Coosemans
72681bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
72781bd5041STijl Coosemans while (count--)
72881bd5041STijl Coosemans outw(addr, value);
72981bd5041STijl Coosemans else
73081bd5041STijl Coosemans while (count--)
73181bd5041STijl Coosemans *(volatile u_int16_t *)(addr) = value;
73281bd5041STijl Coosemans }
73381bd5041STijl Coosemans
73481bd5041STijl Coosemans static __inline void
bus_space_set_multi_4(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int32_t value,size_t count)73581bd5041STijl Coosemans bus_space_set_multi_4(bus_space_tag_t tag, bus_space_handle_t bsh,
73681bd5041STijl Coosemans bus_size_t offset, u_int32_t value, size_t count)
73781bd5041STijl Coosemans {
73881bd5041STijl Coosemans bus_space_handle_t addr = bsh + offset;
73981bd5041STijl Coosemans
74081bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
74181bd5041STijl Coosemans while (count--)
74281bd5041STijl Coosemans outl(addr, value);
74381bd5041STijl Coosemans else
74481bd5041STijl Coosemans while (count--)
74581bd5041STijl Coosemans *(volatile u_int32_t *)(addr) = value;
74681bd5041STijl Coosemans }
74781bd5041STijl Coosemans
748f2fcc434SJim Harris #if 0 /* Cause a link error for bus_space_set_multi_8 */
749f2fcc434SJim Harris #define bus_space_set_multi_8 !!! bus_space_set_multi_8 unimplemented !!!
750f2fcc434SJim Harris #endif
751f2fcc434SJim Harris
75281bd5041STijl Coosemans /*
75381bd5041STijl Coosemans * Write `count' 1, 2, 4, or 8 byte value `val' to bus space described
75481bd5041STijl Coosemans * by tag/handle starting at `offset'.
75581bd5041STijl Coosemans */
75681bd5041STijl Coosemans
75781bd5041STijl Coosemans static __inline void bus_space_set_region_1(bus_space_tag_t tag,
75881bd5041STijl Coosemans bus_space_handle_t bsh,
75981bd5041STijl Coosemans bus_size_t offset, u_int8_t value,
76081bd5041STijl Coosemans size_t count);
76181bd5041STijl Coosemans static __inline void bus_space_set_region_2(bus_space_tag_t tag,
76281bd5041STijl Coosemans bus_space_handle_t bsh,
76381bd5041STijl Coosemans bus_size_t offset, u_int16_t value,
76481bd5041STijl Coosemans size_t count);
76581bd5041STijl Coosemans static __inline void bus_space_set_region_4(bus_space_tag_t tag,
76681bd5041STijl Coosemans bus_space_handle_t bsh,
76781bd5041STijl Coosemans bus_size_t offset, u_int32_t value,
76881bd5041STijl Coosemans size_t count);
76981bd5041STijl Coosemans
77081bd5041STijl Coosemans static __inline void
bus_space_set_region_1(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int8_t value,size_t count)77181bd5041STijl Coosemans bus_space_set_region_1(bus_space_tag_t tag, bus_space_handle_t bsh,
77281bd5041STijl Coosemans bus_size_t offset, u_int8_t value, size_t count)
77381bd5041STijl Coosemans {
77481bd5041STijl Coosemans bus_space_handle_t addr = bsh + offset;
77581bd5041STijl Coosemans
77681bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
77781bd5041STijl Coosemans for (; count != 0; count--, addr++)
77881bd5041STijl Coosemans outb(addr, value);
77981bd5041STijl Coosemans else
78081bd5041STijl Coosemans for (; count != 0; count--, addr++)
78181bd5041STijl Coosemans *(volatile u_int8_t *)(addr) = value;
78281bd5041STijl Coosemans }
78381bd5041STijl Coosemans
78481bd5041STijl Coosemans static __inline void
bus_space_set_region_2(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int16_t value,size_t count)78581bd5041STijl Coosemans bus_space_set_region_2(bus_space_tag_t tag, bus_space_handle_t bsh,
78681bd5041STijl Coosemans bus_size_t offset, u_int16_t value, size_t count)
78781bd5041STijl Coosemans {
78881bd5041STijl Coosemans bus_space_handle_t addr = bsh + offset;
78981bd5041STijl Coosemans
79081bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
79181bd5041STijl Coosemans for (; count != 0; count--, addr += 2)
79281bd5041STijl Coosemans outw(addr, value);
79381bd5041STijl Coosemans else
79481bd5041STijl Coosemans for (; count != 0; count--, addr += 2)
79581bd5041STijl Coosemans *(volatile u_int16_t *)(addr) = value;
79681bd5041STijl Coosemans }
79781bd5041STijl Coosemans
79881bd5041STijl Coosemans static __inline void
bus_space_set_region_4(bus_space_tag_t tag,bus_space_handle_t bsh,bus_size_t offset,u_int32_t value,size_t count)79981bd5041STijl Coosemans bus_space_set_region_4(bus_space_tag_t tag, bus_space_handle_t bsh,
80081bd5041STijl Coosemans bus_size_t offset, u_int32_t value, size_t count)
80181bd5041STijl Coosemans {
80281bd5041STijl Coosemans bus_space_handle_t addr = bsh + offset;
80381bd5041STijl Coosemans
80481bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO)
80581bd5041STijl Coosemans for (; count != 0; count--, addr += 4)
80681bd5041STijl Coosemans outl(addr, value);
80781bd5041STijl Coosemans else
80881bd5041STijl Coosemans for (; count != 0; count--, addr += 4)
80981bd5041STijl Coosemans *(volatile u_int32_t *)(addr) = value;
81081bd5041STijl Coosemans }
81181bd5041STijl Coosemans
812f2fcc434SJim Harris #if 0 /* Cause a link error for bus_space_set_region_8 */
813f2fcc434SJim Harris #define bus_space_set_region_8 !!! bus_space_set_region_8 unimplemented !!!
814f2fcc434SJim Harris #endif
815f2fcc434SJim Harris
81681bd5041STijl Coosemans /*
81781bd5041STijl Coosemans * Copy `count' 1, 2, 4, or 8 byte values from bus space starting
81881bd5041STijl Coosemans * at tag/bsh1/off1 to bus space starting at tag/bsh2/off2.
81981bd5041STijl Coosemans */
82081bd5041STijl Coosemans
82181bd5041STijl Coosemans static __inline void bus_space_copy_region_1(bus_space_tag_t tag,
82281bd5041STijl Coosemans bus_space_handle_t bsh1,
82381bd5041STijl Coosemans bus_size_t off1,
82481bd5041STijl Coosemans bus_space_handle_t bsh2,
82581bd5041STijl Coosemans bus_size_t off2, size_t count);
82681bd5041STijl Coosemans
82781bd5041STijl Coosemans static __inline void bus_space_copy_region_2(bus_space_tag_t tag,
82881bd5041STijl Coosemans bus_space_handle_t bsh1,
82981bd5041STijl Coosemans bus_size_t off1,
83081bd5041STijl Coosemans bus_space_handle_t bsh2,
83181bd5041STijl Coosemans bus_size_t off2, size_t count);
83281bd5041STijl Coosemans
83381bd5041STijl Coosemans static __inline void bus_space_copy_region_4(bus_space_tag_t tag,
83481bd5041STijl Coosemans bus_space_handle_t bsh1,
83581bd5041STijl Coosemans bus_size_t off1,
83681bd5041STijl Coosemans bus_space_handle_t bsh2,
83781bd5041STijl Coosemans bus_size_t off2, size_t count);
83881bd5041STijl Coosemans
83981bd5041STijl Coosemans static __inline void
bus_space_copy_region_1(bus_space_tag_t tag,bus_space_handle_t bsh1,bus_size_t off1,bus_space_handle_t bsh2,bus_size_t off2,size_t count)84081bd5041STijl Coosemans bus_space_copy_region_1(bus_space_tag_t tag, bus_space_handle_t bsh1,
84181bd5041STijl Coosemans bus_size_t off1, bus_space_handle_t bsh2,
84281bd5041STijl Coosemans bus_size_t off2, size_t count)
84381bd5041STijl Coosemans {
84481bd5041STijl Coosemans bus_space_handle_t addr1 = bsh1 + off1;
84581bd5041STijl Coosemans bus_space_handle_t addr2 = bsh2 + off2;
84681bd5041STijl Coosemans
84781bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO) {
84881bd5041STijl Coosemans if (addr1 >= addr2) {
84981bd5041STijl Coosemans /* src after dest: copy forward */
85081bd5041STijl Coosemans for (; count != 0; count--, addr1++, addr2++)
85181bd5041STijl Coosemans outb(addr2, inb(addr1));
85281bd5041STijl Coosemans } else {
85381bd5041STijl Coosemans /* dest after src: copy backwards */
85481bd5041STijl Coosemans for (addr1 += (count - 1), addr2 += (count - 1);
85581bd5041STijl Coosemans count != 0; count--, addr1--, addr2--)
85681bd5041STijl Coosemans outb(addr2, inb(addr1));
85781bd5041STijl Coosemans }
85881bd5041STijl Coosemans } else {
85981bd5041STijl Coosemans if (addr1 >= addr2) {
86081bd5041STijl Coosemans /* src after dest: copy forward */
86181bd5041STijl Coosemans for (; count != 0; count--, addr1++, addr2++)
86281bd5041STijl Coosemans *(volatile u_int8_t *)(addr2) =
86381bd5041STijl Coosemans *(volatile u_int8_t *)(addr1);
86481bd5041STijl Coosemans } else {
86581bd5041STijl Coosemans /* dest after src: copy backwards */
86681bd5041STijl Coosemans for (addr1 += (count - 1), addr2 += (count - 1);
86781bd5041STijl Coosemans count != 0; count--, addr1--, addr2--)
86881bd5041STijl Coosemans *(volatile u_int8_t *)(addr2) =
86981bd5041STijl Coosemans *(volatile u_int8_t *)(addr1);
87081bd5041STijl Coosemans }
87181bd5041STijl Coosemans }
87281bd5041STijl Coosemans }
87381bd5041STijl Coosemans
87481bd5041STijl Coosemans static __inline void
bus_space_copy_region_2(bus_space_tag_t tag,bus_space_handle_t bsh1,bus_size_t off1,bus_space_handle_t bsh2,bus_size_t off2,size_t count)87581bd5041STijl Coosemans bus_space_copy_region_2(bus_space_tag_t tag, bus_space_handle_t bsh1,
87681bd5041STijl Coosemans bus_size_t off1, bus_space_handle_t bsh2,
87781bd5041STijl Coosemans bus_size_t off2, size_t count)
87881bd5041STijl Coosemans {
87981bd5041STijl Coosemans bus_space_handle_t addr1 = bsh1 + off1;
88081bd5041STijl Coosemans bus_space_handle_t addr2 = bsh2 + off2;
88181bd5041STijl Coosemans
88281bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO) {
88381bd5041STijl Coosemans if (addr1 >= addr2) {
88481bd5041STijl Coosemans /* src after dest: copy forward */
88581bd5041STijl Coosemans for (; count != 0; count--, addr1 += 2, addr2 += 2)
88681bd5041STijl Coosemans outw(addr2, inw(addr1));
88781bd5041STijl Coosemans } else {
88881bd5041STijl Coosemans /* dest after src: copy backwards */
88981bd5041STijl Coosemans for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
89081bd5041STijl Coosemans count != 0; count--, addr1 -= 2, addr2 -= 2)
89181bd5041STijl Coosemans outw(addr2, inw(addr1));
89281bd5041STijl Coosemans }
89381bd5041STijl Coosemans } else {
89481bd5041STijl Coosemans if (addr1 >= addr2) {
89581bd5041STijl Coosemans /* src after dest: copy forward */
89681bd5041STijl Coosemans for (; count != 0; count--, addr1 += 2, addr2 += 2)
89781bd5041STijl Coosemans *(volatile u_int16_t *)(addr2) =
89881bd5041STijl Coosemans *(volatile u_int16_t *)(addr1);
89981bd5041STijl Coosemans } else {
90081bd5041STijl Coosemans /* dest after src: copy backwards */
90181bd5041STijl Coosemans for (addr1 += 2 * (count - 1), addr2 += 2 * (count - 1);
90281bd5041STijl Coosemans count != 0; count--, addr1 -= 2, addr2 -= 2)
90381bd5041STijl Coosemans *(volatile u_int16_t *)(addr2) =
90481bd5041STijl Coosemans *(volatile u_int16_t *)(addr1);
90581bd5041STijl Coosemans }
90681bd5041STijl Coosemans }
90781bd5041STijl Coosemans }
90881bd5041STijl Coosemans
90981bd5041STijl Coosemans static __inline void
bus_space_copy_region_4(bus_space_tag_t tag,bus_space_handle_t bsh1,bus_size_t off1,bus_space_handle_t bsh2,bus_size_t off2,size_t count)91081bd5041STijl Coosemans bus_space_copy_region_4(bus_space_tag_t tag, bus_space_handle_t bsh1,
91181bd5041STijl Coosemans bus_size_t off1, bus_space_handle_t bsh2,
91281bd5041STijl Coosemans bus_size_t off2, size_t count)
91381bd5041STijl Coosemans {
91481bd5041STijl Coosemans bus_space_handle_t addr1 = bsh1 + off1;
91581bd5041STijl Coosemans bus_space_handle_t addr2 = bsh2 + off2;
91681bd5041STijl Coosemans
91781bd5041STijl Coosemans if (tag == X86_BUS_SPACE_IO) {
91881bd5041STijl Coosemans if (addr1 >= addr2) {
91981bd5041STijl Coosemans /* src after dest: copy forward */
92081bd5041STijl Coosemans for (; count != 0; count--, addr1 += 4, addr2 += 4)
92181bd5041STijl Coosemans outl(addr2, inl(addr1));
92281bd5041STijl Coosemans } else {
92381bd5041STijl Coosemans /* dest after src: copy backwards */
92481bd5041STijl Coosemans for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
92581bd5041STijl Coosemans count != 0; count--, addr1 -= 4, addr2 -= 4)
92681bd5041STijl Coosemans outl(addr2, inl(addr1));
92781bd5041STijl Coosemans }
92881bd5041STijl Coosemans } else {
92981bd5041STijl Coosemans if (addr1 >= addr2) {
93081bd5041STijl Coosemans /* src after dest: copy forward */
93181bd5041STijl Coosemans for (; count != 0; count--, addr1 += 4, addr2 += 4)
93281bd5041STijl Coosemans *(volatile u_int32_t *)(addr2) =
93381bd5041STijl Coosemans *(volatile u_int32_t *)(addr1);
93481bd5041STijl Coosemans } else {
93581bd5041STijl Coosemans /* dest after src: copy backwards */
93681bd5041STijl Coosemans for (addr1 += 4 * (count - 1), addr2 += 4 * (count - 1);
93781bd5041STijl Coosemans count != 0; count--, addr1 -= 4, addr2 -= 4)
93881bd5041STijl Coosemans *(volatile u_int32_t *)(addr2) =
93981bd5041STijl Coosemans *(volatile u_int32_t *)(addr1);
94081bd5041STijl Coosemans }
94181bd5041STijl Coosemans }
94281bd5041STijl Coosemans }
94381bd5041STijl Coosemans
944f2fcc434SJim Harris #if 0 /* Cause a link error for bus_space_copy_8 */
945f2fcc434SJim Harris #define bus_space_copy_region_8 !!! bus_space_copy_region_8 unimplemented !!!
946f2fcc434SJim Harris #endif
947f2fcc434SJim Harris
94881bd5041STijl Coosemans /*
94981bd5041STijl Coosemans * Bus read/write barrier methods.
95081bd5041STijl Coosemans *
95181bd5041STijl Coosemans * void bus_space_barrier(bus_space_tag_t tag, bus_space_handle_t bsh,
95281bd5041STijl Coosemans * bus_size_t offset, bus_size_t len, int flags);
95381bd5041STijl Coosemans *
95481bd5041STijl Coosemans *
95581bd5041STijl Coosemans * Note that BUS_SPACE_BARRIER_WRITE doesn't do anything other than
95681bd5041STijl Coosemans * prevent reordering by the compiler; all Intel x86 processors currently
95781bd5041STijl Coosemans * retire operations outside the CPU in program order.
95881bd5041STijl Coosemans */
95981bd5041STijl Coosemans static __inline void
bus_space_barrier(bus_space_tag_t tag __unused,bus_space_handle_t bsh __unused,bus_size_t offset __unused,bus_size_t len __unused,int flags)96081bd5041STijl Coosemans bus_space_barrier(bus_space_tag_t tag __unused, bus_space_handle_t bsh __unused,
96181bd5041STijl Coosemans bus_size_t offset __unused, bus_size_t len __unused, int flags)
96281bd5041STijl Coosemans {
96381bd5041STijl Coosemans if (flags & BUS_SPACE_BARRIER_READ)
96481bd5041STijl Coosemans #ifdef __amd64__
96581bd5041STijl Coosemans __asm __volatile("lock; addl $0,0(%%rsp)" : : : "memory");
96681bd5041STijl Coosemans #else
96781bd5041STijl Coosemans __asm __volatile("lock; addl $0,0(%%esp)" : : : "memory");
96881bd5041STijl Coosemans #endif
96981bd5041STijl Coosemans else
9703a473025SAttilio Rao __compiler_membar();
97181bd5041STijl Coosemans }
97281bd5041STijl Coosemans
97381bd5041STijl Coosemans #ifdef BUS_SPACE_NO_LEGACY
97481bd5041STijl Coosemans #undef inb
97581bd5041STijl Coosemans #undef outb
97681bd5041STijl Coosemans #define inb(a) compiler_error
97781bd5041STijl Coosemans #define inw(a) compiler_error
97881bd5041STijl Coosemans #define inl(a) compiler_error
97981bd5041STijl Coosemans #define outb(a, b) compiler_error
98081bd5041STijl Coosemans #define outw(a, b) compiler_error
98181bd5041STijl Coosemans #define outl(a, b) compiler_error
98281bd5041STijl Coosemans #endif
98381bd5041STijl Coosemans
98481bd5041STijl Coosemans /*
98581bd5041STijl Coosemans * Stream accesses are the same as normal accesses on x86; there are no
98681bd5041STijl Coosemans * supported bus systems with an endianess different from the host one.
98781bd5041STijl Coosemans */
98881bd5041STijl Coosemans #define bus_space_read_stream_1(t, h, o) bus_space_read_1((t), (h), (o))
98981bd5041STijl Coosemans #define bus_space_read_stream_2(t, h, o) bus_space_read_2((t), (h), (o))
99081bd5041STijl Coosemans #define bus_space_read_stream_4(t, h, o) bus_space_read_4((t), (h), (o))
99181bd5041STijl Coosemans
99281bd5041STijl Coosemans #define bus_space_read_multi_stream_1(t, h, o, a, c) \
99381bd5041STijl Coosemans bus_space_read_multi_1((t), (h), (o), (a), (c))
99481bd5041STijl Coosemans #define bus_space_read_multi_stream_2(t, h, o, a, c) \
99581bd5041STijl Coosemans bus_space_read_multi_2((t), (h), (o), (a), (c))
99681bd5041STijl Coosemans #define bus_space_read_multi_stream_4(t, h, o, a, c) \
99781bd5041STijl Coosemans bus_space_read_multi_4((t), (h), (o), (a), (c))
99881bd5041STijl Coosemans
99981bd5041STijl Coosemans #define bus_space_write_stream_1(t, h, o, v) \
100081bd5041STijl Coosemans bus_space_write_1((t), (h), (o), (v))
100181bd5041STijl Coosemans #define bus_space_write_stream_2(t, h, o, v) \
100281bd5041STijl Coosemans bus_space_write_2((t), (h), (o), (v))
100381bd5041STijl Coosemans #define bus_space_write_stream_4(t, h, o, v) \
100481bd5041STijl Coosemans bus_space_write_4((t), (h), (o), (v))
100581bd5041STijl Coosemans
100681bd5041STijl Coosemans #define bus_space_write_multi_stream_1(t, h, o, a, c) \
100781bd5041STijl Coosemans bus_space_write_multi_1((t), (h), (o), (a), (c))
100881bd5041STijl Coosemans #define bus_space_write_multi_stream_2(t, h, o, a, c) \
100981bd5041STijl Coosemans bus_space_write_multi_2((t), (h), (o), (a), (c))
101081bd5041STijl Coosemans #define bus_space_write_multi_stream_4(t, h, o, a, c) \
101181bd5041STijl Coosemans bus_space_write_multi_4((t), (h), (o), (a), (c))
101281bd5041STijl Coosemans
101381bd5041STijl Coosemans #define bus_space_set_multi_stream_1(t, h, o, v, c) \
101481bd5041STijl Coosemans bus_space_set_multi_1((t), (h), (o), (v), (c))
101581bd5041STijl Coosemans #define bus_space_set_multi_stream_2(t, h, o, v, c) \
101681bd5041STijl Coosemans bus_space_set_multi_2((t), (h), (o), (v), (c))
101781bd5041STijl Coosemans #define bus_space_set_multi_stream_4(t, h, o, v, c) \
101881bd5041STijl Coosemans bus_space_set_multi_4((t), (h), (o), (v), (c))
101981bd5041STijl Coosemans
102081bd5041STijl Coosemans #define bus_space_read_region_stream_1(t, h, o, a, c) \
102181bd5041STijl Coosemans bus_space_read_region_1((t), (h), (o), (a), (c))
102281bd5041STijl Coosemans #define bus_space_read_region_stream_2(t, h, o, a, c) \
102381bd5041STijl Coosemans bus_space_read_region_2((t), (h), (o), (a), (c))
102481bd5041STijl Coosemans #define bus_space_read_region_stream_4(t, h, o, a, c) \
102581bd5041STijl Coosemans bus_space_read_region_4((t), (h), (o), (a), (c))
102681bd5041STijl Coosemans
102781bd5041STijl Coosemans #define bus_space_write_region_stream_1(t, h, o, a, c) \
102881bd5041STijl Coosemans bus_space_write_region_1((t), (h), (o), (a), (c))
102981bd5041STijl Coosemans #define bus_space_write_region_stream_2(t, h, o, a, c) \
103081bd5041STijl Coosemans bus_space_write_region_2((t), (h), (o), (a), (c))
103181bd5041STijl Coosemans #define bus_space_write_region_stream_4(t, h, o, a, c) \
103281bd5041STijl Coosemans bus_space_write_region_4((t), (h), (o), (a), (c))
103381bd5041STijl Coosemans
103481bd5041STijl Coosemans #define bus_space_set_region_stream_1(t, h, o, v, c) \
103581bd5041STijl Coosemans bus_space_set_region_1((t), (h), (o), (v), (c))
103681bd5041STijl Coosemans #define bus_space_set_region_stream_2(t, h, o, v, c) \
103781bd5041STijl Coosemans bus_space_set_region_2((t), (h), (o), (v), (c))
103881bd5041STijl Coosemans #define bus_space_set_region_stream_4(t, h, o, v, c) \
103981bd5041STijl Coosemans bus_space_set_region_4((t), (h), (o), (v), (c))
104081bd5041STijl Coosemans
104181bd5041STijl Coosemans #define bus_space_copy_region_stream_1(t, h1, o1, h2, o2, c) \
104281bd5041STijl Coosemans bus_space_copy_region_1((t), (h1), (o1), (h2), (o2), (c))
104381bd5041STijl Coosemans #define bus_space_copy_region_stream_2(t, h1, o1, h2, o2, c) \
104481bd5041STijl Coosemans bus_space_copy_region_2((t), (h1), (o1), (h2), (o2), (c))
104581bd5041STijl Coosemans #define bus_space_copy_region_stream_4(t, h1, o1, h2, o2, c) \
104681bd5041STijl Coosemans bus_space_copy_region_4((t), (h1), (o1), (h2), (o2), (c))
104781bd5041STijl Coosemans
104895a85c12SMichal Meloun #define BUS_PEEK_FUNC(width, type) \
104995a85c12SMichal Meloun static inline int \
105095a85c12SMichal Meloun bus_space_peek_##width(bus_space_tag_t tag, \
105195a85c12SMichal Meloun bus_space_handle_t hnd, bus_size_t offset, type *value) \
105295a85c12SMichal Meloun { \
105395a85c12SMichal Meloun type tmp; \
105495a85c12SMichal Meloun tmp = bus_space_read_##width(tag, hnd, offset); \
105531820621SMichal Meloun *value = (type)tmp; \
105695a85c12SMichal Meloun return (0); \
105795a85c12SMichal Meloun }
105895a85c12SMichal Meloun BUS_PEEK_FUNC(1, uint8_t)
105995a85c12SMichal Meloun BUS_PEEK_FUNC(2, uint16_t)
106095a85c12SMichal Meloun BUS_PEEK_FUNC(4, uint32_t)
106188f7c52fSMichal Meloun #ifdef __amd64__
106288f7c52fSMichal Meloun BUS_PEEK_FUNC(8, uint64_t)
106388f7c52fSMichal Meloun #endif
106495a85c12SMichal Meloun
106595a85c12SMichal Meloun #define BUS_POKE_FUNC(width, type) \
106695a85c12SMichal Meloun static inline int \
106795a85c12SMichal Meloun bus_space_poke_##width(bus_space_tag_t tag, \
106895a85c12SMichal Meloun bus_space_handle_t hnd, bus_size_t offset, type value) \
106995a85c12SMichal Meloun { \
107095a85c12SMichal Meloun bus_space_write_##width(tag, hnd, offset, value); \
107195a85c12SMichal Meloun return (0); \
107295a85c12SMichal Meloun }
107395a85c12SMichal Meloun BUS_POKE_FUNC(1, uint8_t)
107495a85c12SMichal Meloun BUS_POKE_FUNC(2, uint16_t)
107595a85c12SMichal Meloun BUS_POKE_FUNC(4, uint32_t)
107688f7c52fSMichal Meloun #ifdef __amd64__
107788f7c52fSMichal Meloun BUS_POKE_FUNC(8, uint64_t)
107888f7c52fSMichal Meloun #endif
107995a85c12SMichal Meloun
1080a90d053bSMark Johnston #endif /* !SAN_NEEDS_INTERCEPTORS && SAN_RUNTIME */
1081849aef49SAndrew Turner
10823ead6023SMark Johnston #endif /* !_MACHINE_BUS_H_ */
1083