Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 4294 → Rev 4295

/branches/dd/uspace/srv/pci/libpci/pci.h
26,7 → 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_US2,
PCI_ACCESS_MAX
};
 
/branches/dd/uspace/srv/pci/libpci/access.c
25,7 → 25,7
#endif
#ifdef UARCH_sparc64
&pm_us2i
&pm_us2
#else
0
#endif
/branches/dd/uspace/srv/pci/libpci/internal.h
38,4 → 38,4
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_us2i;
extern struct pci_methods pm_intel_conf1, pm_intel_conf2, pm_us2;
/branches/dd/uspace/srv/pci/libpci/us2.c
18,33 → 18,23
/*
* 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)
* dev ... device number (0 - 31)
* fn ... function number (0 - 7)
* reg ... register number (register's position within PCI configuration header)
**/
#define CONF_ADDR(bus, dev, fn, reg) ((void *)(conf_addr + ((bus << 16) | (dev << 11) | (fn << 8) | (reg << 0))))
#define CONF_ADDR(bus, dev, fn, reg) ((void *)(conf_addr + ((bus << 16) | (dev << 11) | (fn << 8) | reg)))
 
 
 
static void us2i_init(struct pci_access *a)
static void us2_init(struct pci_access *a)
{
}
 
static void us2i_cleanup(struct pci_access *a UNUSED)
static void us2_cleanup(struct pci_access *a UNUSED)
{
}
 
static inline uint64_t pio_read_64(uint64_t *port)
{
uint64_t rv;
 
rv = *port;
memory_barrier();
 
return rv;
}
 
static int us2i_detect(struct pci_access *a)
static int us2_detect(struct pci_access *a)
{
/*
* Gain control over PCI configuration ports.
53,164 → 43,58
return 0;
}
 
int vendor_id = le16_to_cpu(pio_read_16(CONF_ADDR(0, 0, 0, PCI_VENDOR_ID)));
int device_id = le16_to_cpu(pio_read_16(CONF_ADDR(0, 0, 0, PCI_DEVICE_ID)));
unsigned int vendor_id = le16_to_cpu(pio_read_16(CONF_ADDR(0, 0, 0, PCI_VENDOR_ID)));
unsigned int device_id = le16_to_cpu(pio_read_16(CONF_ADDR(0, 0, 0, PCI_DEVICE_ID)));
printf("PCI: vendor id = %x\n", vendor_id);
printf("PCI: device id = %x\n", device_id);
// printf("PCI: vendor id = %x\n", vendor_id);
// printf("PCI: device id = %x\n", device_id);
 
return vendor_id == 0x108E && device_id == 0x8000; // should be Psycho from Sun Microsystems
}
 
/** Compute new starting position of the operation if byte twisting is used.
*
* See chapter 10.2 of the UPA to PCI Interface User's Manual.
* Note: byte twisting is used only for devices beyond the UPA
* to PCI bridge, not for the device of the bridge itself.
* Configuration registers of the bridge must be read in a different way.
*
* @param pos The original starting position of the read/write operation.
* @param len The length of the read/write operation (<= 4).
* @return New starting position of the operation.
*/
static int byte_twist(int pos, int len)
{
int end = (pos + len) % 4;
if (end == 0) {
end = 4;
}
int begin = 4 - end;
pos = pos - pos % 4 + begin;
return pos;
}
 
/*
static int byte_twist(pos)
{
return pos - pos % 4 + (3 - pos % 4);
}*/
 
static int us2i_read(struct pci_dev *d, int pos, byte * buf, int len)
{
/*void * addr = CONF_ADDR(d->bus, d->dev, d->func, pos);
static int us2_read(struct pci_dev *d, int pos, byte * buf, int len)
{
if (pos >= 256)
return 0;
 
switch (len) {
case 1:
us2i_read_aligned(d->bus, d->dev, d->func, pos, buf, len);
break;
case 2:
us2i_read_aligned(d->bus, d->dev, d->func, pos, buf, len);
((u16 *) buf)[0] = cpu_to_le16(*((u16 *) buf));
break;
case 4:
us2i_read_aligned(d->bus, d->dev, d->func, pos, buf, len);
((u32 *) buf)[0] = cpu_to_le32(*((u32 *) buf));
break;
default:
return pci_generic_block_read(d, pos, buf, len);
}
return 1; */
return 0;
if (len <= 4) {
int twist = d->dev != 0 || d->func != 0;
if (twist) {
pos = byte_twist(pos, len);
}
int i;
for (i = 0; i < len; i++) {
void * addr = CONF_ADDR(d->bus, d->dev, d->func, pos + i);
if (byte_twist) {
buf[i] = pio_read_8(addr);
}
else {
buf[len-i-1] = pio_read_8(addr);
}
}
} else {
return pci_generic_block_read(d, pos, buf, len);
/* The vendor ID and the device ID registers of the device number 0 (the bridge)
* work in simics in different way than the other config. registers. */
if (d->dev == 0 && d->func == 0 && pos == 0 && len == 4) {
((u32 *) buf)[0] = pio_read_32(CONF_ADDR(d->bus, d->dev, d->func, pos));
return 1;
}
return 1;
/*void * addr = CONF_ADDR(d->bus, d->dev, d->func, pos);
if (pos >= 256)
return 0;
 
switch (len) {
case 1:
buf[0] = pio_read_8(addr);
break;
case 2:
((u16 *) buf)[0] = cpu_to_le16(pio_read_16(addr));
break;
case 4:
((u32 *) buf)[0] = cpu_to_le32(pio_read_32(addr));
break;
default:
return pci_generic_block_read(d, pos, buf, len);
int i;
for (i = 0; i < len; i++) {
buf[i] = pio_read_8(CONF_ADDR(d->bus, d->dev, d->func, pos + i));
}
return 1; */
 
/*
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)
static int us2_write(struct pci_dev *d, int pos, byte * buf, int len)
{
void * addr = CONF_ADDR(d->bus, d->dev, d->func, pos);
 
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:
pio_write_16(addr, le16_to_cpu(((u16 *) buf)[0]));
break;
case 4:
pio_write_32(addr, le32_to_cpu(((u32 *) buf)[0]));
break;
default:
return pci_generic_block_write(d, pos, buf, len);
int i;
for (i = 0; i < len; i++) {
pio_write_8(CONF_ADDR(d->bus, d->dev, d->func, pos + i), buf[i]);
}
return 1;
}
 
 
struct pci_methods pm_us2i = {
struct pci_methods pm_us2 = {
"Ultra Sparc IIi",
NULL, /* config */
us2i_detect,
us2i_init,
us2i_cleanup,
us2_detect,
us2_init,
us2_cleanup,
pci_generic_scan,
pci_generic_fill_info,
us2i_read,
us2i_write,
us2_read,
us2_write,
NULL, /* init_dev */
NULL /* cleanup_dev */
};
/branches/dd/uspace/srv/pci/libpci/generic.c
49,6 → 49,7
d->known_fields = PCI_FILL_IDENT;
d->hdrtype = ht;
pci_link_dev(a, d);
switch (ht) {
case PCI_HEADER_TYPE_NORMAL:
break;
/branches/dd/uspace/srv/pci/pci.c
35,7 → 35,7
 
printf("%s: HelenOS PCI driver\n", NAME);
pacc = pci_alloc(); /* Get the pci_access structure */
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 */
for(dev=pacc->devices; dev; dev=dev->next) { /* Iterate over all devices */