25
Linux kernel TLV meetup, 21.09.2015 Kfir Gollan Hardware Probing

Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Embed Size (px)

DESCRIPTION

Have you ever wondered how does the OS know what hardware components are available on a given machine? Basically, someone needs to tell the OS what is available. The process of detecting all the hardware components and pairing them up with the matching drivers in the OS is called hardware probing, or just probing for short.

Citation preview

Page 1: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Linux kernel TLV meetup, 21.09.2015Kfir Gollan

Hardware Probing

Page 2: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

What is hardware probing?Different approaches for detecting hardwareProbing in the linux kernel

Agenda

Page 3: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Have you ever wondered how does the OS know what hardware components are available on a given machine?

Basically, someone needs to tell the OS what is available.

The process of detecting all the hardware components and pairing them up with the matching drivers in the OS is called hardware probing, or just probing for short.

What is hardware probing?

Page 4: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Hardcode the details of the hardware into the kernel

Static configurationDevice trees

Dynamic configurationACPI

Bus based detectionPCI

Different approaches for probing

Page 5: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Device trees

Page 6: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Formal definition:“The Device Tree is a data structure for describing hardware.Rather than hard coding every detail of a device into an operating system, many aspect of the hardware can be described in a data structure that is passed to the operating system at boot time.”

devicetree.org

Device tree – What is it?

Page 7: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Device tree source (DTS)Device tree bindings

Device tree blob (DTB)Flattened Device Tree (FDT)

Device tree compiler (DTC)

Device trees - How do they work?

Page 8: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

{compatible = "nvidia,harmony", "nvidia,tegra20";#address-cells = <1>;#size-cells = <1>;interrupt-parent = <&intc>;

memory {device_type = "memory";reg = <0x00000000 0x40000000>;

};...

};

Device tree example

Page 9: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

{….sound {

compatible = "nvidia,harmony-sound";

i2s-controller = <&i2s1>;i2s-codec = <&wm8903>;

};};

Device tree example

Page 10: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

chosen {bootargs = "console=ttyS0,115200

loglevel=8";initrd-start = <0xc8000000>;initrd-end = <0xc8200000>;

};

Device tree example

Page 11: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Xillybus Device tree tutorialDevice trees for Dummies!Documentation/devicetree/

usage-model.txtbooting-without-of.txt

Device trees – Where to go from here?

Page 12: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

ACPI

Page 13: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Advanced configuration and power interfaceOriginally created by Intel, Toshiba &

MicrosoftCurrently maintained by the UEFI forum

Current last revision of the spec was released at May 2015 (Revision 6.0)

Replaces APM (Advanced Power Management)Allows the kernel/user to control power

features without going into BIOS configurationIt’s complex! (Revision 6.0 is 1056 pages

long)

ACPI

Page 14: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

The fact that it takes more code to parse and interpret ACPI than it does to route traffic on the internet backbones should be a hint something is badly wrong either in ACPI the spec, ACPI the implementation or both.

Alan Cox

ACPI is a complete design disaster in every wayLinus Torvalds

Basically, it is just complex.

Remarks on ACPI

Page 15: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Divided to three major componentsACPI registersACPI BIOSACPI tables

AML – ACPI Machine LanguageRequires a full-fledged interpreter to be

implemented in the kernel.

How it works?

Page 16: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Motherboard devices are described in an hierarchical format called the ACPI namespace.ACPI definition blocksDifferentiated System Description Table

(DSDT)Secondary System Description Table (SSDT)

The operating system is simply required to iterate over the ACPI namespace and load the proper drivers for each device that is listed there.

Configuration and “Plug and Play”

Page 17: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Device (BT){ Name (_HID, "TOS6205") Method (_STA, 0, NotSerialized) { If (BTEN) { Return (0x00) } Else { Return (0x0F) } } ...}

AML example

Page 18: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Device (BT){ … Method (DUSB, 0, NotSerialized) { Store (0x00, \_SB.PCI0.LPC0.EC0.BTDT) } …}

AML example

Page 19: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

ACPI Component Architecture(OS)-independent reference

implementation of the Advanced Configuration and Power Interface Specification (ACPI).

www.acpica.orgDivided into a few major components

OS services layerACPI core subsystemdevice drivers

ACPICA

Page 20: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

A collection of modules that implement the core logic of ACPI.AML interpreter

Execution of the AML bytecodeACPI table management

Validation, parsing, installation and removalResource management

Dependencies between resources IRQ routing tables

Namespace managementProviding simple access to the full ACPI device hierarchy

Many others

ACPICA – ACPI core

Page 21: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Intermediate layer between the ACPI core and the rest of the systemTranslate syscall to a matching ACPI method

Standard set of interfaces that perform OS dependenet functionsMemory allocationHardware accessThreading and synchronization

Needs to be implemented by each operating system that wishes to use ACPICA.

ACPICA – OS service layer

Page 22: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Probing in the linux kernel

Page 23: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Platform devices Platform devices are devices that typically

appear as autonomous entities in the system.No bus initialization and management requiredDirectly probe the hardware –

implementing .probe functionstruct platform_driver{

int (*probe)(struct platform_device *);int (*remove)(struct platform_device *);

...;}

Probing in the linux kernel

Page 24: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

PCI devicesDrivers are registered to the PCI subsystem of

the kernel.When a device is detected the matching drivers

probe function is invoked.struct pci_driver{

... int (*probe) (struct pci_dev *dev, ..); void (*remove) (struct pci_dev *dev);

...;}

Probing in the linux kernel

Page 25: Linux kernel TLV meetup, 21.09.2015 Kfir Gollan. What is hardware probing? Different approaches for detecting hardware Probing in the linux kernel

Questions?