| 1 |
/* |
| 2 |
This file is based on: |
| 3 |
$XFree86: xc/programs/Xserver/hw/xfree86/etc/scanpci.c,v 3.34.2.17 1998/11/10 11:55:40 dawes Exp $ |
| 4 |
Modified for readability by Nick Kurshev |
| 5 |
*/ |
| 6 |
|
| 7 |
#if defined(Lynx_22) |
| 8 |
#ifndef GCCUSESGAS |
| 9 |
#define GCCUSESGAS |
| 10 |
#endif |
| 11 |
|
| 12 |
/* let's mimick the Linux Alpha stuff for LynxOS so we don't have |
| 13 |
* to change too much code |
| 14 |
*/ |
| 15 |
#include <smem.h> |
| 16 |
|
| 17 |
static unsigned char *pciConfBase; |
| 18 |
|
| 19 |
static __inline__ void enable_os_io(void) |
| 20 |
{ |
| 21 |
pciConfBase = (unsigned char *) smem_create("PCI-CONF", |
| 22 |
(char *)0x80800000, 64*1024, SM_READ|SM_WRITE); |
| 23 |
if (pciConfBase == (void *) -1) |
| 24 |
exit(1); |
| 25 |
} |
| 26 |
|
| 27 |
static __inline__ void disable_os_io(void) |
| 28 |
{ |
| 29 |
smem_create(NULL, (char *) pciConfBase, 0, SM_DETACH); |
| 30 |
smem_remove("PCI-CONF"); |
| 31 |
pciConfBase = NULL; |
| 32 |
} |
| 33 |
|
| 34 |
#include <smem.h> |
| 35 |
|
| 36 |
static unsigned char *pciConfBase; |
| 37 |
|
| 38 |
static __inline__ unsigned long |
| 39 |
static swapl(unsigned long val) |
| 40 |
{ |
| 41 |
unsigned char *p = (unsigned char *)&val; |
| 42 |
return ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | (p[0] << 0)); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
#define BUS(tag) (((tag)>>16)&0xff) |
| 47 |
#define DFN(tag) (((tag)>>8)&0xff) |
| 48 |
|
| 49 |
#define PCIBIOS_DEVICE_NOT_FOUND 0x86 |
| 50 |
#define PCIBIOS_SUCCESSFUL 0x00 |
| 51 |
|
| 52 |
static int pciconfig_read( |
| 53 |
unsigned char bus, |
| 54 |
unsigned char dev, |
| 55 |
unsigned char offset, |
| 56 |
int len, /* unused, alway 4 */ |
| 57 |
unsigned long *val) |
| 58 |
{ |
| 59 |
unsigned long _val; |
| 60 |
unsigned long *ptr; |
| 61 |
|
| 62 |
dev >>= 3; |
| 63 |
if (bus || dev >= 16) { |
| 64 |
*val = 0xFFFFFFFF; |
| 65 |
return PCIBIOS_DEVICE_NOT_FOUND; |
| 66 |
} else { |
| 67 |
ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset)); |
| 68 |
_val = swapl(*ptr); |
| 69 |
} |
| 70 |
*val = _val; |
| 71 |
return PCIBIOS_SUCCESSFUL; |
| 72 |
} |
| 73 |
|
| 74 |
static int pciconfig_write( |
| 75 |
unsigned char bus, |
| 76 |
unsigned char dev, |
| 77 |
unsigned char offset, |
| 78 |
int len, /* unused, alway 4 */ |
| 79 |
unsigned long val) |
| 80 |
{ |
| 81 |
unsigned long _val; |
| 82 |
unsigned long *ptr; |
| 83 |
|
| 84 |
dev >>= 3; |
| 85 |
_val = swapl(val); |
| 86 |
if (bus || dev >= 16) { |
| 87 |
return PCIBIOS_DEVICE_NOT_FOUND; |
| 88 |
} else { |
| 89 |
ptr = (unsigned long *)(pciConfBase + ((1<<dev) | offset)); |
| 90 |
*ptr = _val; |
| 91 |
} |
| 92 |
return PCIBIOS_SUCCESSFUL; |
| 93 |
} |