Linux PCI pci_dev 생 성

3627 단어 linux
Linux 에서 PCI 구동 구 조 는 Linux BUS, DEVICE, DRIVER 구조 이다.아래 의 모든 코드 는 linux 3.13 에서 나온다.
struct pci_dev 는 device 의 데이터 구 조 를 설명 합 니 다.
struct pci_driver 는 driver 의 데이터 구 조 를 설명 합 니 다.
struct pci_bus 는 bus 의 데이터 구 조 를 묘사 합 니 다.
device 와 driver 는 모두 bus 에 걸 려 있 습 니 다.
PCI 의 driver 와 device 가 일치 하 는 인증 을 하려 면 vendor, id, class 정 보 를 검증 합 니 다.
static inline const struct pci_device_id * pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
{
	if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) &&
	    (id->device == PCI_ANY_ID || id->device == dev->device) &&
	    (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
	    (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) &&
	    !((id->class ^ dev->class) & id->class_mask))
		return id;
	return NULL;
}

이 함 수 는 pci device 와 driver 가 일치 하 는 최 하층 함수 입 니 다.비 교 된 것 은 vendor, id, class 정 보 를 볼 수 있 습 니 다.호출 경 로 는:
pci_bus_match()->pci_match_device()->pci_match_one_device()
많은 사람들 이 Pci driver 를 어떻게 써 야 하 는 지 소개 했다.pci device 가 언제 만 들 어 졌 는 지 무시 합 니 다.
Pci driver 가 시스템 에 등록 되면 시스템 은 Pci driver 와 Pci device 와 일치 합 니 다.하지만 이 때 는 Pci device 가 만 들 어 졌 기 때문에 match 할 수 있 습 니 다.그럼 pci device 는 언제 만 들 었 나 요?
정 답 은 시스템 초기 화 때.
시스템 초기 화 시 Pci 버스 를 스 캔 하여 위 에 연 결 된 모든 장 치 를 발견 하고 모든 사회 보장 에 struct Pci 를 만 듭 니 다.dev 대상.
pci bus 뿌리 부터 스 캔 합 니 다.
pciscan_slot()
struct pci_bus *pci_scan_root_bus(struct device *parent, int bus,
		struct pci_ops *ops, void *sysdata, struct list_head *resources)
{
	struct pci_host_bridge_window *window;
	bool found = false;
	struct pci_bus *b;
	int max;

	list_for_each_entry(window, resources, list)
		if (window->res->flags & IORESOURCE_BUS) {
			found = true;
			break;
		}

	b = pci_create_root_bus(parent, bus, ops, sysdata, resources); //   pci bus
	if (!b)
		return NULL;

	if (!found) {
		dev_info(&b->dev,
		 "No busn resource found for root bus, will use [bus %02x-ff]
", bus); pci_bus_insert_busn_res(b, bus, 255); } max = pci_scan_child_bus(b); // pci bus, pci if (!found) pci_bus_update_busn_res_end(b, max); pci_bus_add_devices(b); return b; }
unsigned int pci_scan_child_bus(struct pci_bus *bus)
{
	unsigned int devfn, pass, max = bus->busn_res.start;
	struct pci_dev *dev;

	dev_dbg(&bus->dev, "scanning bus
"); /* Go find them, Rover! */ for (devfn = 0; devfn < 0x100; devfn += 8) pci_scan_slot(bus, devfn); // slot . . . return max; }
int pci_scan_slot(struct pci_bus *bus, int devfn)
{
	unsigned fn, nr = 0;
	struct pci_dev *dev;

	if (only_one_child(bus) && (devfn > 0))
		return 0; /* Already scanned the entire slot */

	dev = pci_scan_single_device(bus, devfn);//    ,     
	if (!dev)
		return 0;
	if (!dev->is_added)
		nr++;

	.
        .
        .
	return nr;
}

계속 보기 pciscan_device()
4. 567913. 자, 기본 적 인 절 차 는 바로 이렇다.물론 스 캔 은 pci 다리 가 있 으 면 한 층 더 올 라 가기 때문이다.
핫 플러그 장치 도 있 습 니 다. 꽂 으 면 device 가 생 성 됩 니 다.
struct pci 보고dev 의 생 성 은 Pci 구동 의 구 조 를 더욱 완전 하 게 이해 할 수 있 습 니 다.
On kernel 4.3, the following list shows the sequence of the PCI bus create and scan.
  ,

The first PCI scan starts from ACPI.
If ACPI is disabled, then it starts from pci_legacy_init().

좋은 웹페이지 즐겨찾기