start rewrite of pci_find_classcode

was scanning PCI config space of all valid slot/bus combination when all needed information is already available from the initial scan.
This commit is contained in:
Markus Fröschle
2016-12-05 07:03:16 +00:00
parent 6880e4c3a0
commit fda5616124
8 changed files with 52 additions and 81 deletions

View File

@@ -198,11 +198,11 @@ typedef struct /* structure of address conversion */
#define PCI_STATUS(i) ((i) & 0xffff) #define PCI_STATUS(i) ((i) & 0xffff)
#define PCI_COMMAND(i) (((i) >> 16) & 0xffff) #define PCI_COMMAND(i) (((i) >> 16) & 0xffff)
/* register 0x08 macros */ /* register 0x08 macros (use on little endian value!) */
#define PCI_CLASS_CODE(i) (((i) & 0xff000000) >> 24) #define PCI_CLASS_CODE(i) (((i) & 0x00ff0000) >> 16)
#define PCI_SUBCLASS(i) (((i) & 0x00ff0000) >> 16) #define PCI_SUBCLASS(i) (((i) & 0x0000ff00) >> 8)
#define PCI_PROG_IF(i) (((i) & 0x0000ff00) >> 8) #define PCI_PROG_IF(i) (((i) & 0x000000ff) >> 0)
#define PCI_REVISION_ID(i) (((i) & 0x000000ff)) #define PCI_REVISION_ID(i) (((i) & 0xff000000) >> 24)
/* register 0x0c macros */ /* register 0x0c macros */
#define PCI_BIST(i) (((i) & 0xff000000) >> 24) #define PCI_BIST(i) (((i) & 0xff000000) >> 24)

View File

@@ -12,6 +12,8 @@
#include "wait.h" #include "wait.h"
#include "video.h" #include "video.h"
#define RADEON_TILING
//#include "radeon_theatre.h" //#include "radeon_theatre.h"
#include "radeon_reg.h" #include "radeon_reg.h"

View File

