Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4220 → Rev 4221

/branches/dd/uspace/srv/pci/libpci/i386-ports.c
14,9 → 14,12
 
#include "internal.h"
 
#define PCI_CONF1 0xcf8
#define PCI_CONF1_SIZE 8
 
 
static void conf12_init(struct pci_access *a)
{
{
}
 
static void conf12_cleanup(struct pci_access *a UNUSED)
70,6 → 73,14
{
unsigned int tmp;
int res = 0;
/*
* Gain control over PCI configuration ports.
*/
void * addr;
if (pio_enable((void *)PCI_CONF1, PCI_CONF1_SIZE, &addr)) {
return 0;
}
 
pio_write_8(0xCFB, 0x01);
tmp = pio_read_32(0xCF8);
142,6 → 153,17
 
static int conf2_detect(struct pci_access *a)
{
/*
* Gain control over PCI configuration ports.
*/
void * addr;
if (pio_enable((void *)PCI_CONF1, PCI_CONF1_SIZE, &addr)) {
return 0;
}
if (pio_enable((void *)0xC000, 0x1000, &addr)) {
return 0;
}
/* This is ugly and tends to produce false positives. Beware. */
pio_write_8(0xCFB, 0x00);
pio_write_8(0xCF8, 0x00);
178,7 → 200,7
pio_write_8(0xcf8, 0);
return pci_generic_block_read(d, pos, buf, len);
}
pio_write_8((void *)0xcf8, 0);
pio_write_8(0xcf8, 0);
return 1;
}
 
/branches/dd/uspace/srv/pci/libpci/pci.h
26,6 → 26,7
/* Known access methods, remember to update access.c as well */
PCI_ACCESS_I386_TYPE1, /* i386 ports, type 1 (params: none) */
PCI_ACCESS_I386_TYPE2, /* i386 ports, type 2 (params: none) */
PCI_ACCESS_US2I,
PCI_ACCESS_MAX
};
 
/branches/dd/uspace/srv/pci/libpci/access.c
16,8 → 16,19
#include "internal.h"
 
static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = {
#ifdef UARCH_ia32
&pm_intel_conf1,
&pm_intel_conf2,
#else
0,
0,
#endif
#ifdef UARCH_sparc64
&pm_us2i
#else
0
#endif
};
 
struct pci_access *pci_alloc(void)
/branches/dd/uspace/srv/pci/libpci/internal.h
38,6 → 38,6
struct pci_dev *pci_alloc_dev(struct pci_access *);
int pci_link_dev(struct pci_access *, struct pci_dev *);
 
extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_linux_proc,
extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_us2i, pm_linux_proc,
pm_fbsd_device, pm_aix_device, pm_nbsd_libpci, pm_obsd_device,
pm_dump, pm_linux_sysfs;
/branches/dd/uspace/srv/pci/libpci/us2i.c
0,0 → 1,125
#include <unistd.h>
#include <ddi.h>
#include <libarch/ddi.h>
#include <stdio.h>
 
#include "internal.h"
#include "header.h"
 
/* physical addresses and offsets */
#define U2P_BASE 0x1FE00000000
#define PCI_CONF_OFFSET 0x001000000
#define PCI_CONF_SIZE 0x001000000
#define PCI_CONF_BASE (U2P_BASE + PCI_CONF_OFFSET)
 
/* virtual address of PCI configuration space */
static void *conf_addr = 0;
 
/*
* virtual address of specified PCI configuration register:
* bus ... bus number (0 for top level PCI bus B, 1 for top level PCI bus A)
* dev ... device number (0 - 15)
* fn ... function number (0 - 7)
* reg ... register number (register's position within PCI configuration header)
**/
#define CONF_ADDR(bus, dev, fn, reg) (conf_addr + ((bus << 16) | (dev << 11) | (fn << 8) | (reg << 2)))
 
 
static void us2i_init(struct pci_access *a)
{
}
 
static void us2i_cleanup(struct pci_access *a UNUSED)
{
}
 
