aboutsummaryrefslogtreecommitdiff
path: root/src/northbridge/via/vx800/pci_rawops.h
blob: 7fabc3e105a9ef333a9e7ddb102effce66545312 (plain)
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*
 * This file is part of the coreboot project.
 *
 * Copyright (C) 2009 One Laptop per Child, Association, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

#ifndef ARCH_I386_PCI_RAWOPS_H
# define ARCH_I386_PCI_RAWOPS_H 1
#include <stdint.h>

#define PCI_RAWDEV(SEGBUS, DEV, FN) ( \
        (((SEGBUS) & 0xFFF) << 20) | \
        (((DEV) & 0x1F) << 15) | \
        (((FN)  & 0x07) << 12))

struct VIA_PCI_REG_INIT_TABLE {
	u8 ChipRevisionStart;
	u8 ChipRevisionEnd;
	u8 Bus;
	u8 Device;
	u8 Function;
	u32 Register;
	u8 Mask;
	u8 Value;
};

typedef unsigned device_t_raw;	/* pci and pci_mmio need to have different ways to have dev */

#warning "FIXME: get rid of this extra copy of pci access functions."

/* FIXME: We need to make the coreboot to run at 64bit mode, So when read/write memory above 4G,
 * We don't need to set %fs, and %gs anymore
 * Before that We need to use %gs, and leave %fs to other RAM access
 */
static u8 pci_io_rawread_config8(device_t_raw dev, unsigned where)
{
	unsigned addr;
#if CONFIG_PCI_IO_CFG_EXT == 0
	addr = (dev >> 4) | where;
#else
	addr = (dev >> 4) | (where & 0xff) | ((where & 0xf00) << 16);	//seg == 0
#endif
	outl(0x80000000 | (addr & ~3), 0xCF8);
	return inb(0xCFC + (addr & 3));
}

#if CONFIG_MMCONF_SUPPORT
static u8 pci_mmio_rawread_config8(device_t_raw dev, unsigned where)
{
	unsigned addr;
	addr = dev | where;
	return read8x(addr);
}
#endif
static u8 pci_rawread_config8(device_t_raw dev, unsigned where)
{
#if CONFIG_MMCONF_SUPPORT
	return pci_mmio_rawread_config8(dev, where);
#else
	return pci_io_rawread_config8(dev, where);
#endif
}

static u16 pci_io_rawread_config16(device_t_raw dev, unsigned where)
{
	unsigned addr;
#if CONFIG_PCI_IO_CFG_EXT == 0
	addr = (dev >> 4) | where;
#else
	addr = (dev >> 4) | (where & 0xff) | ((where & 0xf00) << 16);
#endif
	outl(0x80000000 | (addr & ~3), 0xCF8);
	return inw(0xCFC + (addr & 2));
}

#if CONFIG_MMCONF_SUPPORT
static u16 pci_mmio_rawread_config16(device_t_raw dev, unsigned where)
{
	unsigned addr;
	addr = dev | where;
	return read16x(addr);
}
#endif

static u16 pci_rawread_config16(device_t_raw dev, unsigned where)
{
#if CONFIG_MMCONF_SUPPORT
	return pci_mmio_rawread_config16(dev, where);
#else
	return pci_io_rawread_config16(dev, where);
#endif
}

static u32 pci_io_rawread_config32(device_t_raw dev, unsigned where)
{
	unsigned addr;
#if CONFIG_PCI_IO_CFG_EXT == 0
	addr = (dev >> 4) | where;
#else
	addr = (dev >> 4) | (where & 0xff) | ((where & 0xf00) << 16);
#endif
	outl(0x80000000 | (addr & ~3), 0xCF8);
	return inl(0xCFC);
}

#if CONFIG_MMCONF_SUPPORT
static u32 pci_mmio_rawread_config32(device_t_raw dev, unsigned where)
{
	unsigned addr;
	addr = dev | where;
	return read32x(addr);
}
#endif

static u32 pci_rawread_config32(device_t_raw dev, unsigned where)
{
#if CONFIG_MMCONF_SUPPORT
	return pci_mmio_rawread_config32(dev, where);
#else
	return pci_io_rawread_config32(dev, where);
#endif
}

static void pci_io_rawwrite_config8(device_t_raw dev, unsigned where, u8 value)
{
	unsigned addr;
#if CONFIG_PCI_IO_CFG_EXT == 0
	addr = (dev >> 4) | where;
#else
	addr = (dev >> 4) | (where & 0xff) | ((where & 0xf00) << 16);
#endif
	outl(0x80000000 | (addr & ~3), 0xCF8);
	outb(value, 0xCFC + (addr & 3));
}

