xref: /openbmc/linux/arch/x86/pci/olpc.c (revision 3ef0e1f8cad0a851b3dbf91802b14af7dd780352)
1*3ef0e1f8SAndres Salomon /*
2*3ef0e1f8SAndres Salomon  * Low-level PCI config space access for OLPC systems who lack the VSA
3*3ef0e1f8SAndres Salomon  * PCI virtualization software.
4*3ef0e1f8SAndres Salomon  *
5*3ef0e1f8SAndres Salomon  * Copyright © 2006  Advanced Micro Devices, Inc.
6*3ef0e1f8SAndres Salomon  *
7*3ef0e1f8SAndres Salomon  * This program is free software; you can redistribute it and/or modify
8*3ef0e1f8SAndres Salomon  * it under the terms of the GNU General Public License as published by
9*3ef0e1f8SAndres Salomon  * the Free Software Foundation; either version 2 of the License, or
10*3ef0e1f8SAndres Salomon  * (at your option) any later version.
11*3ef0e1f8SAndres Salomon  *
12*3ef0e1f8SAndres Salomon  * The AMD Geode chipset (ie: GX2 processor, cs5536 I/O companion device)
13*3ef0e1f8SAndres Salomon  * has some I/O functions (display, southbridge, sound, USB HCIs, etc)
14*3ef0e1f8SAndres Salomon  * that more or less behave like PCI devices, but the hardware doesn't
15*3ef0e1f8SAndres Salomon  * directly implement the PCI configuration space headers.  AMD provides
16*3ef0e1f8SAndres Salomon  * "VSA" (Virtual System Architecture) software that emulates PCI config
17*3ef0e1f8SAndres Salomon  * space for these devices, by trapping I/O accesses to PCI config register
18*3ef0e1f8SAndres Salomon  * (CF8/CFC) and running some code in System Management Mode interrupt state.
19*3ef0e1f8SAndres Salomon  * On the OLPC platform, we don't want to use that VSA code because
20*3ef0e1f8SAndres Salomon  * (a) it slows down suspend/resume, and (b) recompiling it requires special
21*3ef0e1f8SAndres Salomon  * compilers that are hard to get.  So instead of letting the complex VSA
22*3ef0e1f8SAndres Salomon  * code simulate the PCI config registers for the on-chip devices, we
23*3ef0e1f8SAndres Salomon  * just simulate them the easy way, by inserting the code into the
24*3ef0e1f8SAndres Salomon  * pci_write_config and pci_read_config path.  Most of the config registers
25*3ef0e1f8SAndres Salomon  * are read-only anyway, so the bulk of the simulation is just table lookup.
26*3ef0e1f8SAndres Salomon  */
27*3ef0e1f8SAndres Salomon 
28*3ef0e1f8SAndres Salomon #include <linux/pci.h>
29*3ef0e1f8SAndres Salomon #include <linux/init.h>
30*3ef0e1f8SAndres Salomon #include <asm/olpc.h>
31*3ef0e1f8SAndres Salomon #include <asm/geode.h>
32*3ef0e1f8SAndres Salomon #include "pci.h"
33*3ef0e1f8SAndres Salomon 
34*3ef0e1f8SAndres Salomon /*
35*3ef0e1f8SAndres Salomon  * In the tables below, the first two line (8 longwords) are the
36*3ef0e1f8SAndres Salomon  * size masks that are used when the higher level PCI code determines
37*3ef0e1f8SAndres Salomon  * the size of the region by writing ~0 to a base address register
38*3ef0e1f8SAndres Salomon  * and reading back the result.
39*3ef0e1f8SAndres Salomon  *
40*3ef0e1f8SAndres Salomon  * The following lines are the values that are read during normal
41*3ef0e1f8SAndres Salomon  * PCI config access cycles, i.e. not after just having written
42*3ef0e1f8SAndres Salomon  * ~0 to a base address register.
43*3ef0e1f8SAndres Salomon  */
44*3ef0e1f8SAndres Salomon 
45*3ef0e1f8SAndres Salomon static const uint32_t lxnb_hdr[] = {  /* dev 1 function 0 - devfn = 8 */
46*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
47*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
48*3ef0e1f8SAndres Salomon 
49*3ef0e1f8SAndres Salomon 	0x281022, 0x2200005, 0x6000021, 0x80f808,	/* AMD Vendor ID */
50*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,   /* No virtual registers, hence no BAR */
51*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x28100b,
52*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
53*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
54*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
55*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
56*3ef0e1f8SAndres Salomon };
57*3ef0e1f8SAndres Salomon 
58*3ef0e1f8SAndres Salomon static const uint32_t gxnb_hdr[] = {  /* dev 1 function 0 - devfn = 8 */
59*3ef0e1f8SAndres Salomon 	0xfffffffd, 0x0, 0x0,	0x0,
60*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
61*3ef0e1f8SAndres Salomon 
62*3ef0e1f8SAndres Salomon 	0x28100b, 0x2200005, 0x6000021, 0x80f808,	/* NSC Vendor ID */
63*3ef0e1f8SAndres Salomon 	0xac1d,	0x0,	0x0,	0x0,  /* I/O BAR - base of virtual registers */
64*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x28100b,
65*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
66*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
67*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
68*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
69*3ef0e1f8SAndres Salomon };
70*3ef0e1f8SAndres Salomon 
71*3ef0e1f8SAndres Salomon static const uint32_t lxfb_hdr[] = {  /* dev 1 function 1 - devfn = 9 */
72*3ef0e1f8SAndres Salomon 	0xff000008, 0xffffc000, 0xffffc000, 0xffffc000,
73*3ef0e1f8SAndres Salomon 	0xffffc000,	0x0,	0x0,	0x0,
74*3ef0e1f8SAndres Salomon 
75*3ef0e1f8SAndres Salomon 	0x20811022, 0x2200003, 0x3000000, 0x0,		/* AMD Vendor ID */
76*3ef0e1f8SAndres Salomon 	0xfd000000, 0xfe000000, 0xfe004000, 0xfe008000, /* FB, GP, VG, DF */
77*3ef0e1f8SAndres Salomon 	0xfe00c000, 0x0, 0x0,	0x30100b,		/* VIP */
78*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x10e,	   /* INTA, IRQ14 for graphics accel */
79*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
80*3ef0e1f8SAndres Salomon 	0x3d0,	0x3c0,	0xa0000, 0x0,	    /* VG IO, VG IO, EGA FB, MONO FB */
81*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
82*3ef0e1f8SAndres Salomon };
83*3ef0e1f8SAndres Salomon 
84*3ef0e1f8SAndres Salomon static const uint32_t gxfb_hdr[] = {  /* dev 1 function 1 - devfn = 9 */
85*3ef0e1f8SAndres Salomon 	0xff800008, 0xffffc000, 0xffffc000, 0xffffc000,
86*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
87*3ef0e1f8SAndres Salomon 
88*3ef0e1f8SAndres Salomon 	0x30100b, 0x2200003, 0x3000000, 0x0,		/* NSC Vendor ID */
89*3ef0e1f8SAndres Salomon 	0xfd000000, 0xfe000000, 0xfe004000, 0xfe008000,	/* FB, GP, VG, DF */
90*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x30100b,
91*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
92*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
93*3ef0e1f8SAndres Salomon 	0x3d0,	0x3c0,	0xa0000, 0x0,  	    /* VG IO, VG IO, EGA FB, MONO FB */
94*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
95*3ef0e1f8SAndres Salomon };
96*3ef0e1f8SAndres Salomon 
97*3ef0e1f8SAndres Salomon static const uint32_t aes_hdr[] = {	/* dev 1 function 2 - devfn = 0xa */
98*3ef0e1f8SAndres Salomon 	0xffffc000, 0x0, 0x0,	0x0,
99*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
100*3ef0e1f8SAndres Salomon 
101*3ef0e1f8SAndres Salomon 	0x20821022, 0x2a00006, 0x10100000, 0x8,		/* NSC Vendor ID */
102*3ef0e1f8SAndres Salomon 	0xfe010000, 0x0, 0x0,	0x0,			/* AES registers */
103*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x20821022,
104*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
105*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
106*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
107*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
108*3ef0e1f8SAndres Salomon };
109*3ef0e1f8SAndres Salomon 
110*3ef0e1f8SAndres Salomon 
111*3ef0e1f8SAndres Salomon static const uint32_t isa_hdr[] = {  /* dev f function 0 - devfn = 78 */
112*3ef0e1f8SAndres Salomon 	0xfffffff9, 0xffffff01, 0xffffffc1, 0xffffffe1,
113*3ef0e1f8SAndres Salomon 	0xffffff81, 0xffffffc1, 0x0, 0x0,
114*3ef0e1f8SAndres Salomon 
115*3ef0e1f8SAndres Salomon 	0x20901022, 0x2a00049, 0x6010003, 0x802000,
116*3ef0e1f8SAndres Salomon 	0x18b1,	0x1001,	0x1801,	0x1881,	/* SMB-8   GPIO-256 MFGPT-64  IRQ-32 */
117*3ef0e1f8SAndres Salomon 	0x1401,	0x1841,	0x0,	0x20901022,		/* PMS-128 ACPI-64 */
118*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
119*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
120*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0xaa5b,			/* IRQ steering */
121*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
122*3ef0e1f8SAndres Salomon };
123*3ef0e1f8SAndres Salomon 
124*3ef0e1f8SAndres Salomon static const uint32_t ac97_hdr[] = {  /* dev f function 3 - devfn = 7b */
125*3ef0e1f8SAndres Salomon 	0xffffff81, 0x0, 0x0,	0x0,
126*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
127*3ef0e1f8SAndres Salomon 
128*3ef0e1f8SAndres Salomon 	0x20931022, 0x2a00041, 0x4010001, 0x0,
129*3ef0e1f8SAndres Salomon 	0x1481,	0x0,	0x0,	0x0,			/* I/O BAR-128 */
130*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x20931022,
131*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x205,			/* IntB, IRQ5 */
132*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
133*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
134*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
135*3ef0e1f8SAndres Salomon };
136*3ef0e1f8SAndres Salomon 
137*3ef0e1f8SAndres Salomon static const uint32_t ohci_hdr[] = {  /* dev f function 4 - devfn = 7c */
138*3ef0e1f8SAndres Salomon 	0xfffff000, 0x0, 0x0,	0x0,
139*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
140*3ef0e1f8SAndres Salomon 
141*3ef0e1f8SAndres Salomon 	0x20941022, 0x2300006, 0xc031002, 0x0,
142*3ef0e1f8SAndres Salomon 	0xfe01a000, 0x0, 0x0,	0x0,			/* MEMBAR-1000 */
143*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x20941022,
144*3ef0e1f8SAndres Salomon 	0x0,	0x40,	0x0,	0x40a,			/* CapPtr INT-D, IRQA */
145*3ef0e1f8SAndres Salomon 	0xc8020001, 0x0, 0x0,	0x0,	/* Capabilities - 40 is R/O,
146*3ef0e1f8SAndres Salomon 					   44 is mask 8103 (power control) */
147*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
148*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
149*3ef0e1f8SAndres Salomon };
150*3ef0e1f8SAndres Salomon 
151*3ef0e1f8SAndres Salomon static const uint32_t ehci_hdr[] = {  /* dev f function 4 - devfn = 7d */
152*3ef0e1f8SAndres Salomon 	0xfffff000, 0x0, 0x0,	0x0,
153*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x0,
154*3ef0e1f8SAndres Salomon 
155*3ef0e1f8SAndres Salomon 	0x20951022, 0x2300006, 0xc032002, 0x0,
156*3ef0e1f8SAndres Salomon 	0xfe01b000, 0x0, 0x0,	0x0,			/* MEMBAR-1000 */
157*3ef0e1f8SAndres Salomon 	0x0,	0x0,	0x0,	0x20951022,
158*3ef0e1f8SAndres Salomon 	0x0,	0x40,	0x0,	0x40a,			/* CapPtr INT-D, IRQA */
159*3ef0e1f8SAndres Salomon 	0xc8020001, 0x0, 0x0,	0x0,	/* Capabilities - 40 is R/O, 44 is
160*3ef0e1f8SAndres Salomon 					   mask 8103 (power control) */
161*3ef0e1f8SAndres Salomon #if 0
162*3ef0e1f8SAndres Salomon 	0x1,	0x40080000, 0x0, 0x0,	/* EECP - see EHCI spec section 2.1.7 */
163*3ef0e1f8SAndres Salomon #endif
164*3ef0e1f8SAndres Salomon 	0x01000001, 0x0, 0x0,	0x0,	/* EECP - see EHCI spec section 2.1.7 */
165*3ef0e1f8SAndres Salomon 	0x2020,	0x0,	0x0,	0x0,	/* (EHCI page 8) 60 SBRN (R/O),
166*3ef0e1f8SAndres Salomon 					   61 FLADJ (R/W), PORTWAKECAP  */
167*3ef0e1f8SAndres Salomon };
168*3ef0e1f8SAndres Salomon 
169*3ef0e1f8SAndres Salomon static uint32_t ff_loc = ~0;
170*3ef0e1f8SAndres Salomon static uint32_t zero_loc;
171*3ef0e1f8SAndres Salomon static int bar_probing;		/* Set after a write of ~0 to a BAR */
172*3ef0e1f8SAndres Salomon static int is_lx;
173*3ef0e1f8SAndres Salomon 
174*3ef0e1f8SAndres Salomon #define NB_SLOT 0x1	/* Northbridge - GX chip - Device 1 */
175*3ef0e1f8SAndres Salomon #define SB_SLOT 0xf	/* Southbridge - CS5536 chip - Device F */
176*3ef0e1f8SAndres Salomon 
177*3ef0e1f8SAndres Salomon static int is_simulated(unsigned int bus, unsigned int devfn)
178*3ef0e1f8SAndres Salomon {
179*3ef0e1f8SAndres Salomon 	return (!bus && ((PCI_SLOT(devfn) == NB_SLOT) ||
180*3ef0e1f8SAndres Salomon 			(PCI_SLOT(devfn) == SB_SLOT)));
181*3ef0e1f8SAndres Salomon }
182*3ef0e1f8SAndres Salomon 
183*3ef0e1f8SAndres Salomon static uint32_t *hdr_addr(const uint32_t *hdr, int reg)
184*3ef0e1f8SAndres Salomon {
185*3ef0e1f8SAndres Salomon 	uint32_t addr;
186*3ef0e1f8SAndres Salomon 
187*3ef0e1f8SAndres Salomon 	/*
188*3ef0e1f8SAndres Salomon 	 * This is a little bit tricky.  The header maps consist of
189*3ef0e1f8SAndres Salomon 	 * 0x20 bytes of size masks, followed by 0x70 bytes of header data.
190*3ef0e1f8SAndres Salomon 	 * In the normal case, when not probing a BAR's size, we want
191*3ef0e1f8SAndres Salomon 	 * to access the header data, so we add 0x20 to the reg offset,
192*3ef0e1f8SAndres Salomon 	 * thus skipping the size mask area.
193*3ef0e1f8SAndres Salomon 	 * In the BAR probing case, we want to access the size mask for
194*3ef0e1f8SAndres Salomon 	 * the BAR, so we subtract 0x10 (the config header offset for
195*3ef0e1f8SAndres Salomon 	 * BAR0), and don't skip the size mask area.
196*3ef0e1f8SAndres Salomon 	 */
197*3ef0e1f8SAndres Salomon 
198*3ef0e1f8SAndres Salomon 	addr = (uint32_t)hdr + reg + (bar_probing ? -0x10 : 0x20);
199*3ef0e1f8SAndres Salomon 
200*3ef0e1f8SAndres Salomon 	bar_probing = 0;
201*3ef0e1f8SAndres Salomon 	return (uint32_t *)addr;
202*3ef0e1f8SAndres Salomon }
203*3ef0e1f8SAndres Salomon 
204*3ef0e1f8SAndres Salomon static int pci_olpc_read(unsigned int seg, unsigned int bus,
205*3ef0e1f8SAndres Salomon 		unsigned int devfn, int reg, int len, uint32_t *value)
206*3ef0e1f8SAndres Salomon {
207*3ef0e1f8SAndres Salomon 	uint32_t *addr;
208*3ef0e1f8SAndres Salomon 
209*3ef0e1f8SAndres Salomon 	/* Use the hardware mechanism for non-simulated devices */
210*3ef0e1f8SAndres Salomon 	if (!is_simulated(bus, devfn))
211*3ef0e1f8SAndres Salomon 		return pci_direct_conf1.read(seg, bus, devfn, reg, len, value);
212*3ef0e1f8SAndres Salomon 
213*3ef0e1f8SAndres Salomon 	/*
214*3ef0e1f8SAndres Salomon 	 * No device has config registers past 0x70, so we save table space
215*3ef0e1f8SAndres Salomon 	 * by not storing entries for the nonexistent registers
216*3ef0e1f8SAndres Salomon 	 */
217*3ef0e1f8SAndres Salomon 	if (reg >= 0x70)
218*3ef0e1f8SAndres Salomon 		addr = &zero_loc;
219*3ef0e1f8SAndres Salomon 	else {
220*3ef0e1f8SAndres Salomon 		switch (devfn) {
221*3ef0e1f8SAndres Salomon 		case  0x8:
222*3ef0e1f8SAndres Salomon 			addr = hdr_addr(is_lx ? lxnb_hdr : gxnb_hdr, reg);
223*3ef0e1f8SAndres Salomon 			break;
224*3ef0e1f8SAndres Salomon 		case  0x9:
225*3ef0e1f8SAndres Salomon 			addr = hdr_addr(is_lx ? lxfb_hdr : gxfb_hdr, reg);
226*3ef0e1f8SAndres Salomon 			break;
227*3ef0e1f8SAndres Salomon 		case  0xa:
228*3ef0e1f8SAndres Salomon 			addr = is_lx ? hdr_addr(aes_hdr, reg) : &ff_loc;
229*3ef0e1f8SAndres Salomon 			break;
230*3ef0e1f8SAndres Salomon 		case 0x78:
231*3ef0e1f8SAndres Salomon 			addr = hdr_addr(isa_hdr, reg);
232*3ef0e1f8SAndres Salomon 			break;
233*3ef0e1f8SAndres Salomon 		case 0x7b:
234*3ef0e1f8SAndres Salomon 			addr = hdr_addr(ac97_hdr, reg);
235*3ef0e1f8SAndres Salomon 			break;
236*3ef0e1f8SAndres Salomon 		case 0x7c:
237*3ef0e1f8SAndres Salomon 			addr = hdr_addr(ohci_hdr, reg);
238*3ef0e1f8SAndres Salomon 			break;
239*3ef0e1f8SAndres Salomon 		case 0x7d:
240*3ef0e1f8SAndres Salomon 			addr = hdr_addr(ehci_hdr, reg);
241*3ef0e1f8SAndres Salomon 			break;
242*3ef0e1f8SAndres Salomon 		default:
243*3ef0e1f8SAndres Salomon 			addr = &ff_loc;
244*3ef0e1f8SAndres Salomon 			break;
245*3ef0e1f8SAndres Salomon 		}
246*3ef0e1f8SAndres Salomon 	}
247*3ef0e1f8SAndres Salomon 	switch (len) {
248*3ef0e1f8SAndres Salomon 	case 1:
249*3ef0e1f8SAndres Salomon 		*value = *(uint8_t *)addr;
250*3ef0e1f8SAndres Salomon 		break;
251*3ef0e1f8SAndres Salomon 	case 2:
252*3ef0e1f8SAndres Salomon 		*value = *(uint16_t *)addr;
253*3ef0e1f8SAndres Salomon 		break;
254*3ef0e1f8SAndres Salomon 	case 4:
255*3ef0e1f8SAndres Salomon 		*value = *addr;
256*3ef0e1f8SAndres Salomon 		break;
257*3ef0e1f8SAndres Salomon 	default:
258*3ef0e1f8SAndres Salomon 		BUG();
259*3ef0e1f8SAndres Salomon 	}
260*3ef0e1f8SAndres Salomon 
261*3ef0e1f8SAndres Salomon 	return 0;
262*3ef0e1f8SAndres Salomon }
263*3ef0e1f8SAndres Salomon 
264*3ef0e1f8SAndres Salomon static int pci_olpc_write(unsigned int seg, unsigned int bus,
265*3ef0e1f8SAndres Salomon 		unsigned int devfn, int reg, int len, uint32_t value)
266*3ef0e1f8SAndres Salomon {
267*3ef0e1f8SAndres Salomon 	/* Use the hardware mechanism for non-simulated devices */
268*3ef0e1f8SAndres Salomon 	if (!is_simulated(bus, devfn))
269*3ef0e1f8SAndres Salomon 		return pci_direct_conf1.write(seg, bus, devfn, reg, len, value);
270*3ef0e1f8SAndres Salomon 
271*3ef0e1f8SAndres Salomon 	/* XXX we may want to extend this to simulate EHCI power management */
272*3ef0e1f8SAndres Salomon 
273*3ef0e1f8SAndres Salomon 	/*
274*3ef0e1f8SAndres Salomon 	 * Mostly we just discard writes, but if the write is a size probe
275*3ef0e1f8SAndres Salomon 	 * (i.e. writing ~0 to a BAR), we remember it and arrange to return
276*3ef0e1f8SAndres Salomon 	 * the appropriate size mask on the next read.  This is cheating
277*3ef0e1f8SAndres Salomon 	 * to some extent, because it depends on the fact that the next
278*3ef0e1f8SAndres Salomon 	 * access after such a write will always be a read to the same BAR.
279*3ef0e1f8SAndres Salomon 	 */
280*3ef0e1f8SAndres Salomon 
281*3ef0e1f8SAndres Salomon 	if ((reg >= 0x10) && (reg < 0x2c)) {
282*3ef0e1f8SAndres Salomon 		/* write is to a BAR */
283*3ef0e1f8SAndres Salomon 		if (value == ~0)
284*3ef0e1f8SAndres Salomon 			bar_probing = 1;
285*3ef0e1f8SAndres Salomon 	} else {
286*3ef0e1f8SAndres Salomon 		/*
287*3ef0e1f8SAndres Salomon 		 * No warning on writes to ROM BAR, CMD, LATENCY_TIMER,
288*3ef0e1f8SAndres Salomon 		 * CACHE_LINE_SIZE, or PM registers.
289*3ef0e1f8SAndres Salomon 		 */
290*3ef0e1f8SAndres Salomon 		if ((reg != PCI_ROM_ADDRESS) && (reg != PCI_COMMAND_MASTER) &&
291*3ef0e1f8SAndres Salomon 				(reg != PCI_LATENCY_TIMER) &&
292*3ef0e1f8SAndres Salomon 				(reg != PCI_CACHE_LINE_SIZE) && (reg != 0x44))
293*3ef0e1f8SAndres Salomon 			printk(KERN_WARNING "OLPC PCI: Config write to devfn"
294*3ef0e1f8SAndres Salomon 				" %x reg %x value %x\n", devfn, reg, value);
295*3ef0e1f8SAndres Salomon 	}
296*3ef0e1f8SAndres Salomon 
297*3ef0e1f8SAndres Salomon 	return 0;
298*3ef0e1f8SAndres Salomon }
299*3ef0e1f8SAndres Salomon 
300*3ef0e1f8SAndres Salomon static struct pci_raw_ops pci_olpc_conf = {
301*3ef0e1f8SAndres Salomon 	.read =	pci_olpc_read,
302*3ef0e1f8SAndres Salomon 	.write = pci_olpc_write,
303*3ef0e1f8SAndres Salomon };
304*3ef0e1f8SAndres Salomon 
305*3ef0e1f8SAndres Salomon void __init pci_olpc_init(void)
306*3ef0e1f8SAndres Salomon {
307*3ef0e1f8SAndres Salomon 	if (!machine_is_olpc() || olpc_has_vsa())
308*3ef0e1f8SAndres Salomon 		return;
309*3ef0e1f8SAndres Salomon 
310*3ef0e1f8SAndres Salomon 	printk(KERN_INFO "PCI: Using configuration type OLPC\n");
311*3ef0e1f8SAndres Salomon 	raw_pci_ops = &pci_olpc_conf;
312*3ef0e1f8SAndres Salomon 	is_lx = is_geode_lx();
313*3ef0e1f8SAndres Salomon }
314