PCI bus manager: changed the type of domain from int to uint8.

* fixed narrowing conversion problem found by GCC 4.7.
This commit is contained in:
Jérôme Duval 2013-04-26 18:17:51 +02:00
parent f92b1f2eaf
commit 8b9c0710cd
8 changed files with 84 additions and 74 deletions

View File

@ -21,7 +21,7 @@ pci_get_msi_count(uint8 virtualBus, uint8 _device, uint8 function)
return 0;
uint8 bus;
int domain;
uint8 domain;
if (gPCI->ResolveVirtualBus(virtualBus, &domain, &bus) != B_OK)
return 0;
@ -48,7 +48,7 @@ pci_configure_msi(uint8 virtualBus, uint8 _device, uint8 function,
return B_BAD_VALUE;
uint8 bus;
int domain;
uint8 domain;
status_t result = gPCI->ResolveVirtualBus(virtualBus, &domain, &bus);
if (result != B_OK)
return result;
@ -102,7 +102,7 @@ pci_unconfigure_msi(uint8 virtualBus, uint8 _device, uint8 function)
return B_UNSUPPORTED;
uint8 bus;
int domain;
uint8 domain;
status_t result = gPCI->ResolveVirtualBus(virtualBus, &domain, &bus);
if (result != B_OK)
return result;
@ -138,7 +138,7 @@ pci_enable_msi(uint8 virtualBus, uint8 _device, uint8 function)
return B_UNSUPPORTED;
uint8 bus;
int domain;
uint8 domain;
status_t result = gPCI->ResolveVirtualBus(virtualBus, &domain, &bus);
if (result != B_OK)
return result;
@ -176,7 +176,7 @@ pci_disable_msi(uint8 virtualBus, uint8 _device, uint8 function)
return B_UNSUPPORTED;
uint8 bus;
int domain;
uint8 domain;
status_t result = gPCI->ResolveVirtualBus(virtualBus, &domain, &bus);
if (result != B_OK)
return result;

View File

@ -47,7 +47,7 @@ pci_read_config(uint8 virtualBus, uint8 device, uint8 function, uint8 offset,
uint8 size)
{
uint8 bus;
int domain;
uint8 domain;
uint32 value;
if (gPCI->ResolveVirtualBus(virtualBus, &domain, &bus) != B_OK)
@ -66,7 +66,7 @@ pci_write_config(uint8 virtualBus, uint8 device, uint8 function, uint8 offset,
uint8 size, uint32 value)
{
uint8 bus;
int domain;
uint8 domain;
if (gPCI->ResolveVirtualBus(virtualBus, &domain, &bus) != B_OK)
return;
@ -79,7 +79,7 @@ pci_find_capability(uchar virtualBus, uchar device, uchar function,
uchar capID, uchar *offset)
{
uint8 bus;
int domain;
uint8 domain;
if (gPCI->ResolveVirtualBus(virtualBus, &domain, &bus) != B_OK)
return B_ERROR;
@ -93,7 +93,7 @@ pci_reserve_device(uchar virtualBus, uchar device, uchar function,
{
status_t status;
uint8 bus;
int domain;
uint8 domain;
TRACE(("pci_reserve_device(%d, %d, %d, %s)\n", virtualBus, device, function,
driverName));
@ -118,7 +118,7 @@ pci_reserve_device(uchar virtualBus, uchar device, uchar function,
{B_DEVICE_BUS, B_STRING_TYPE, {string: "pci"}},
// location on PCI bus
{B_PCI_DEVICE_DOMAIN, B_UINT32_TYPE, {ui32: domain}},
{B_PCI_DEVICE_DOMAIN, B_UINT8_TYPE, {ui8: domain}},
{B_PCI_DEVICE_BUS, B_UINT8_TYPE, {ui8: bus}},
{B_PCI_DEVICE_DEVICE, B_UINT8_TYPE, {ui8: device}},
{B_PCI_DEVICE_FUNCTION, B_UINT8_TYPE, {ui8: function}},
@ -191,7 +191,7 @@ pci_unreserve_device(uchar virtualBus, uchar device, uchar function,
{
status_t status;
uint8 bus;
int domain;
uint8 domain;
TRACE(("pci_unreserve_device(%d, %d, %d, %s)\n", virtualBus, device,
function, driverName));
@ -210,7 +210,7 @@ pci_unreserve_device(uchar virtualBus, uchar device, uchar function,
{B_DEVICE_BUS, B_STRING_TYPE, {string: "pci"}},
// location on PCI bus
{B_PCI_DEVICE_DOMAIN, B_UINT32_TYPE, {ui32: domain}},
{B_PCI_DEVICE_DOMAIN, B_UINT8_TYPE, {ui8: domain}},
{B_PCI_DEVICE_BUS, B_UINT8_TYPE, {ui8: bus}},
{B_PCI_DEVICE_DEVICE, B_UINT8_TYPE, {ui8: device}},
{B_PCI_DEVICE_FUNCTION, B_UINT8_TYPE, {ui8: function}},
@ -288,7 +288,7 @@ pci_update_interrupt_line(uchar virtualBus, uchar device, uchar function,
uchar newInterruptLineValue)
{
uint8 bus;
int domain;
uint8 domain;
if (gPCI->ResolveVirtualBus(virtualBus, &domain, &bus) != B_OK)
return B_ERROR;
@ -299,7 +299,7 @@ pci_update_interrupt_line(uchar virtualBus, uchar device, uchar function,
// used by pci_info.cpp print_info_basic()
void
__pci_resolve_virtual_bus(uint8 virtualBus, int *domain, uint8 *bus)
__pci_resolve_virtual_bus(uint8 virtualBus, uint8 *domain, uint8 *bus)
{
if (gPCI->ResolveVirtualBus(virtualBus, domain, bus) < B_OK)
panic("ResolveVirtualBus failed");
@ -532,7 +532,7 @@ void
PCI::InitBus()
{
PCIBus **nextBus = &fRootBus;
for (int i = 0; i < fDomainCount; i++) {
for (uint8 i = 0; i < fDomainCount; i++) {
PCIBus *bus = new PCIBus;
bus->next = NULL;
bus->parent = NULL;
@ -544,13 +544,13 @@ PCI::InitBus()
}
if (fBusEnumeration) {
for (int i = 0; i < fDomainCount; i++) {
for (uint8 i = 0; i < fDomainCount; i++) {
_EnumerateBus(i, 0);
}
}
if (1) {
for (int i = 0; i < fDomainCount; i++) {
for (uint8 i = 0; i < fDomainCount; i++) {
_FixupDevices(i, 0);
}
}
@ -570,7 +570,7 @@ PCI::~PCI()
status_t
PCI::_CreateVirtualBus(int domain, uint8 bus, uint8 *virtualBus)
PCI::_CreateVirtualBus(uint8 domain, uint8 bus, uint8 *virtualBus)
{
#if defined(__INTEL__) || defined(__x86_64__)
@ -584,22 +584,23 @@ PCI::_CreateVirtualBus(int domain, uint8 bus, uint8 *virtualBus)
if (fNextVirtualBus > 0xff)
panic("PCI::CreateVirtualBus: virtual bus number space exhausted");
if (unsigned(domain) > 0xff)
panic("PCI::CreateVirtualBus: domain %d too large", domain);
uint16 value = domain << 8 | bus;
for (VirtualBusMap::Iterator it = fVirtualBusMap.Begin(); it != fVirtualBusMap.End(); ++it) {
for (VirtualBusMap::Iterator it = fVirtualBusMap.Begin();
it != fVirtualBusMap.End(); ++it) {
if (it->Value() == value) {
*virtualBus = it->Key();
FLOW("PCI::CreateVirtualBus: domain %d, bus %d already in map => virtualBus %d\n", domain, bus, *virtualBus);
FLOW("PCI::CreateVirtualBus: domain %d, bus %d already in map => "
"virtualBus %d\n", domain, bus, *virtualBus);
return B_OK;
}
}
*virtualBus = fNextVirtualBus++;
FLOW("PCI::CreateVirtualBus: domain %d, bus %d => virtualBus %d\n", domain, bus, *virtualBus);
FLOW("PCI::CreateVirtualBus: domain %d, bus %d => virtualBus %d\n", domain,
bus, *virtualBus);
return fVirtualBusMap.Insert(*virtualBus, value);
@ -608,7 +609,7 @@ PCI::_CreateVirtualBus(int domain, uint8 bus, uint8 *virtualBus)
status_t
PCI::ResolveVirtualBus(uint8 virtualBus, int *domain, uint8 *bus)
PCI::ResolveVirtualBus(uint8 virtualBus, uint8 *domain, uint8 *bus)
{
#if defined(__INTEL__) || defined(__x86_64__)
@ -650,20 +651,21 @@ PCI::AddController(pci_controller *controller, void *controller_cookie)
void
PCI::InitDomainData()
{
for (int i = 0; i < fDomainCount; i++) {
for (uint8 i = 0; i < fDomainCount; i++) {
int32 count;
status_t status;
status = (*fDomainData[i].controller->get_max_bus_devices)(fDomainData[i].controller_cookie, &count);
status = (*fDomainData[i].controller->get_max_bus_devices)(
fDomainData[i].controller_cookie, &count);
fDomainData[i].max_bus_devices = (status == B_OK) ? count : 0;
}
}
domain_data *
PCI::_GetDomainData(int domain)
PCI::_GetDomainData(uint8 domain)
{
if (domain < 0 || domain >= fDomainCount)
if (domain >= fDomainCount)
return NULL;
return &fDomainData[domain];
@ -671,7 +673,7 @@ PCI::_GetDomainData(int domain)
inline int
PCI::_NumFunctions(int domain, uint8 bus, uint8 device)
PCI::_NumFunctions(uint8 domain, uint8 bus, uint8 device)
{
uint8 type = ReadConfig(domain, bus, device,
0, PCI_header_type, 1);
@ -716,7 +718,7 @@ PCI::_GetNthInfo(PCIBus *bus, long *currentIndex, long wantIndex,
void
PCI::_EnumerateBus(int domain, uint8 bus, uint8 *subordinateBus)
PCI::_EnumerateBus(uint8 domain, uint8 bus, uint8 *subordinateBus)
{
TRACE(("PCI: EnumerateBus: domain %u, bus %u\n", domain, bus));
@ -854,7 +856,7 @@ PCI::_EnumerateBus(int domain, uint8 bus, uint8 *subordinateBus)
void
PCI::_FixupDevices(int domain, uint8 bus)
PCI::_FixupDevices(uint8 domain, uint8 bus)
{
FLOW("PCI: FixupDevices domain %u, bus %u\n", domain, bus);
@ -1100,7 +1102,7 @@ PCI::_DiscoverDevice(PCIBus *bus, uint8 dev, uint8 function)
PCIBus *
PCI::_CreateBus(PCIDev *parent, int domain, uint8 bus)
PCI::_CreateBus(PCIDev *parent, uint8 domain, uint8 bus)
{
PCIBus *newBus = new(std::nothrow) PCIBus;
if (newBus == NULL)
@ -1122,7 +1124,8 @@ PCI::_CreateBus(PCIDev *parent, int domain, uint8 bus)
PCIDev *
PCI::_CreateDevice(PCIBus *parent, uint8 device, uint8 function)
{
FLOW("PCI: CreateDevice, domain %u, bus %u, dev %u, func %u:\n", parent->domain, parent->bus, device, function);
FLOW("PCI: CreateDevice, domain %u, bus %u, dev %u, func %u:\n", parent->domain,
parent->bus, device, function);
PCIDev *newDev = new(std::nothrow) PCIDev;
if (newDev == NULL)
@ -1138,8 +1141,9 @@ PCI::_CreateDevice(PCIBus *parent, uint8 device, uint8 function)
_ReadBasicInfo(newDev);
FLOW("PCI: CreateDevice, vendor 0x%04x, device 0x%04x, class_base 0x%02x, class_sub 0x%02x\n",
newDev->info.vendor_id, newDev->info.device_id, newDev->info.class_base, newDev->info.class_sub);
FLOW("PCI: CreateDevice, vendor 0x%04x, device 0x%04x, class_base 0x%02x, "
"class_sub 0x%02x\n", newDev->info.vendor_id, newDev->info.device_id,
newDev->info.class_base, newDev->info.class_sub);
// append
if (parent->child == NULL) {
@ -1451,7 +1455,7 @@ PCI::_RefreshDeviceInfo(PCIBus *bus)
status_t
PCI::ReadConfig(int domain, uint8 bus, uint8 device, uint8 function,
PCI::ReadConfig(uint8 domain, uint8 bus, uint8 device, uint8 function,
uint8 offset, uint8 size, uint32 *value)
{
domain_data *info = _GetDomainData(domain);
@ -1474,7 +1478,7 @@ PCI::ReadConfig(int domain, uint8 bus, uint8 device, uint8 function,
uint32
PCI::ReadConfig(int domain, uint8 bus, uint8 device, uint8 function,
PCI::ReadConfig(uint8 domain, uint8 bus, uint8 device, uint8 function,
uint8 offset, uint8 size)
{
uint32 value;
@ -1499,7 +1503,7 @@ PCI::ReadConfig(PCIDev *device, uint8 offset, uint8 size)
status_t
PCI::WriteConfig(int domain, uint8 bus, uint8 device, uint8 function,
PCI::WriteConfig(uint8 domain, uint8 bus, uint8 device, uint8 function,
uint8 offset, uint8 size, uint32 value)
{
domain_data *info = _GetDomainData(domain);
@ -1530,7 +1534,7 @@ PCI::WriteConfig(PCIDev *device, uint8 offset, uint8 size, uint32 value)
status_t
PCI::FindCapability(int domain, uint8 bus, uint8 device, uint8 function,
PCI::FindCapability(uint8 domain, uint8 bus, uint8 device, uint8 function,
uint8 capID, uint8 *offset)
{
if (offset == NULL) {
@ -1597,14 +1601,14 @@ PCI::FindCapability(PCIDev *device, uint8 capID, uint8 *offset)
PCIDev *
PCI::FindDevice(int domain, uint8 bus, uint8 device, uint8 function)
PCI::FindDevice(uint8 domain, uint8 bus, uint8 device, uint8 function)
{
return _FindDevice(fRootBus, domain, bus, device, function);
}
PCIDev *
PCI::_FindDevice(PCIBus *current, int domain, uint8 bus, uint8 device,
PCI::_FindDevice(PCIBus *current, uint8 domain, uint8 bus, uint8 device,
uint8 function)
{
if (current->domain == domain) {
@ -1635,7 +1639,7 @@ PCI::_FindDevice(PCIBus *current, int domain, uint8 bus, uint8 device,
status_t
PCI::UpdateInterruptLine(int domain, uint8 bus, uint8 _device, uint8 function,
PCI::UpdateInterruptLine(uint8 domain, uint8 bus, uint8 _device, uint8 function,
uint8 newInterruptLineValue)
{
PCIDev *device = FindDevice(domain, bus, _device, function);

View File

@ -34,7 +34,7 @@ struct PCIBus {
PCIBus * next;
PCIDev * parent;
PCIDev * child;
int domain;
uint8 domain;
uint8 bus;
};
@ -42,7 +42,7 @@ struct PCIDev {
PCIDev * next;
PCIBus * parent;
PCIBus * child;
int domain;
uint8 domain;
uint8 bus;
uint8 device;
uint8 function;
@ -76,44 +76,45 @@ public:
status_t GetNthInfo(long index, pci_info *outInfo);
status_t ReadConfig(int domain, uint8 bus, uint8 device,
status_t ReadConfig(uint8 domain, uint8 bus, uint8 device,
uint8 function, uint8 offset, uint8 size,
uint32 *value);
uint32 ReadConfig(int domain, uint8 bus, uint8 device,
uint32 ReadConfig(uint8 domain, uint8 bus, uint8 device,
uint8 function, uint8 offset, uint8 size);
uint32 ReadConfig(PCIDev *device, uint8 offset,
uint8 size);
status_t WriteConfig(int domain, uint8 bus, uint8 device,
status_t WriteConfig(uint8 domain, uint8 bus, uint8 device,
uint8 function, uint8 offset, uint8 size,
uint32 value);
status_t WriteConfig(PCIDev *device, uint8 offset,
uint8 size, uint32 value);
status_t FindCapability(int domain, uint8 bus, uint8 device,
uint8 function, uint8 capID, uint8 *offset);
status_t FindCapability(uint8 domain, uint8 bus,
uint8 device, uint8 function, uint8 capID,
uint8 *offset);
status_t FindCapability(PCIDev *device, uint8 capID,
uint8 *offset);
status_t ResolveVirtualBus(uint8 virtualBus, int *domain,
status_t ResolveVirtualBus(uint8 virtualBus, uint8 *domain,
uint8 *bus);
PCIDev * FindDevice(int domain, uint8 bus, uint8 device,
PCIDev * FindDevice(uint8 domain, uint8 bus, uint8 device,
uint8 function);
void ClearDeviceStatus(PCIBus *bus, bool dumpStatus);
void RefreshDeviceInfo();
status_t UpdateInterruptLine(int domain, uint8 bus,
status_t UpdateInterruptLine(uint8 domain, uint8 bus,
uint8 device, uint8 function,
uint8 newInterruptLineValue);
private:
void _EnumerateBus(int domain, uint8 bus,
void _EnumerateBus(uint8 domain, uint8 bus,
uint8 *subordinateBus = NULL);
void _FixupDevices(int domain, uint8 bus);
void _FixupDevices(uint8 domain, uint8 bus);
void _DiscoverBus(PCIBus *bus);
void _DiscoverDevice(PCIBus *bus, uint8 dev,
@ -121,7 +122,8 @@ private:
PCIDev * _CreateDevice(PCIBus *parent, uint8 dev,
uint8 function);
PCIBus * _CreateBus(PCIDev *parent, int domain, uint8 bus);
PCIBus * _CreateBus(PCIDev *parent, uint8 domain,
uint8 bus);
status_t _GetNthInfo(PCIBus *bus, long *currentIndex,
long wantIndex, pci_info *outInfo);
@ -139,14 +141,15 @@ private:
uint32 *address, uint32 *size = 0,
uint8 *flags = 0);
domain_data * _GetDomainData(int domain);
domain_data * _GetDomainData(uint8 domain);
status_t _CreateVirtualBus(int domain, uint8 bus,
status_t _CreateVirtualBus(uint8 domain, uint8 bus,
uint8 *virtualBus);
int _NumFunctions(int domain, uint8 bus, uint8 device);
PCIDev * _FindDevice(PCIBus *current, int domain, uint8 bus,
uint8 device, uint8 function);
int _NumFunctions(uint8 domain, uint8 bus,
uint8 device);
PCIDev * _FindDevice(PCIBus *current, uint8 domain,
uint8 bus, uint8 device, uint8 function);
private:
PCIBus * fRootBus;
@ -154,7 +157,7 @@ private:
enum { MAX_PCI_DOMAINS = 8 };
domain_data fDomainData[MAX_PCI_DOMAINS];
int fDomainCount;
uint8 fDomainCount;
bool fBusEnumeration;
typedef VectorMap<uint8, uint16> VirtualBusMap;
@ -182,7 +185,7 @@ uint32 pci_read_config(uint8 virtualBus, uint8 device, uint8 function,
void pci_write_config(uint8 virtualBus, uint8 device, uint8 function,
uint8 offset, uint8 size, uint32 value);
void __pci_resolve_virtual_bus(uint8 virtualBus, int *domain, uint8 *bus);
void __pci_resolve_virtual_bus(uint8 virtualBus, uint8 *domain, uint8 *bus);
#ifdef __cplusplus
}

View File

@ -107,9 +107,9 @@ pci_device_get_pci_info(pci_device* device, struct pci_info* info)
static status_t
pci_device_init_driver(device_node* node, void** _cookie)
{
uint32 domain;
uint8 domain;
uint8 bus, deviceNumber, function;
if (gDeviceManager->get_attr_uint32(node, B_PCI_DEVICE_DOMAIN, &domain,
if (gDeviceManager->get_attr_uint8(node, B_PCI_DEVICE_DOMAIN, &domain,
false) != B_OK
|| gDeviceManager->get_attr_uint8(node, B_PCI_DEVICE_BUS, &bus,
false) != B_OK

View File

@ -22,7 +22,7 @@
* the IDE driver for the AHCI controller for some reason).
*/
static void
jmicron_fixup_ahci(PCI *pci, int domain, uint8 bus, uint8 device,
jmicron_fixup_ahci(PCI *pci, uint8 domain, uint8 bus, uint8 device,
uint8 function, uint16 deviceId)
{
// We only care about function 0.
@ -80,8 +80,8 @@ jmicron_fixup_ahci(PCI *pci, int domain, uint8 bus, uint8 device,
static void
intel_fixup_ahci(PCI *pci, int domain, uint8 bus, uint8 device, uint8 function,
uint16 deviceId)
intel_fixup_ahci(PCI *pci, uint8 domain, uint8 bus, uint8 device,
uint8 function, uint16 deviceId)
{
// TODO(bga): disabled until the PCI manager can assign new resources.
return;
@ -156,7 +156,8 @@ intel_fixup_ahci(PCI *pci, int domain, uint8 bus, uint8 device, uint8 function,
static void
ati_fixup_ixp(PCI *pci, int domain, uint8 bus, uint8 device, uint8 function, uint16 deviceId)
ati_fixup_ixp(PCI *pci, uint8 domain, uint8 bus, uint8 device, uint8 function,
uint16 deviceId)
{
#if defined(__INTEL__) || defined(__x86_64__)
/* ATI Technologies Inc, IXP chipset:
@ -187,7 +188,8 @@ ati_fixup_ixp(PCI *pci, int domain, uint8 bus, uint8 device, uint8 function, uin
void
pci_fixup_device(PCI *pci, int domain, uint8 bus, uint8 device, uint8 function)
pci_fixup_device(PCI *pci, uint8 domain, uint8 bus, uint8 device,
uint8 function)
{
uint16 vendorId = pci->ReadConfig(domain, bus, device, function,
PCI_vendor_id, 2);

View File

@ -8,7 +8,8 @@
class PCI;
void
pci_fixup_device(PCI *pci, int domain, uint8 bus, uint8 device, uint8 function);
void pci_fixup_device(PCI *pci, uint8 domain, uint8 bus, uint8 device,
uint8 function);
#endif

View File

@ -179,7 +179,7 @@ print_capabilities(const pci_info *info)
static void
print_info_basic(const pci_info *info, bool verbose)
{
int domain;
uint8 domain;
uint8 bus;
__pci_resolve_virtual_bus(info->bus, &domain, &bus);

View File

@ -63,7 +63,7 @@ pci_root_register_child_devices(void* cookie)
pci_info info;
for (int32 i = 0; pci_get_nth_pci_info(i, &info) == B_OK; i++) {
int domain;
uint8 domain;
uint8 bus;
if (gPCI->ResolveVirtualBus(info.bus, &domain, &bus) != B_OK) {
dprintf("FAILED!!!!\n");
@ -75,7 +75,7 @@ dprintf("FAILED!!!!\n");
{B_DEVICE_BUS, B_STRING_TYPE, {string: "pci"}},
// location on PCI bus
{B_PCI_DEVICE_DOMAIN, B_UINT32_TYPE, {ui32: domain}},
{B_PCI_DEVICE_DOMAIN, B_UINT8_TYPE, {ui8: domain}},
{B_PCI_DEVICE_BUS, B_UINT8_TYPE, {ui8: bus}},
{B_PCI_DEVICE_DEVICE, B_UINT8_TYPE, {ui8: info.device}},
{B_PCI_DEVICE_FUNCTION, B_UINT8_TYPE, {ui8: info.function}},