pci: track usage of pci devices by drivers

Warn about if more than one driver uses the same device.

Issue #1487
devel
Alexander Boettcher 8 years ago committed by Christian Helmuth
parent 6c65e436bf
commit 729ae0a838

@ -52,6 +52,12 @@ namespace Pci {
Genode::Session_label _label;
Genode::Session_policy _policy;
enum { MAX_PCI_DEVICES = Device_config::MAX_BUSES *
Device_config::MAX_DEVICES *
Device_config::MAX_FUNCTIONS };
static Genode::Bit_array<MAX_PCI_DEVICES> bdf_in_use;
/**
* Scan PCI buses for a device
*
@ -496,6 +502,18 @@ namespace Pci {
* device and return its capability.
*/
try {
/* if more than one driver uses the device - warn about */
if (bdf_in_use.get(Device_config::MAX_BUSES * bus +
Device_config::MAX_DEVICES * device +
function, 1))
PERR("Device %2x:%2x.%u is used by more than one "
"driver - session '%s'.", bus, device, function,
_label.string());
else
bdf_in_use.set(Device_config::MAX_BUSES * bus +
Device_config::MAX_DEVICES * device +
function, 1);
Device_component * dev = new (_device_slab) Device_component(config, config_space, _ep, this);
_device_list.insert(dev);
return _ep->manage(dev);
@ -513,6 +531,13 @@ namespace Pci {
if (!device)
return;
unsigned const bus = device->config().bus_number();
unsigned const dev = device->config().device_number();
unsigned const func = device->config().function_number();
bdf_in_use.clear(Device_config::MAX_BUSES * bus +
Device_config::MAX_DEVICES * dev + func, 1);
_device_list.remove(device);
_ep->dissolve(device);

@ -58,3 +58,9 @@ bool Pci::bus_valid(int bus)
return buses.valid[bus];
}
using Pci::Session_component;
using Genode::Bit_array;
Bit_array<Session_component::MAX_PCI_DEVICES> Session_component::bdf_in_use;

Loading…
Cancel
Save