parent
e4d663cf41
commit
8743575dcf
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* \brief Non PCI devices, e.g. PS2
|
||||
* \author Alexander Boettcher
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#include <irq_session/connection.h>
|
||||
#include "pci_session_component.h"
|
||||
|
||||
|
||||
namespace Nonpci { class Ps2; }
|
||||
|
||||
class Nonpci::Ps2 : public Pci::Device_component
|
||||
{
|
||||
private:
|
||||
|
||||
enum {
|
||||
IRQ_KEYBOARD = 1,
|
||||
IRQ_MOUSE = 12,
|
||||
};
|
||||
|
||||
Genode::Irq_connection _irq_mouse;
|
||||
|
||||
public:
|
||||
|
||||
Ps2(Genode::Rpc_entrypoint * ep, Pci::Session_component * session)
|
||||
:
|
||||
Pci::Device_component(ep, IRQ_KEYBOARD),
|
||||
_irq_mouse(IRQ_MOUSE)
|
||||
{ }
|
||||
|
||||
Genode::Irq_session_capability irq(Genode::uint8_t virt_irq) override
|
||||
{
|
||||
switch (virt_irq) {
|
||||
case 0:
|
||||
return Device_component::irq(virt_irq);
|
||||
case 1:
|
||||
return _irq_mouse.cap();
|
||||
default:
|
||||
return Genode::Irq_session_capability();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* PCI session component devices which are non PCI devices, e.g. PS2
|
||||
*/
|
||||
Pci::Device_capability Pci::Session_component::device(String const &name) {
|
||||
|
||||
if (!name.is_valid_string())
|
||||
return Device_capability();
|
||||
|
||||
using namespace Genode;
|
||||
|
||||
char const * device_name = name.string();
|
||||
const char * devices [] = { "PS2" };
|
||||
unsigned devices_i = 0;
|
||||
|
||||
for (; devices_i < sizeof(devices) / sizeof(devices[0]); devices_i++)
|
||||
if (!strcmp(device_name, devices[devices_i]))
|
||||
break;
|
||||
|
||||
if (devices_i >= sizeof(devices) / sizeof(devices[0])) {
|
||||
PERR("unknown '%s' device name", device_name);
|
||||
return Device_capability();
|
||||
}
|
||||
|
||||
try {
|
||||
Device_component * dev = nullptr;
|
||||
|
||||
switch(devices_i) {
|
||||
case 0:
|
||||
dev = new (_md_alloc) Nonpci::Ps2(_ep, this);
|
||||
break;
|
||||
default:
|
||||
return Device_capability();
|
||||
}
|
||||
|
||||
_device_list.insert(dev);
|
||||
return _ep->manage(dev);
|
||||
} catch (Genode::Allocator::Out_of_memory) {
|
||||
throw Pci::Device::Quota_exceeded();
|
||||
} catch (Genode::Parent::Service_denied) {
|
||||
return Device_capability();
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* \brief PCI-session component
|
||||
* \author Norman Feske
|
||||
* \date 2008-01-28
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2008-2015 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#include "pci_session_component.h"
|
||||
|
||||
/**
|
||||
* Check if given PCI bus was found on initial scan
|
||||
*
|
||||
* This tremendously speeds up further scans by other drivers.
|
||||
*/
|
||||
bool Pci::bus_valid(int bus)
|
||||
{
|
||||
struct Valid_buses
|
||||
{
|
||||
bool valid[Device_config::MAX_BUSES];
|
||||
|
||||
void scan_bus(Config_access &config_access, int bus = 0)
|
||||
{
|
||||
for (int dev = 0; dev < Device_config::MAX_DEVICES; ++dev) {
|
||||
for (int fun = 0; fun < Device_config::MAX_FUNCTIONS; ++fun) {
|
||||
|
||||
/* read config space */
|
||||
Device_config config(bus, dev, fun, &config_access);
|
||||
|
||||
if (!config.valid())
|
||||
continue;
|
||||
|
||||
/*
|
||||
* There is at least one device on the current bus, so
|
||||
* we mark it as valid.
|
||||
*/
|
||||
valid[bus] = true;
|
||||
|
||||
/* scan behind bridge */
|
||||
if (config.is_pci_bridge()) {
|
||||
int sub_bus = config.read(&config_access,
|
||||
0x19, Device::ACCESS_8BIT);
|
||||
scan_bus(config_access, sub_bus);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Valid_buses() { Config_access c; scan_bus(c); }
|
||||
};
|
||||
|
||||
static Valid_buses buses;
|
||||
|
||||
return buses.valid[bus];
|
||||
}
|
Loading…
Reference in new issue