aboutsummaryrefslogtreecommitdiff
path: root/sys/amd64/include/bus.h
blob: 7594eb4e7826341e86d6581318e14221099124b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*-
 * Copyright (c) 2012 Intel Corporation
 * Copyright (c) 2009 Marcel Moolenaar
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#ifndef _MACHINE_BUS_H_
#define _MACHINE_BUS_H_

#include <sys/systm.h>
#include <x86/bus.h>

#define KASSERT_BUS_SPACE_MEM_ONLY(tag)                     \
	KASSERT((tag) == X86_BUS_SPACE_MEM,                 \
	    ("%s: can only handle mem space", __func__))

static __inline uint64_t
bus_space_read_8(bus_space_tag_t tag, bus_space_handle_t bsh,
    bus_size_t ofs)
{

	KASSERT_BUS_SPACE_MEM_ONLY(tag);

	return (*(volatile uint64_t *)(bsh + ofs));
}

static __inline void
bus_space_write_8(bus_space_tag_t tag, bus_space_handle_t bsh,
    bus_size_t ofs, uint64_t val)
{

	KASSERT_BUS_SPACE_MEM_ONLY(tag);

	*(volatile uint64_t *)(bsh + ofs) = val;
}

static __inline void
bus_space_read_region_8(bus_space_tag_t tag, bus_space_handle_t bsh,
    bus_size_t ofs, uint64_t *bufp, size_t count)
{
	volatile uint64_t *bsp;

	KASSERT_BUS_SPACE_MEM_ONLY(tag);

	bsp = (void *)(bsh + ofs);
	while (count-- > 0)
		*bufp++ = *bsp++;
}

static __inline void
bus_space_write_region_8(bus_space_tag_t tag, bus_space_handle_t bsh,
    bus_size_t ofs, uint64_t const *bufp, size_t count)
{
	volatile uint64_t *bsp;

	KASSERT_BUS_SPACE_MEM_ONLY(tag);

	bsp = (void *)(bsh + ofs);
	while (count-- > 0)
		*bsp++ = *bufp++;
}

static __inline void
bus_space_set_region_8(bus_space_tag_t tag, bus_space_handle_t bsh,
    bus_size_t ofs, uint64_t val, size_t count)
{
	volatile uint64_t *bsp;

	KASSERT_BUS_SPACE_MEM_ONLY(tag);

	bsp = (void *)(bsh + ofs);
	while (count-- > 0)
		*bsp++ = val;
}

static __inline void
bus_space_copy_region_8(bus_space_tag_t tag, bus_space_handle_t sbsh,
    bus_size_t sofs, bus_space_handle_t dbsh, bus_size_t dofs, size_t count)
{
	volatile uint64_t *dst, *src;

	KASSERT_BUS_SPACE_MEM_ONLY(tag);

	src = (void *)(sbsh + sofs);
	dst = (void *)(dbsh + dofs);
	if (src < dst) {
		src += count - 1;
		dst += count - 1;
		while (count-- > 0)
			*dst-- = *src--;
	} else {
		while (count-- > 0)
			*dst++ = *src++;
	}
}

static __inline void
bus_space_read_multi_8(bus_space_tag_t tag, bus_space_handle_t bsh,
    bus_size_t ofs, uint64_t *bufp, size_t count)
{

	KASSERT_BUS_SPACE_MEM_ONLY(tag);

	while (count-- > 0)
		*bufp++ = *(volatile uint64_t *)(bsh + ofs);
}

static __inline void
bus_space_write_multi_8(bus_space_tag_t tag, bus_space_handle_t bsh,
    bus_size_t ofs, uint64_t const *bufp, size_t count)
{

	KASSERT_BUS_SPACE_MEM_ONLY(tag);

	while (count-- > 0)
		*(volatile uint64_t *)(bsh + ofs) = *bufp++;
}

static __inline void
bus_space_set_multi_8(bus_space_tag_t tag, bus_space_handle_t bsh,
    bus_size_t ofs, uint64_t val, size_t count)
{

	KASSERT_BUS_SPACE_MEM_ONLY(tag);

	while (count-- > 0)
		*(volatile uint64_t *)(bsh + ofs) = val;
}

#endif /*_MACHINE_BUS_H_*/