// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Low - level PCI config space access for OLPC systems who lack the VSA
* PCI virtualization software .
*
* Copyright © 2006 Advanced Micro Devices , Inc .
*
* The AMD Geode chipset ( ie : GX2 processor , cs5536 I / O companion device )
* has some I / O functions ( display , southbridge , sound , USB HCIs , etc )
* that more or less behave like PCI devices , but the hardware doesn ' t
* directly implement the PCI configuration space headers . AMD provides
* " VSA " ( Virtual System Architecture ) software that emulates PCI config
* space for these devices , by trapping I / O accesses to PCI config register
* ( CF8 / CFC ) and running some code in System Management Mode interrupt state .
* On the OLPC platform , we don ' t want to use that VSA code because
* ( a ) it slows down suspend / resume , and ( b ) recompiling it requires special
* compilers that are hard to get . So instead of letting the complex VSA
* code simulate the PCI config registers for the on - chip devices , we
* just simulate them the easy way , by inserting the code into the
* pci_write_config and pci_read_config path . Most of the config registers
* are read - only anyway , so the bulk of the simulation is just table lookup .
*/
#include <linux/pci.h>
#include <linux/init.h>
#include <asm /olpc.h>
#include <asm /geode.h>
#include <asm /pci_x86.h>
/*
* In the tables below , the first two line ( 8 longwords ) are the
* size masks that are used when the higher level PCI code determines
* the size of the region by writing ~ 0 to a base address register
* and reading back the result .
*
* The following lines are the values that are read during normal
* PCI config access cycles , i . e . not after just having written
* ~ 0 to a base address register .
*/
static const uint32_t lxnb_hdr[] = { /* dev 1 function 0 - devfn = 8 */
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x281022, 0 x2200005, 0 x6000021, 0 x80f808, /* AMD Vendor ID */
0 x0, 0 x0, 0 x0, 0 x0, /* No virtual registers, hence no BAR */
0 x0, 0 x0, 0 x0, 0 x28100b,
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
};
static const uint32_t gxnb_hdr[] = { /* dev 1 function 0 - devfn = 8 */
0 xfffffffd, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x28100b, 0 x2200005, 0 x6000021, 0 x80f808, /* NSC Vendor ID */
0 xac1d, 0 x0, 0 x0, 0 x0, /* I/O BAR - base of virtual registers */
0 x0, 0 x0, 0 x0, 0 x28100b,
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
};
static const uint32_t lxfb_hdr[] = { /* dev 1 function 1 - devfn = 9 */
0 xff000008, 0 xffffc000, 0 xffffc000, 0 xffffc000,
0 xffffc000, 0 x0, 0 x0, 0 x0,
0 x20811022, 0 x2200003, 0 x3000000, 0 x0, /* AMD Vendor ID */
0 xfd000000, 0 xfe000000, 0 xfe004000, 0 xfe008000, /* FB, GP, VG, DF */
0 xfe00c000, 0 x0, 0 x0, 0 x30100b, /* VIP */
0 x0, 0 x0, 0 x0, 0 x10e, /* INTA, IRQ14 for graphics accel */
0 x0, 0 x0, 0 x0, 0 x0,
0 x3d0, 0 x3c0, 0 xa0000, 0 x0, /* VG IO, VG IO, EGA FB, MONO FB */
0 x0, 0 x0, 0 x0, 0 x0,
};
static const uint32_t gxfb_hdr[] = { /* dev 1 function 1 - devfn = 9 */
0 xff800008, 0 xffffc000, 0 xffffc000, 0 xffffc000,
0 x0, 0 x0, 0 x0, 0 x0,
0 x30100b, 0 x2200003, 0 x3000000, 0 x0, /* NSC Vendor ID */
0 xfd000000, 0 xfe000000, 0 xfe004000, 0 xfe008000, /* FB, GP, VG, DF */
0 x0, 0 x0, 0 x0, 0 x30100b,
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x3d0, 0 x3c0, 0 xa0000, 0 x0, /* VG IO, VG IO, EGA FB, MONO FB */
0 x0, 0 x0, 0 x0, 0 x0,
};
static const uint32_t aes_hdr[] = { /* dev 1 function 2 - devfn = 0xa */
0 xffffc000, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x20821022, 0 x2a00006, 0 x10100000, 0 x8, /* NSC Vendor ID */
0 xfe010000, 0 x0, 0 x0, 0 x0, /* AES registers */
0 x0, 0 x0, 0 x0, 0 x20821022,
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
};
static const uint32_t isa_hdr[] = { /* dev f function 0 - devfn = 78 */
0 xfffffff9, 0 xffffff01, 0 xffffffc1, 0 xffffffe1,
0 xffffff81, 0 xffffffc1, 0 x0, 0 x0,
0 x20901022, 0 x2a00049, 0 x6010003, 0 x802000,
0 x18b1, 0 x1001, 0 x1801, 0 x1881, /* SMB-8 GPIO-256 MFGPT-64 IRQ-32 */
0 x1401, 0 x1841, 0 x0, 0 x20901022, /* PMS-128 ACPI-64 */
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 xaa5b, /* IRQ steering */
0 x0, 0 x0, 0 x0, 0 x0,
};
static const uint32_t ac97_hdr[] = { /* dev f function 3 - devfn = 7b */
0 xffffff81, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x20931022, 0 x2a00041, 0 x4010001, 0 x0,
0 x1481, 0 x0, 0 x0, 0 x0, /* I/O BAR-128 */
0 x0, 0 x0, 0 x0, 0 x20931022,
0 x0, 0 x0, 0 x0, 0 x205, /* IntB, IRQ5 */
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
};
static const uint32_t ohci_hdr[] = { /* dev f function 4 - devfn = 7c */
0 xfffff000, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x20941022, 0 x2300006, 0 xc031002, 0 x0,
0 xfe01a000, 0 x0, 0 x0, 0 x0, /* MEMBAR-1000 */
0 x0, 0 x0, 0 x0, 0 x20941022,
0 x0, 0 x40, 0 x0, 0 x40a, /* CapPtr INT-D, IRQA */
0 xc8020001, 0 x0, 0 x0, 0 x0, /* Capabilities - 40 is R/O,
44 is mask 8103 (power control) */
0 x0, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
};
static const uint32_t ehci_hdr[] = { /* dev f function 4 - devfn = 7d */
0 xfffff000, 0 x0, 0 x0, 0 x0,
0 x0, 0 x0, 0 x0, 0 x0,
0 x20951022, 0 x2300006, 0 xc032002, 0 x0,
0 xfe01b000, 0 x0, 0 x0, 0 x0, /* MEMBAR-1000 */
0 x0, 0 x0, 0 x0, 0 x20951022,
0 x0, 0 x40, 0 x0, 0 x40a, /* CapPtr INT-D, IRQA */
0 xc8020001, 0 x0, 0 x0, 0 x0, /* Capabilities - 40 is R/O, 44 is
mask 8103 (power control) */
0 x01000001, 0 x0, 0 x0, 0 x0, /* EECP - see EHCI spec section 2.1.7 */
0 x2020, 0 x0, 0 x0, 0 x0, /* (EHCI page 8) 60 SBRN (R/O),
61 FLADJ (R/W), PORTWAKECAP */
};
static uint32_t ff_loc = ~0 ;
static uint32_t zero_loc;
static int bar_probing; /* Set after a write of ~0 to a BAR */
static int is_lx;
#define NB_SLOT 0 x1 /* Northbridge - GX chip - Device 1 */
#define SB_SLOT 0 xf /* Southbridge - CS5536 chip - Device F */
static int is_simulated(unsigned int bus, unsigned int devfn)
{
return (!bus && ((PCI_SLOT(devfn) == NB_SLOT) ||
(PCI_SLOT(devfn) == SB_SLOT)));
}
static uint32_t *hdr_addr(const uint32_t *hdr, int reg)
{
uint32_t addr;
/*
* This is a little bit tricky . The header maps consist of
* 0 x20 bytes of size masks , followed by 0 x70 bytes of header data .
* In the normal case , when not probing a BAR ' s size , we want
* to access the header data , so we add 0 x20 to the reg offset ,
* thus skipping the size mask area .
* In the BAR probing case , we want to access the size mask for
* the BAR , so we subtract 0 x10 ( the config header offset for
* BAR0 ) , and don ' t skip the size mask area .
*/
addr = (uint32_t)hdr + reg + (bar_probing ? -0 x10 : 0 x20);
bar_probing = 0 ;
return (uint32_t *)addr;
}
static int pci_olpc_read(unsigned int seg, unsigned int bus,
unsigned int devfn, int reg, int len, uint32_t *value)
{
uint32_t *addr;
WARN_ON(seg);
/* Use the hardware mechanism for non-simulated devices */
if (!is_simulated(bus, devfn))
return pci_direct_conf1.read(seg, bus, devfn, reg, len, value);
/*
* No device has config registers past 0 x70 , so we save table space
* by not storing entries for the nonexistent registers
*/
if (reg >= 0 x70)
addr = &zero_loc;
else {
switch (devfn) {
case 0 x8:
addr = hdr_addr(is_lx ? lxnb_hdr : gxnb_hdr, reg);
break ;
case 0 x9:
addr = hdr_addr(is_lx ? lxfb_hdr : gxfb_hdr, reg);
break ;
case 0 xa:
addr = is_lx ? hdr_addr(aes_hdr, reg) : &ff_loc;
break ;
case 0 x78:
addr = hdr_addr(isa_hdr, reg);
break ;
case 0 x7b:
addr = hdr_addr(ac97_hdr, reg);
break ;
case 0 x7c:
addr = hdr_addr(ohci_hdr, reg);
break ;
case 0 x7d:
addr = hdr_addr(ehci_hdr, reg);
break ;
default :
addr = &ff_loc;
break ;
}
}
switch (len) {
case 1 :
*value = *(uint8_t *)addr;
break ;
case 2 :
*value = *(uint16_t *)addr;
break ;
case 4 :
*value = *addr;
break ;
default :
BUG();
}
return 0 ;
}
static int pci_olpc_write(unsigned int seg, unsigned int bus,
unsigned int devfn, int reg, int len, uint32_t value)
{
WARN_ON(seg);
/* Use the hardware mechanism for non-simulated devices */
if (!is_simulated(bus, devfn))
return pci_direct_conf1.write(seg, bus, devfn, reg, len, value);
/* XXX we may want to extend this to simulate EHCI power management */
/*
* Mostly we just discard writes , but if the write is a size probe
* ( i . e . writing ~ 0 to a BAR ) , we remember it and arrange to return
* the appropriate size mask on the next read . This is cheating
* to some extent , because it depends on the fact that the next
* access after such a write will always be a read to the same BAR .
*/
if ((reg >= 0 x10) && (reg < 0 x2c)) {
/* write is to a BAR */
if (value == ~0 )
bar_probing = 1 ;
} else {
/*
* No warning on writes to ROM BAR , CMD , LATENCY_TIMER ,
* CACHE_LINE_SIZE , or PM registers .
*/
if ((reg != PCI_ROM_ADDRESS) && (reg != PCI_COMMAND_MASTER) &&
(reg != PCI_LATENCY_TIMER) &&
(reg != PCI_CACHE_LINE_SIZE) && (reg != 0 x44))
printk(KERN_WARNING "OLPC PCI: Config write to devfn"
" %x reg %x value %x\n" , devfn, reg, value);
}
return 0 ;
}
static const struct pci_raw_ops pci_olpc_conf = {
.read = pci_olpc_read,
.write = pci_olpc_write,
};
int __init pci_olpc_init(void )
{
printk(KERN_INFO "PCI: Using configuration type OLPC XO-1\n" );
raw_pci_ops = &pci_olpc_conf;
is_lx = is_geode_lx();
return 0 ;
}
Messung V0.5 in Prozent C=85 H=95 G=90
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-09-30)
¤
*© Formatika GbR, Deutschland