From b1b2817a689464e35c799274c4ceedcfed37e475 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Sat, 24 Jun 2017 10:24:36 +0100 Subject: [PATCH] pci.sh /proc/interrupts and lspci -k, pci.c dev_info --- kernel_module/pci.c | 9 +++++++-- rootfs_overlay/pci.sh | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/kernel_module/pci.c b/kernel_module/pci.c index 055ac75..298a110 100644 --- a/kernel_module/pci.c +++ b/kernel_module/pci.c @@ -1,4 +1,8 @@ /* +Usage: + + /pci.sh + Like every other hardware, we could interact with PCI on x86 using only IO instructions and memory operations. @@ -140,7 +144,7 @@ static irqreturn_t irq_handler(int irq, void *dev) devi = *(int *)dev; if (devi == major) { irq_status = ioread32(mmio + IO_IRQ_STATUS); - pr_info("interrupt irq = %d dev = %d irq_status = %llx\n", + pr_info("irq_handler irq = %d dev = %d irq_status = %llx\n", irq, devi, (unsigned long long)irq_status); /* Must do this ACK, or else the interrupts just keeps firing. */ iowrite32(irq_status, mmio + IO_IRQ_ACK); @@ -162,7 +166,8 @@ static int pci_probe(struct pci_dev *dev, const struct pci_device_id *id) { u8 val; - pr_info("pci_probe\n"); + /* https://stackoverflow.com/questions/31382803/how-does-dev-family-functions-are-useful-while-debugging-kernel/44734857#44734857 */ + dev_info(&(dev->dev), "pci_probe\n"); major = register_chrdev(0, CDEV_NAME, &fops); pdev = dev; if (pci_enable_device(dev) < 0) { diff --git a/rootfs_overlay/pci.sh b/rootfs_overlay/pci.sh index 364593f..d56d6d1 100755 --- a/rootfs_overlay/pci.sh +++ b/rootfs_overlay/pci.sh @@ -2,10 +2,21 @@ set -ex +# Our modules does not the PCI device yet. +lspci -k +# => 00:04.0 Class 00ff: 1234:11e8 lkmc_pci + +# Interrupt counts before we generate our interrupts. +cat /proc/interrupts + # Setup. insmod /pci.ko /mknoddev.sh pci +# Shows that this module owns the PCI device. +lspci -k +# => 00:04.0 Class 00ff: 1234:11e8 lkmc_pci + # Identifiction: just returns some fixed magic bytes. dd bs=4 status=none if=/dev/lkmc_pci count=1 skip=0 | od -An -t x1 # => 010000ed @@ -39,3 +50,8 @@ sleep 1 # Teardown. rm /dev/lkmc_pci rmmod pci + +# Interrupt counts after we generate our interrupts. +# Compare with before. +cat /proc/interrupts +