@@ -34,7 +34,7 @@
#include "interrupts.h" #include "interrupts.h"
#include "wait.h" #include "wait.h"
// // #define DEBUG #define DEBUG
#include "debug.h" #include "debug.h"
#define pci_config_wait() do { __asm__ __volatile("tpf" ::: "memory"); } while (0) #define pci_config_wait() do { __asm__ __volatile("tpf" ::: "memory"); } while (0)
@@ -513,81 +513,55 @@ int32_t pci_find_device(uint16_t device_id, uint16_t vendor_id, int index)
*/ */
int32_t pci_find_classcode(uint32_t classcode, int index) int32_t pci_find_classcode(uint32_t classcode, int index)
{ {
uint16_t bus; int i;
uint16_t device; uint32_t handle;
uint16_t function = 0; uint32_t ret = PCI_DEVICE_NOT_FOUND;
uint16_t n = 0; int n = 0;
int32_t handle; uint8_t find_mask;
for (bus = 0; bus < 2; bus++)
{
for (device = 10; device < 31; device++)
{
uint32_t value; uint32_t value;
uint8_t htr; int cmp;
bool match = false;
handle = PCI_HANDLE(bus, device, 0); classcode = swpl(classcode);
dbg("check handle %d\r\n", handle); find_mask = classcode & 0xff;
classcode >>= 8;
value = swpl(pci_read_config_longword(handle, PCIIDR)); do
{
if (value != 0xffffffff) /* device found */ for (i = 0; (handle = handles[i]) != -1; i++)
{
match = false;
for (cmp = 0; cmp < 3; cmp++)
{
if ((find_mask >> cmp) & 1)
{ {
value = swpl(pci_read_config_longword(handle, PCICCR)); value = swpl(pci_read_config_longword(handle, PCICCR));
dbg("compare classcode (0x%x), 0x%x against value (0x%x) 0x%x\r\n",
dbg("classcode to search for=%x\r\n", classcode); classcode, (classcode >> (cmp * 8)) & 0xff, value, (value >> (cmp * 8)) & 0xff);
dbg("PCI_CLASSCODE found=%02x\r\n", PCI_CLASS_CODE(value)); if (((classcode >> (cmp * 8)) & 0xff) == ((value >> (cmp * 8)) & 0xff))
dbg("PCI_SUBCLASS found=%02x\r\n", PCI_SUBCLASS(value));
dbg("PCI_PROG_IF found=%02x\r\n", PCI_PROG_IF(value));
if ((classcode & (1 << 26) ? ((PCI_CLASS_CODE(value) == (classcode & 0xff))) : true) &&
(classcode & (1 << 25) ? ((PCI_SUBCLASS(value) == ((classcode & 0xff00) >> 8))) : true) &&
(classcode & (1 << 24) ? ((PCI_PROG_IF(value) == ((classcode & 0xff0000) >> 16))) : true))
{ {
if (n == index) if (n == index)
{
dbg("found device at handle %d\r\n", handle);
return handle; return handle;
}
n++; n++;
} }
else
{
match = false;
goto next;
}
}
else
match = true;
}
/* next:
* there is a device at this position, but not the one we are looking for. ;
* Check to see if it is a multi-function device. We need to look "behind" it }
* for the other functions in that case. } while (n < index);
*/
if ((htr = pci_read_config_byte(handle, PCI_LANESWAP_B(PCIHTR))) & 0x80)
{
/* yes, this is a multi-function device, look for more functions */
for (function = 1; function < 8; function++) if (match)
{ ret = handle;
handle = PCI_HANDLE(bus, device, function); return ret;
value = pci_read_config_longword(handle, PCIIDR);
if (value != 0xffffffff) /* device found */
{
value = swpl(pci_read_config_longword(handle, PCICCR));
if ((classcode & PCI_FIND_BASE_CLASS ? ((PCI_CLASS_CODE(value) == (classcode & 0xff))) : true) &&
(classcode & PCI_FIND_SUB_CLASS ? ((PCI_SUBCLASS(value) == ((classcode & 0xff00) >> 8))) : true) &&
(classcode & PCI_FIND_PROG_IF ? ((PCI_PROG_IF(value) == ((classcode & 0xff0000) >> 16))) : true))
{
if (n == index)
{
dbg("found device with handle %d\n", handle);
return handle;
}
n++;
}
}
}
}
}
}
}
return PCI_DEVICE_NOT_FOUND;
} }
int32_t pci_hook_interrupt(int32_t handle, void *handler, void *parameter) int32_t pci_hook_interrupt(int32_t handle, void *handler, void *parameter)

View File

@@ -1982,7 +1982,7 @@ int radeonfb_set_par(struct fb_info *info)
#endif #endif
memcpy(&rinfo->state, newmode, sizeof(*newmode)); memcpy(&rinfo->state, newmode, sizeof(*newmode));
#ifdef RADEON_TILING #ifdef RADEON_TILING
rinfo->tilingEnabled = (mode->vmode & (FB_VMODE_DOUBLE | FB_VMODE_INTERLACED)) ? FALSE : TRUE; rinfo->tilingEnabled = (mode->vmode & (FB_VMODE_DOUBLE | FB_VMODE_INTERLACED)) ? false : true;
#endif #endif
radeon_write_mode(rinfo, newmode, 0); radeon_write_mode(rinfo, newmode, 0);
/* (re)initialize the engine */ /* (re)initialize the engine */

View File

@@ -3,7 +3,7 @@
#include "exceptions.h" #include "exceptions.h"
#include "pci.h" #include "pci.h"
#define DEBUG // #define DEBUG
#include "debug.h" #include "debug.h"
/* /*

View File

@@ -53,7 +53,7 @@
#include "usb.h" #include "usb.h"
#include "video.h" #include "video.h"
// // #define DEBUG #define DEBUG
#include "debug.h" #include "debug.h"
#define UNUSED(x) (void)(x) /* Unused variable */ #define UNUSED(x) (void)(x) /* Unused variable */
@@ -588,11 +588,11 @@ void init_usb(void)
int usb_found = 0; int usb_found = 0;
int index = 0; int index = 0;
xprintf("USB controller initialization:\r\n"); inf("USB controller initialization:\r\n");
do do
{ {
handle = pci_find_classcode(PCI_CLASS_SERIAL_USB | PCI_FIND_BASE_CLASS | PCI_FIND_SUB_CLASS, index++); handle = pci_find_classcode(PCI_CLASS_SERIAL_USB | PCI_FIND_BASE_CLASS | PCI_FIND_SUB_CLASS | PCI_FIND_PROG_IF, index++);
dbg("handle 0x%02x\r\n", handle); dbg("handle 0x%02x\r\n", handle);
if (handle > 0) if (handle > 0)
{ {

View File

@@ -54,7 +54,7 @@
#include "usb.h" #include "usb.h"
#include "usb_hub.h" #include "usb_hub.h"
// // #define DEBUG // #define DEBUG
#include "debug.h" #include "debug.h"
struct hci struct hci

View File

@@ -286,7 +286,7 @@ static struct fb_var_screeninfo default_fb =
.xres = 1280, .xres = 1280,
.yres = 1024, .yres = 1024,
.xres_virtual = 1280, .xres_virtual = 1280,
.yres_virtual = 1024, .yres_virtual = 1024 * 2, /* ensure we have accel offscreen space */
.bits_per_pixel = 8, .bits_per_pixel = 8,
.grayscale = 0, .grayscale = 0,
.red = { .length = 8 }, .red = { .length = 8 },
@@ -364,11 +364,6 @@ void video_init(void)
int32_t id; int32_t id;
bool radeon_found = false; bool radeon_found = false;
dbg("\r\n");
/* FIXME: we currently just return here because the PCI configuration of ATI cards does not (yet) work */
//return;
do do
{ {
/* /*