static int us2i_detect(struct pci_access *a)
{
unsigned int tmp;
/*
* Gain control over PCI configuration ports.
*/
if (pio_enable((void *)PCI_CONF_BASE, PCI_CONF_SIZE, &conf_addr)) {
return 0;
}
printf("PCI: conf_addr = %lx", conf_addr);
printf("PCI: vendor id address = %lx", CONF_ADDR(0, 0, 0, PCI_VENDOR_ID));
asm volatile ("sethi 0x42224, %g0");
int vendor_id = pio_read_16(CONF_ADDR(0, 0, 0, PCI_VENDOR_ID));
vendor_id = vendor_id | pio_read_8(CONF_ADDR(0, 0, 0, PCI_VENDOR_ID + 1)) << 8;
int device_id = pio_read_8(CONF_ADDR(0, 0, 0, PCI_DEVICE_ID));
device_id = device_id | pio_read_8(CONF_ADDR(0, 0, 0, PCI_DEVICE_ID + 1)) << 8;
printf("PCI: vendor id = %x", vendor_id);
printf("PCI: device id = %x", device_id);
 
return vendor_id == 0x108E && device_id == 0x8000; // should be Psycho from Sun Microsystems
}
 
static int us2i_read(struct pci_dev *d, int pos, byte * buf, int len)
{
if (pos >= 256)
return 0;
 
switch (len) {
case 1:
buf[0] = pio_read_8(CONF_ADDR(d->bus, d->dev, d->func, pos));
break;
case 2:
us2i_read(d, pos + 1, buf, 1); // unlike PCI, sparc uses big endian
us2i_read(d, pos, buf + 1, 1);
break;
case 4:
us2i_read(d, pos + 3, buf, 1); // endians in an ugly way ... FIX ME
us2i_read(d, pos + 2, buf + 1, 1);
us2i_read(d, pos + 1, buf + 2, 1);
us2i_read(d, pos, buf + 3, 1);
break;
default:
return pci_generic_block_read(d, pos, buf, len);
}
return 1;
}
 
static int us2i_write(struct pci_dev *d, int pos, byte * buf, int len)
{
if (pos >= 256)
return 0;
 
switch (len) {
case 1:
pio_write_8(CONF_ADDR(d->bus, d->dev, d->func, pos), buf[0]);
break;
case 2:
us2i_write(d, pos + 1, buf, 1); // unlike PCI, sparc uses big endian
us2i_write(d, pos, buf + 1, 1);
break;
case 4:
us2i_write(d, pos + 3, buf, 1); // endians in an ugly way ... FIX ME
us2i_write(d, pos + 2, buf + 1, 1);
us2i_write(d, pos + 1, buf + 2, 1);
us2i_write(d, pos, buf + 3, 1);
break;
default:
return pci_generic_block_write(d, pos, buf, len);
}
return 1;
}
 
 
struct pci_methods pm_us2i = {
"Ultra Sparc IIi",
NULL, /* config */
us2i_detect,
us2i_init,
us2i_cleanup,
pci_generic_scan,
pci_generic_fill_info,
us2i_read,
us2i_write,
NULL, /* init_dev */
NULL /* cleanup_dev */
};
/branches/dd/uspace/srv/pci/libpci/Makefile
15,7 → 15,7
 
PCILIB=libpci.a
 
OBJS += i386-ports.o
OBJS += i386-ports.o us2i.o
 
all: $(PCILIB)
 
/branches/dd/uspace/srv/pci/pci.c
22,9 → 22,6
 
#include "libpci/pci.h"
 
#define PCI_CONF1 0xcf8
#define PCI_CONF1_SIZE 8
 
#define NAME "PCI"
 
static struct pci_access *pacc;
37,13 → 34,7
ipcarg_t ns_in_phone_hash;
 
printf("%s: HelenOS PCI driver\n", NAME);
 
/*
* Gain control over PCI configuration ports.
*/
void * addr;
pio_enable((void *) PCI_CONF1, PCI_CONF1_SIZE, &addr);
 
pacc = pci_alloc(); /* Get the pci_access structure */
pci_init(pacc); /* Initialize the PCI library */
pci_scan_bus(pacc); /* We want to get the list of devices */
/branches/dd/uspace/Makefile
65,7 → 65,8
ifeq ($(UARCH),sparc64)
DIRS += \
srv/fhc \
srv/obio
srv/obio \
srv/pci
endif
 
BUILDS := $(addsuffix .build,$(DIRS))