#if CONFIG_MMCONF_SUPPORT
static void pci_mmio_rawwrite_config8(device_t_raw dev, unsigned where, u8 value)
{
	unsigned addr;
	addr = dev | where;
	write8x(addr, value);
}
#endif

static void pci_rawwrite_config8(device_t_raw dev, unsigned where, u8 value)
{
#if CONFIG_MMCONF_SUPPORT
	pci_mmio_rawwrite_config8(dev, where, value);
#else
	pci_io_rawwrite_config8(dev, where, value);
#endif
}

static void pci_io_rawwrite_config16(device_t_raw dev, unsigned where, u16 value)
{
	unsigned addr;
#if CONFIG_PCI_IO_CFG_EXT == 0
	addr = (dev >> 4) | where;
#else
	addr = (dev >> 4) | (where & 0xff) | ((where & 0xf00) << 16);
#endif
	outl(0x80000000 | (addr & ~3), 0xCF8);
	outw(value, 0xCFC + (addr & 2));
}

#if CONFIG_MMCONF_SUPPORT
static void pci_mmio_rawwrite_config16(device_t_raw dev, unsigned where,
				u16 value)
{
	unsigned addr;
	addr = dev | where;
	write16x(addr, value);
}
#endif

static void pci_rawwrite_config16(device_t_raw dev, unsigned where, u16 value)
{
#if CONFIG_MMCONF_SUPPORT
	pci_mmio_rawwrite_config16(dev, where, value);
#else
	pci_io_rawwrite_config16(dev, where, value);
#endif
}

static void pci_io_rawwrite_config32(device_t_raw dev, unsigned where, u32 value)
{
	unsigned addr;
#if CONFIG_PCI_IO_CFG_EXT == 0
	addr = (dev >> 4) | where;
#else
	addr = (dev >> 4) | (where & 0xff) | ((where & 0xf00) << 16);
#endif
	outl(0x80000000 | (addr & ~3), 0xCF8);
	outl(value, 0xCFC);
}

#if CONFIG_MMCONF_SUPPORT
static void pci_mmio_rawwrite_config32(device_t_raw dev, unsigned where, u32 value)
{
	unsigned addr;
	addr = dev | where;
	write32x(addr, value);
}
#endif

static void pci_rawwrite_config32(device_t_raw dev, unsigned where, u32 value)
{
#if CONFIG_MMCONF_SUPPORT
	pci_mmio_rawwrite_config32(dev, where, value);
#else
	pci_io_rawwrite_config32(dev, where, value);
#endif
}

static void pci_rawmodify_config8(device_t_raw dev, unsigned where, u8 orval, u8 mask)
{
	u8 data = pci_rawread_config8(dev, where);
	data &= (~mask);
	data |= orval;
	pci_rawwrite_config8(dev, where, data);
}

static void pci_rawmodify_config16(device_t_raw dev, unsigned where, u16 orval, u16 mask)
{
	u16 data = pci_rawread_config16(dev, where);
	data &= (~mask);
	data |= orval;
	pci_rawwrite_config16(dev, where, data);
}

static void pci_rawmodify_config32(device_t_raw dev, unsigned where, u32 orval, u32 mask)
{
	u32 data = pci_rawread_config32(dev, where);
	data &= (~mask);
	data |= orval;
	pci_rawwrite_config32(dev, where, data);
}

static void io_rawmodify_config8(u16 where, u8 orval, u8 mask)
{
	u8 data = inb(where);
	data &= (~mask);
	data |= orval;
	outb(data, where);
}

static void via_pci_inittable(u8 chipversion,
		       const struct VIA_PCI_REG_INIT_TABLE *initdata)
{
	u8 i = 0;
	device_t_raw devbxdxfx;
	for (i = 0;; i++) {
		if ((initdata[i].Mask == 0) && (initdata[i].Value == 0)
		    && (initdata[i].Bus == 0)
		    && (initdata[i].ChipRevisionEnd == 0xff)
		    && (initdata[i].ChipRevisionStart == 0)
		    && (initdata[i].Device == 0)
		    && (initdata[i].Function == 0)
		    && (initdata[i].Register == 0))
			break;
		if ((chipversion >= initdata[i].ChipRevisionStart)
		    && (chipversion <= initdata[i].ChipRevisionEnd)) {
			devbxdxfx =
			    PCI_RAWDEV(initdata[i].Bus, initdata[i].Device,
				       initdata[i].Function);
			pci_rawmodify_config8(devbxdxfx,
					      initdata[i].Register,
					      initdata[i].Value,
					      initdata[i].Mask);
		}
	}
}
#endif