pcibus.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 132 行
JAVA
132 行
/*
* $Id: PCIBus.java,v 1.2 2003/12/21 07:50:12 epr Exp $
*/
package org.jnode.driver.pci;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger;
import org.jnode.driver.Bus;
/**
* @author epr
*/
public class PCIBus extends Bus implements PCIConstants {
/** My logger */
private final Logger log = Logger.getLogger(getClass());
/** The PCI system */
private final PCIDriver pci;
/** My numeric index */
private final int bus;
/** All devices connected to this bus */
private final ArrayList list = new ArrayList();
/**
* Initialize a root bus (bus 0)
* @param pci
*/
public PCIBus(Bus parent, PCIDriver pci) {
super(parent);
this.pci = pci;
this.bus = 0;
}
public PCIBus(PCIBus parent, int bus) {
super(parent);
this.pci = parent.pci;
this.bus = bus;
}
/**
* Gets the numeric index of this bus.
*/
public final int getBus() {
return bus;
}
/**
* Probe for all devices connected to the this bus.
* @param result
*/
protected void probeDevices(List result) {
log.debug("Probing PCI bus " + bus);
list.clear();
for (int i = 0; i < 32; i++) {
PCIDevice dev = createDevice(i, 0);
if (dev != null) {
list.add(dev);
if (dev.getConfig().isMultiFunctional()) {
for (int f = 1; f < 8; f++) {
dev = createDevice(i, f);
if (dev != null) {
list.add(dev);
}
}
}
}
}
// Add every found device to the result list
result.addAll(list);
// Now probe all bridges
for (Iterator i = list.iterator(); i.hasNext(); ) {
final PCIDevice dev = (PCIDevice)i.next();
final PCIDeviceConfig cfg = dev.getConfig();
if ((cfg.getBaseClass() == CLASS_BRIDGE) && (cfg.getSubClass() == SUBCLASS_BR_PCI)) {
log.debug("Found PCI-PCI bridge " + dev.getPCIName());
//int mybus = dev.getBus();
//int primBus = cfg.getBridgePrimaryBus();
//int secBus = cfg.getBridgeSecondaryBus();
final PCIBus newBus = new PCIBus(this, cfg.getBridgeSecondaryBus());
newBus.probeDevices(result);
}
}
}
/**
* Create a PCIDevice instance based on (1) the presence of the device
* and (2) the class of the device.
* @param unit
* @param func
* @return A new PCIDevice for the given bus, unit and function or
* <code>null</code> if no device is present at the given bus, unit and function.
*/
private final PCIDevice createDevice(int unit, int func) {
if (PCIDeviceConfig.isPresent(pci, bus, unit, func)) {
//final int[] pciClass = PCIDeviceConfig.getPCIClass(this, bus, unit, func);
//final int major = pciClass[0];
//final int sub = pciClass[1];
// No specific device class, so just create the default
return new PCIDevice(this, unit, func);
} else {
return null;
}
}
/**
* Return the list of PCI devices connected to this bus.
* @return A List containing all connected devices as instanceof PCIDevice.
*/
public List getDevices() {
return list;
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
return "PCIBus: " + bus;
}
/**
* @return
*/
final PCIDriver getPCI() {
return this.pci;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?