Presentation is loading. Please wait.

Presentation is loading. Please wait.

PCI Drivers 491530025 陳俐如 (greener). Bus architecture  The higher-level bus architectures  Consist of programming interface and electrical interface.

Similar presentations


Presentation on theme: "PCI Drivers 491530025 陳俐如 (greener). Bus architecture  The higher-level bus architectures  Consist of programming interface and electrical interface."— Presentation transcript:

1 PCI Drivers 491530025 陳俐如 (greener)

2 Bus architecture  The higher-level bus architectures  Consist of programming interface and electrical interface  PCI  ISA

3 PCI Interface  PCI (Peripheral Component Interconnect)  How a PCI driver can find its hardware and gain access to it  Replace the ISA standard, with three main goals get better performance when transferring data between the cpu and its peripherals platform independent simplify adding and removing peripherals to the system  The PCI bus achieves better performance by using a higher clock rate than ISA  PCI devices are jumperless (unlike most older peripherals) and are automatically configured at boot time without any probing (Cf. device driver)

4 PCI Addressing  Each PCI peripheral is identified by a 16-bits number, or key, including a bus number (8 bits), a device number (5 bits), and a function number (3 bits)  The 16-bit address, or key, is hardware address of PCI  A PCI domain – > 256 buses – > 32 devices – > a multifunction board with a maximum of 8 functions  Device drivers written for Linux use a specific data structure, called pci_dev, to act on the devices.  Bridges, joining two buses  The 16-bit hardware addresses, hidden in the struct pci_dev object, Output of lspci and the layout of information in /proc/pci and /proc/bus/pci

5 PCI Addressing (cont’d)

6  The hardware circuitry of each peripheral board three address spaces memory locations I/O ports configuration registers  Geographical addressing configuration queries address only one slot at a time  Addresses are supposed to be unique to one device, but software may erroneously configure two devices to the same address, making it impossible to access either one unless playing with registers it shouldn ’ t touch  The firmware initializes PCI hardware at system boot, mapping each region to a different address to avoid collisions in configuration registers

7 Boot Time  That ’ s when the devices are configured to accessible by the system – configuration transaction  Firmware BIOS NVRAM PROM  Map the device ’ s memory and I/O ports to the system ’ s address space  Information in /proc/bus/pci/devices or /proc/pci

8 Configuration Registers and Initialization Little-endian

9 Configuration Registers and Initialization (cont’d)  struct pci_device_id { __u32 vendor; __u32 device; __u32 subvendor; __u32 subdevice; __u32 class; __u32 class_mask; kernel_ulong_t driver_data; PCI_DEVICE(vendor, device) PCI_DEVICE_CLASS(device_class, device_class_mask) }

10 MODULE_DEVICE_TABLE  Macro – know what modules works with what devices  /lib/modules/ /mo dules.pcimap  hotplug

11 Registering a PCI Driver  struct pci_driver { const char *name; const struct pci_device_id *id_table; int (*probe) (struct pci_dev *dev, const struct pci_device_id *id); void (*remove) (struct pci_dev *dev); int (*suspend) (struct pci_dev *dev, u32 state); int (*resume) (struct pci_dev *dev); }  static struct pci_driver pci_driver = {.name = "pci_skel",.id_table = ids,.probe = probe,.remove = remove, };  static int __init pci_skel_init(void);  static void __exit pci_skel_exit(void);  int pci_enable_device(struct pci_dev *dev);

12 Accessing the Configuration Space  Devices ’ memory, port, and configuration space (memory and I/O port map)  PCI controller – access configuration space  Defined in int pci_read_config_byte(struct pci_dev *dev, int where, u8 *val); int pci_read_config_word(struct pci_dev *dev, int where, u16 *val); int pci_read_config_dword(struct pci_dev *dev, int where, u32 *val); int pci_write_config_byte(struct pci_dev *dev, int where, u8 val); int pci_write_config_word(struct pci_dev *dev, int where, u16 val); int pci_write_config_dword(struct pci_dev *dev, int where, u32 val);

13 Accessing the I/O and Memory Spaces  6 I/O address regions, being memory or I/O regions  “ prefetchable ” – the cpu can cache the memory region ’ s content  Generic resource management unsigned long pci_resource_start(struct pci_dev *dev, int bar); unsigned long pci_resource_end(struct pci_dev *dev, int bar); unsigned long pci_resource_flags(struct pci_dev *dev, int bar); In  IORESOURCE_IO  IORESOURCE_MEM-- associated I/O region exists  IORESOURCE_PREFETCH  IORESOURCE_READONLY-- prefetchable and/or write protected

14 PCI Interrupts  IRQ in configuration register 60 (PCI_INTERRUPT_LINE)  Configuration register 60 (PCI_INTERRUPT_PIN) If the value = 0, supporting interrupts Tell which single pin is used

15 Hardware Abstractions  C language uses structure containing methods and pointers to simulate OOP  struct pci_ops { int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val); int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size u32 val); };  The actual implementa-tion of pci_read_config_byte(dev, where, val) is dev- >bus->ops->read(bus, devfn, where, 8, val);

16 A Look Back: ISA  Poor performer  Build your own ISA devices easily  Cons ISA is that it ’ s tightly bound to the PC architecture The lack of geographical addressing

17 Hardware Resources  I/O ports  Memory areas  Interrupt lines

18 ISA Programming  Not easy to access to ISA devices  Registers of I/O port and IRQ lines

19 The Plug-and-Play Specification  Relocatable I/O regions  PC BIOS is responsible for the relocation (like PCI)  Geographical addressing supported 64-bits Card Select Number, CSN  PnP detail See drivers/net/3c509.c

20 PC/104 and PC/104+  Pug-and-socket  The electrical and logical layout of the two buses is identical to ISA (PC/104) and PCI (PC/104+)

21 Other PC Buses  MCA (Micro Channel Architecture) ISA < MCA < PCI  EISA (Extended ISA)  VLB (VESA Local Bus) One of extended ISA  SBus Old Sparc Virual address Physical address, connecting to the MMU of CPU  NuBus Old Mac Drivers/nubus/nubus.c (reverse engineering)  External Buses USB, FireWire (IEEE 1394), and IEEE 1284


Download ppt "PCI Drivers 491530025 陳俐如 (greener). Bus architecture  The higher-level bus architectures  Consist of programming interface and electrical interface."

Similar presentations


Ads by Google