chipset programming on embedded ia (tunnel creek version) shi, steven 2011, july

139
Chipset Programming on Embedded I (Tunnel Creek version Shi, Steven 2011, July

Upload: alexina-henry

Post on 23-Dec-2015

221 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Chipset Programming on Embedded IA(Tunnel Creek version)

Shi, Steven2011, July

Page 2: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Legal Information

INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION WITH INTEL® PRODUCTS. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. EXCEPT AS PROVIDED IN INTEL’S TERMS AND CONDITIONS OF SALE FOR SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER, AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL® PRODUCTS INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. INTEL PRODUCTS ARE NOT INTENDED FOR USE IN MEDICAL, LIFE SAVING, OR LIFE SUSTAINING APPLICATIONS.

Intel may make changes to specifications and product descriptions at any time, without notice.

All products, dates, and figures specified are preliminary based on current expectations, and are subject to change without notice.

Intel, processors, chipsets, and desktop boards may contain design defects or errors known as errata, which may cause the product to deviate from published specifications. Current characterized errata are available on request.

Intel and the Intel logo are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

*Other names and brands may be claimed as the property of others.

Copyright © 2011 Intel Corporation.

Page 3: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

ObjectivesAt the end of this session, you will be able to:

Know the IA platform architecture trend SOC Review the methodology of general IA

programming Know some industry IO standards and

programming interfaces exposed on Intel Tunnel Creek

Know some key IO technologies for future Embedded/SOC chipset enabling

Get some practical Lab samples for college course

Page 4: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Agenda

The IA platform architecture trend Chipset architecture and Programming methodology review

(Multi-layers to enable devices) Usb Flash Disk (Lab) LPC (Lab)

New devices programming interface intro PCI/PCIE (Lab) Usb3.0 (Lab) SDIO (Lab) ACPI - CPU C/P states (Lab) I2C , SPI and CAN

Other embedded platform Some potential future topics

Page 5: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

IA platform architecture trend

Page 6: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

IA platform Architecture - Previous

CPU-North-South

Processor

FSBAnalogDisplayVGA

AGP orPCI Exp.Graphics

Card

SystemMemory

(G)MCH

ICH

DMI/Hub Interface

IDE (& SATA))

USB

GPIO

Power Management

Clock Generation

LAN

System Management

SMBus/I2C

Other ASIC(Optional)

Super IO

BIOS Support/ Firmware Hub

Low Pin Count (LPC) Interfaces

Key Board

Mouse

PCI Bus

G_Ethernet

PCI Exp.

AC’97 Codecs

Page 7: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

IA platform Architecture - Menlow

CPU-SCH

Processor

FSBAnalogDisplayVGA

AGP orPCI Exp.Graphics

Card

SystemMemory

IDE (& SATA))

USB

GPIO

Power Management

Clock Generation

LAN

System Management

SMBus/I2C

Other ASIC(Optional)

Super IO

BIOS Support/ Firmware Hub

Low Pin Count (LPC) Interfaces

Key Board

Mouse

PCI Bus

G_Ethernet

PCI Exp.

AC’97 Codecs

SCH

Page 8: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

IA platform Architecture - PineTrail

8

Legal text goes here in Verdana regular 7pt.BIOS Support

/ Firmware Hub

CPU-SCH

Page 9: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

IA platform Architecture – TunnelCreek

Page 10: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

IA platform Architecture – TunnelCreek

Page 11: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

IA platform Architecture – TunnelCreek

Page 12: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Platform Controller

Hub EG20T

Page 13: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

IA platform Architecture - Summary

SOC is coming

Page 14: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Exercise and questions(实验习题与思考 )

1.Will PC be SOC system? 2.How many major chip there will be in IA client system

(Embedded, Tablet, Netbook, Notebook, Desktop, Workstation)?

3.What will future PC looks like?4.Why future is SOC?5.What will become easier and hardier for development?

Page 15: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Programming methodology review

Page 16: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

IA Programming methodology Review

IA device programming methodology is stable , despite of the platform Architecture change

“…each new kernel release sees about 70,000 new lines of ARM code, whereas there's roughly 5,000 lines of new x86 code added”

Page 17: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

TunnelCreek Architecture

Different device types: OS virtual device

Not real hardware ACPI device

real hardware, not connected through PCI bus

PCI connected Device real hardware connected through PCI bus

PCI/PCIE programming interface device or leverage PCI/PCIE programming to control itself

Page 18: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Our Target devices: PCI connected Device

Standard and usually cross platform

Device has hierarchical connection relationship

TunnelCreek Architecture

Page 19: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Programming methodology

Chipset Programming methodology Identify device hierarchical relationship on the PCIE

bus Get the target device location

Program with orders/levels Get to know the init sequence and precondition Lower level device dependence on higher level

Traverse to all leaves

Chipset Programming Pattern Detect target device Get or enable higher level assigned resource Specific Interface Initialization and publish Interrupt/Polling Service Exception/Error Handling

Page 20: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Case Study

How could I enable my USB2.0 Flash disk?How could I enable the serial COM/UART

port?

Page 21: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Check the hierarchical location for below devices: How could I enable my

USB2.0 Flash disk? How could I enable the

serial COM/UART port?

Case Study

Page 22: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Programming methodology – Question’s answer

Enable the devices layer by layer:

EHCI

Super I/O

OHCI

PCI Bus

LPC

Usb Mouse

Usb Flash Disk

Layer1 :Init PCI Bus

Layer2:Init PCI/PCIE host device

Layer3:Init specific child device

COM

Page 23: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer1: Init PCI Bus – Bios roleLayer2: Init PCI/PCIE host device - Bios and

OS roleLayer3: Init specific child device - Bios and

OS role

Case Study

Page 24: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer1: Init PCI Bus – What need to do

Init or Enumerate PCI Bus:1.Search all PCI device.2.Assign PCI unique address (Bus number,

for plug in device under bridge)3.Assign device required system resource

PCI Bus

Step1:Init PCI Bus

PciRootBridge

Page 25: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer1: Init PCI Bus – How to do it in Bios

Go through whole PCI bus twice:First time: Detect the bridge, to assign the Bus number.

- ensure the PCI configuration transaction can go through related device.- Deep first, recursively

Second time: Detect system resource and assign the device system resource.- Bios Pci Bus driver will calculate whole required system resource firstly, then assign them to different PCI devices.- Bios Pci Bus also report whole required system resource to OS through ACPI table.

Page 26: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer1: Init PCI Bus – How to do it in Bios

After Layer1 PciBus init, all PCI device is enumerated and found out but we don’t know what specific PCI device

they are.

PciIO

PciIO

ICH8PCI Bus

PciIO

PciRootBridge

Layer1 :Init PCI Bus

Page 27: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer1 Lab : Init PCI Bus

Disconnect –rConnect Pcibusdriver HandleDH –p Pciio

Page 28: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Init Host controller

Which device is EHCI host controller?Which device is LPC host controller?

PciIO

PciIO

ICH8PCI Bus

PciIO

PciRootBridge

Layer1 :Init PCI Bus

Page 29: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Detect Host controller

EHCI : check the class code and program interface

of PCI configuration space

LPC: check the Base Class and Sub Class Code of

PCI configuration space

Page 30: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: USB Lab – Enable Host controller

Disconnect –rConnect Pcibusdriver HandleDh –p usbhc2Connect Ehcidriver HandleDh –p usbhc2

Page 31: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Init Usb host device

After Layer2 Usb host controller init, the Usb host controller is init but we don’t whether there is USB device on

those USB bus.

EHCIICH8PCI Bus

PciIO

PciIO

Layer2:Init PCI/PCIE host device

PciRootBridge

Usb_HC

Layer1 :Init PCI Bus

Page 32: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2 : USB Lab – Enable USB Bus

Disconnect –rConnect Pcibusdriver HandleConnect Ehcidriver HandleConnect UsbBusDriver Handle

Page 33: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Init USB Bus

After Layer2 USB bus init, all USB device is enumerated and found out but we don’t know what specific Usb device

they are.

EHCIICH8PCI Bus

PciIO

PciIO

UsbIO

Layer1 :Init PCI Bus

Layer2:Init PCI/PCIE host device

PciRootBridgeUsb_HC

Usb_HC

Page 34: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Programming Pattern

Detect target Pci/Pcie device - EHC Status = PciIo->Pci.Read ( PciIo, EfiPciIoWidthUint8, EHC_PCI_CLASSC, sizeof (USB_CLASSC) / sizeof (UINT8), &UsbClassCReg );

if (EFI_ERROR (Status)) { Status = EFI_UNSUPPORTED; goto ON_EXIT; } // // Test whether the controller belongs to Ehci type // if ((UsbClassCReg.BaseCode != PCI_CLASS_SERIAL) || (UsbClassCReg.SubClassCode != PCI_CLASS_SERIAL_USB) || (UsbClassCReg.PI != EHC_PCI_CLASSC_PI)) {

Status = EFI_UNSUPPORTED; }

Page 35: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Programming Pattern

Get or enable higher level assigned resource - EHC

// // Open the PciIo Protocol, then enable the USB host controller // Status = gBS->OpenProtocol ( Controller, &gEfiPciIoProtocolGuid, &PciIo, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_BY_DRIVER );

Status = PciIo->Attributes ( PciIo, EfiPciIoAttributeOperationEnable, EFI_PCI_DEVICE_ENABLE, NULL );

Page 36: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Programming Pattern

Specific Interface Initialization and publish - EHC

// // Create then install USB2_HC_PROTOCOL // Ehc = EhcCreateUsb2Hc (PciIo);

Status = gBS->InstallProtocolInterface ( &Controller, &gEfiUsb2HcProtocolGuid, EFI_NATIVE_INTERFACE, &Ehc->Usb2Hc );

Page 37: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Programming Pattern

Interrupt/Polling Service - EHC// // Start the asynchronous interrupt monitor // Status = gBS->SetTimer (Ehc->PollTimer, TimerPeriodic, EHC_ASYNC_POLL_INTERVAL);

Page 38: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Programming Pattern

Exception/Error Handling - EHC

if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; }

if (Ehc == NULL) { EHC_ERROR (("EhcDriverBindingStart: failed to create

USB2_HC\n"));

Status = EFI_OUT_OF_RESOURCES; goto CLOSE_PCIIO; }

if (EFI_ERROR (Status)) { EHC_ERROR (("EhcDriverBindingStart: failed to start async

interrupt monitor\n")); EhcHaltHC (Ehc, EHC_GENERIC_TIMEOUT); goto UNINSTALL_USBHC; }

UNINSTALL_USBHC: gBS->UninstallProtocolInterface ( Controller, &gEfiUsb2HcProtocolGuid, &Ehc->Usb2Hc );

FREE_POOL: EhcFreeSched (Ehc); gBS->CloseEvent (Ehc->PollTimer); gBS->FreePool (Ehc);

CLOSE_PCIIO: gBS->CloseProtocol ( Controller, &gEfiPciIoProtocolGuid, This->DriverBindingHandle, Controller );

return Status;

Page 39: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer3: Init specific child device

Which USB device is Usb Flash disk?Where is COM/UART port and how to

access it?

EHCI

OHCI

ICH8PCI Bus

PCIIO

UsbIO

UsbIO

Layer1 :Init PCI Bus

Layer2:Init PCI/PCIE host device

PciRootBridgeUsb_HC

Usb_HC

Page 40: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer3: USB device drivers

Usb Bus driver

Host controller driver

Usb Device driver

EHCI

PCI Bus

OHCI

Page 41: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer3: USB Lab – Start USB device

Disconnect –rConnect

Pcibusdriver Handle

Connect Ehci driver handle

Dh –p usbioConnect USBBus

driver handleDh –p usbio

Dh –p blkioConnect Usb Mass storage driver HandleDh –p blkio

Page 42: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer3: Programming Pattern

Detect target device – Usb Flash Disk// // Get the interface to check the USB class and find a transport // protocol handler. // Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface); if (EFI_ERROR (Status)) { goto ON_EXIT; }

Status = EFI_UNSUPPORTED;

if (Interface.InterfaceClass != USB_MASS_STORE_CLASS) { goto ON_EXIT; }

Page 43: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer3: Programming Pattern

Get higher level assigned resource – Usb Flash Disk

Status = gBS->OpenProtocol ( Controller, &gEfiUsbIoProtocolGuid, &UsbIo, This->DriverBindingHandle, Controller, EFI_OPEN_PROTOCOL_BY_DRIVER );

Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &Interface); if (EFI_ERROR (Status)) { DEBUG ((mUsbMscError, "UsbMassInitTransport: UsbIo->UsbGetInterfaceDescriptor (%r)\n",

Status)); goto ON_EXIT; }

Page 44: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer3: Programming Pattern

Specific Interface Initialization and publish – Usb Flash Disk

UsbMass->Signature = USB_MASS_SIGNATURE; UsbMass->UsbIo = UsbIo; UsbMass->BlockIo.Media = &UsbMass->BlockIoMedia; UsbMass->BlockIo.Reset = UsbMassReset; UsbMass->BlockIo.ReadBlocks = UsbMassReadBlocks; UsbMass->BlockIo.WriteBlocks = UsbMassWriteBlocks; UsbMass->BlockIo.FlushBlocks = UsbMassFlushBlocks; UsbMass->OpticalStorage = FALSE; UsbMass->Transport = Transport; UsbMass->Context = Context; UsbMass->Lun = Index; // // Create a UsbMass handle for each lun, and install blockio and devicepath protocols. // Status = gBS->InstallMultipleProtocolInterfaces ( &UsbMass->Controller, &gEfiDevicePathProtocolGuid, UsbMass->DevicePath, &gEfiBlockIoProtocolGuid, &UsbMass->BlockIo, NULL );

Page 45: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer3: Programming Pattern

Exception/Error Handling – Usb Flash DiskON_ERROR: if (UsbMass->DevicePath != NULL) { gBS->FreePool (UsbMass->DevicePath); } if (UsbMass != NULL) { gBS->FreePool (UsbMass); } if (UsbIo != NULL) { gBS->CloseProtocol ( Controller, &gEfiUsbIoProtocolGuid, This->DriverBindingHandle, UsbMass->Controller );

}

Page 46: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Init LPC/SuperIO

Page 47: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Init Host controller

Which device is LPC host controller?

PciIO

PciIO

ICH8PCI Bus

PciIO

PciRootBridge

Layer1 :Init PCI Bus

Page 48: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: LPC/SuperIO - W83627DHG-PStep 1: Enumerate

PCI bus to get the LPC bridge PCI device

Step 2: Enables decoding on the LPC for the super I/O (skipped in SCH, always enabled by HW)

Step 3: Configure the SuperIo internal component according to platform policy

Step 4: Now, we can use the UART through IO 0x03F8-0x03FF register block

Page 49: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Init LPC/SuperIO After Layer2 LPC init, all ISA device can be accessed directlyLPC device is hardcode IO device, no need to enumerate, so no Bus driver

EHCIICH8PCI Bus

LPC

Layer1 :Init PCI Bus

Layer2:Init PCI/PCIE host device

PciRootBridgeUsb_HC

Usb_HC

PciIO

Super I/O COM

Page 50: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer2: Programming Pattern

Detect target Pci/Pcie device - LPC// // Check whether the Pci device is the wanted LPC controller // Status = PciIo->Pci.Read ( PciIo, EfiPciIoWidthUint32, 0, sizeof (Pci) / sizeof (UINT32), &Pci ); if (!EFI_ERROR (Status)) { // // See if this is a standard PCI to ISA Bridge from the Base Code // and Class Code // if (Pci.Hdr.ClassCode[2] == PCI_CLASS_BRIDGE) { //Sub Class Code if (Pci.Hdr.ClassCode[1] == PCI_CLASS_ISA) { //Base Class Code Found = TRUE; break; } } }

Page 51: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Layer3: Lab Demonstration - UART

A simple driver to show how to enable the LPC UART part, and use the UART to output “hello word!”.

Page 52: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Programming methodology

Chipset Programming methodology Identify device hierarchical relationship on the PCIE

bus Get the target device location

Program with orders/levels Get to know the init sequence and precondition Lower level device dependence on higher level

Traverse to all leaves

Chipset Programming Pattern Detect target device Get or enable higher level assigned resource Specific Interface Initialization and publish Interrupt/Polling Service Exception/Error Handling

Page 53: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

PCI/PCIE Device system resource Lab

实验目的 Know the basic concepts of PCI/PCIE device Know PCI/PCIE device programming interface Know how to get assigned resource of PCIE device

实验器材 Atom Lab platform Windows XP

实验预习要求 Review the IA platform Programming methodology

实验内容Manually programming PCIE/PCI configuration space to get the required system resourceManually read the PCIE/PCI configuration space to know the assigned system resource

Page 54: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

PCI/PCIE Device Programming basic concept

PCI Express elements emulate PCI configuration environmentPCI Express elements emulate PCI configuration environment

PCI-XDevice

PCI-X Device

CPU

Host BridgeAGPGFX

PCIBridge

PCI

PCI-XBridge

PCIBridge

PCI-XBridge

PCI-XDevice

PCI-X Device

Memory

PCI System

Endpoint

LegacyEnd

point

Switch Switch

Switch

CPU

Root ComplexPCI Express

GFX

PCIBridge

PCI

LegacyEnd

point

Endpoint

Memory

PCI Express System

Page 55: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

PCI/PCIE “3D” Address SpaceA PCI target can implement up to three different types

of address space Configuration Space

Stores basic information about the device Allows the central resource or O/S to program a device with optional

setting I/O Space

PCI device consumed system resource, permit device to map its internal registers to those IO address.

limited, used mainly with legacy peripherals, like Usb1.1 uhci, LPC/ ISA

Memory Space PCI device consumed system resource, permit device to map its

internal registers to those volatile memory address. Used for just about everything else, modern PCI device, like Usb2.0

ehci

Page 56: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

PCI/PCIE Configuration Space

PCI ExpressExtended

ConfigurationSpace

(Not availableon legacy OS)

Extended configuration space for PCI Express parameters capabilities

(First extended capability begins at

offset 100h)

0x1000

PCI ConfigurationSpace

(Availableon legacy OS

through CF8/CFC)

PCI Express Capability Structure

0

0x100

PCI 2.x Compatible Configuration Header

0x40

Page 57: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

PCI/PCIE Configuration Space

PCI ExpressExtended

ConfigurationSpace

(Not availableon legacy OS)

0x1000

PCI ConfigurationSpace

(Availableon legacy OS

through CF8/CFC)

0

0x100

0x40

Page 58: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

PCI/PCIE IO Space

This space is where legacy peripherals (Keyboard, serial port, etc) are mapped.

The PCI spec allows an agent to request 4 bytes to 2GB of I/O space. But x86 processor only supports an 64K I/O port.

Modern PCI/PCIE device don’t prefer to consume the IO space any longer.

Page 59: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

PCI/PCIE Memory Space

This space is used by most everything else – it’s the general purpose address space The PCI spec recommends that a device use

memory space, even if it is a peripheral.

An agent can request between 16 bytes and 2 GB of memory space The PCI Spec recommends that an agent use

at least 4K of memory space, to reduce the width of the agent’s address decoder.

Page 60: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

System Resource Consumed

• Memory• IO• DMA (for legacy device only)• IRQ

Page 61: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

PCIE & Chipset Programming methodology

Lab steps (实验步骤 )1. Find the target PCIE/PCI device through

DeviceID/VenderID2. Stop the PCIE/PCI device3. Preserve the original value4. Write the Bars with allone5. Read the Bars response values6. Write back the original value

Page 62: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

PCIE & Chipset Programming methodology

Lab steps (实验步骤 )1. Find the target

PCIE/PCI device through DeviceID/VenderID

Page 63: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

PCIE & Chipset Programming methodology

Lab steps (实验步骤 )2. Stop the PCIE/PCI device

Page 64: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

PCIE & Chipset Programming methodology

Lab steps (实验步骤 )4. Write the Bars with allone5. Read the Bars response values

Page 65: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

PCIE Programming methodology

Exercise and questions(实验习题与思考 )1.How a PCIE device expose its programming

interface(PI)? 2.What’s the same and different between System

Memory Address, MMIO and IO? 3.Since the IO address is old, why we still maintain it?4.How to know how many resource a PCIE device need

through its PI?5.Please summary what type system resource the below

devices need? Ehci, SATA, SMBus6.Please change the assigned resource to difference

range in BIOS or OS, and let it still work fine.

Page 66: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Usb3.0

Page 67: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Usb3.0 cable assembly

Page 68: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Usb3.0 cable assembly

Page 69: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Usb3.0 cable assembly

Page 70: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

70

Physical Layer OverviewDefines the signaling technology for the SuperSpeed

bus. The physical layer function is to encode 8-bit data from the link layer

into 10-bit symbols and exchange the symbols between devices reliably.

The physical layer consists of a transmitter, a receiver, and the necessary clock sources for the transmitter and the receiver.

The channel can be FR4 stripline, microstrip, a cable, or a combination of these components.

Tx

Rx

Host Host Channel

Cable Conn

Tx

Rx

DeviceDevice Channel

Ref Clk A Ref Clk B

pinspads pads

Conn

Typical Channel topologyHost silicon Tx/Rx Device silicon Tx/Rx

Page 71: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Differences From High-SpeedHigh-Speed

480 MT/s No-SSC 2 wires for signaling

Tx and Rx use same wire

1 bi-directional link DC coupled bus NRZ encoding

SuperSpeed 5.0 GT/s SSC is required 4 wires for signaling

2 for Tx and 2 for Rx Each Uni-directional

AC coupled bus 8b10b encoded

Device BHOST

+

-

+

-

+-

+-

Tx

Rx

Rx

Tx

Tx

Rx

+-

+

-

+-

+

- Tx

Page 72: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Usb3.0 Bus Architecture

Page 73: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Usb3.0 Packet Flow

 Screen clipping taken: 2011/7/25, 10:10  

Page 74: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Usb3.0 Hub Architecture

Page 75: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Usb3.0 vs. Thunderbolt

Page 76: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

USB overview

• Host, hub and device build up the topology map, one HC one Bus UHC/OHC: Usb1.1 EHC: Usb2.0 XHC: Usb3.0

• 4 transfer speeds: low (1.1), full(1.1), high(2.0), super high(3.0)

• 4 transfer types: control, bulk, interrupt, isochronous• Plug and play• Support power management • USB 1.1&2.0 is a polled bus, it is the host to device or

device to host transfer mode, not the point to point mode (But USB3.0 is PtP)

Page 77: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

USB2.0 Basic programming concept

Usb Bus driver

Host controller driver

Usb Device driver

EHCI

PCI Bus

OHCI

Page 78: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

USB Basic programming concept

Usb Bus driver

Host controller driver

Universal Serial Bus Specification 3.0Universal Serial Bus Specification 2.0

eXtensible Host Controller InterfaceEnhanced Host Controller Interface Specification Universal Host Controller Interface (UHCI) Design GuideOpen Host Controller Interface Specification

Device Class Definition for Human Interface DevicesMass Storage Class Bulk-Only Transport spec Usb Device driver

Page 79: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

USB Basic programming concept

UsbMassStorage

Usb Bus driver

UsbKB

UsbIO

BLKIO TxtIn

EHC driver

UsbMouse

OHC driver

Pointer

UsbIOUsbIO

Usb2_HCUsb2_HCLayer2

Page 80: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

USB Basic programming concept

80

Page 81: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

USB Basic programming concept

Device States: Attached Powered Default Address Configured

81

Page 82: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

USB Basic programming concept

usbview.exe

Page 83: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

USB2.0 host controller drivers

Usb Bus driver

Host controller driver

Usb Device driver

EHCI

PCI Bus

OHCI

Page 84: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

EHCI Programming interface

Page 85: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

EHCI Programming interface

Memory Space

FrameList

Periodic QH

Async QH

MM IO

B0:D29:F7

PCI Configuration Space

EHC MMIO Op regs block

Page 86: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Architecture of EHCI

Page 87: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

EHCI Programming interface

Page 88: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

EHCI Programming interface

Page 89: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

EHCI Programming interface

Memory Space

FrameList

Periodic QH

Async QH

MM IO

B0:D29:F7

PCI Configuration Space

EHC MMIO Op regs block

Control

Isochronous

Bulk

Interrupt

USB standard Transfer

Page 90: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

USB Bus Enumeration

90

Usb Bus driver

Host controller driver

Usb Device driver

EHCI

ICH8PCI Bus

UHCI

Page 91: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

USB Bus – How to do it in UEFI

Enumerate new Usb Bus steps: UsbGetMaxPacketSize UsbSetAddress UsbSelectConfig

All above steps need Usb control transferDemo in shell for the step sequence.

Page 92: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

eXtensible Host Controller Interface

Page 93: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

eXtensible Host Controller Interface

Usb Bus driver

Host controller driver

Usb Device driver

XHCI

PPTPCI Bus

EHCI

Page 94: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Usb3.0 and Usb2.0 Driver relations

UsbMassStorage

Usb Bus driver

xHC driver

UsbKB

UsbIO

BLKIO TxtIn

EHC driver

UsbMouse

UHC driverOHC driver

Pointer

Usb2_HC

UsbIOUsbIO

Usb2_HCUsb2_HCUsb2_HC

Page 95: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

General Architecture of XHCI

Page 96: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Xhci v.s. Ehci/Uhci for programming

Ehci/Uhci Device states unrelated Hardware is simple Software own and track all

device info Software own the detail

transactions level schedule, need create every transaction for a transfer

Xhci Device states unrelated Hardware is complex Hardware own and track

device info Software only own the

transfer level schedule, need not create detail transaction for a transfer

Device BHOST

+

-

+

-

+-

+-

Tx

Rx

Rx

Tx

Tx

Rx

+-

+

-

+-

+

- Tx

Page 97: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Usb3.0 & Xhci host controllerLab goal (实验目的 )

Know the Usb3.0 and superspeed related concepts Know the host controller (Xhci) programming interfaces Know how to write the minimal Xhci driver to access Usb3.0

deviceLab devices(实验器材 )

Atom Lab platform NEC D720200F1 PCIE-Usb3.0 card Duet - Uefi driver development environment

Lab preparation requirement(实验预习要求 ) Review the Usb2.0 and high speed programming interface Review how to get assigned resource of PCIE device How to create Duet and boot shell

Lab context (实验内容 ) Write a basic Xhci driver to support Usb super speed and high

speed flash disk

Page 98: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

实验步骤

Page 99: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Usb3.0 & Xhci host controller

Exercise and questions(实验习题与思考 )1.Does Usb3.0 equal SuperSpeed? 2.Does the Usb3.0 host controller support Usb2.0 high

speed device? How?3. Is the Usb interrupt transfer a real interrupt way?4.What transfer type a standard Usb flash disk need?

What about Usb Mouse and keyboard?5.What’s the programming interface design differences

among the Uhci/Ohci, Ehci and Xhci? Why?6.Please try to minimize and port the Uefi Xhci driver to

Meego/Vxworks/Linux to support a Usb KB or Usb Flash disk?

7.Please complete the Isochronous Transfer in UEFI

Page 100: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

SDIO

Page 101: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

SDIO

Two SDIO ports:Conforms to SD Host Controller Standard

Specification Ver1.0, speed class 6— SD memory card: SD Memory Card

Specifications Part 1 Physical Layer Specification Ver2.0

— SDIO card: SDIO Card Specification Ver1.10— MMC: MMC System Specification Ver4.1

Page 102: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

SDIO Basic programming concept

Page 103: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

SDIO Basic programming concept

Page 104: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Tunnel Creek SDIO programming interface

Page 105: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

SDIO LabLab goal (实验目的 )

Know the Know the

Lab devices(实验器材 ) Atom Lab platform NEC D720200F1 PCIE-Usb3.0 card Duet - Uefi driver development environment

Lab preparation requirement(实验预习要求 ) Review the Usb2.0 and high speed programming interface Review how to get assigned resource of PCIE device How to create Duet and boot shell

Lab context (实验内容 ) Write a basic SDController and MMC drivesr to support SD card

Page 106: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

实验步骤

Page 107: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Exercise and questions (实验习题与思考 )

Page 108: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

ACPI & CPU C/P states

Page 109: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

ACPI Structure

Page 110: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

ACPI Description Tables Structures

Page 111: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

ACPI Description Tables Structures

Page 112: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

ACPI Global System Power States

Page 113: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Processor States

Page 114: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

C States and P States

Page 115: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

C StatesProcessor Power consumption and

thermal management statesReduces power consumption by stopping

the processor Code only executes in the C0 state

OS idle handlers maintain the C State policy and perform C State transitions

Page 116: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

C States – Contd.C0 (Full On)

Active Working State Can throttle the CPU to reduce CPU power consumption

C1 (Auto-Halt) Entered via STI-HLT instruction sequence no hardware support is needed from the chipset has no software-visible effects maintain the context of the system caches

C2 (Stop Grant) a low-power state optimized around multiprocessor

and bus master systems has no software-visible effects has lower power and higher exit latency than the

C1 CPU keeping its caches coherent

Page 117: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

C States

C4 (Deeper Sleep) (Stop-Clock with lower CPU voltage) shuts down its PLL and cannot handle snoop requests Deep Sleep plus reduction in core voltage continue to handle traffic to memory so long as this traffic

does not require a snoop

C6 (Deep Power Down Technology) flush its cache and save its core context to a dedicated on-die

SRAM core processor’s voltage can be completely shut off.

Page 118: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

P StatesMultiple frequency and voltage points for optimal

performance and power efficiency eliminating the need for any coordination during the

frequency/voltage transition.

Offers differing levels of operational efficiency while still in C0 Core frequency and core voltage are changed in unison An incremental shift in voltage is required to increase

frequency for any given processor ƒ ~ V, P ƒ * V2 P ~ V3

Leakage power ~ V2 Thus, reducing performance by 20% can reduce power by

~50%

Page 119: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

P States & Turbo Boost

Page 120: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

ACPI & CPU C/P states Lab

实验目的 Know the ACPI, CPU C and P states concepts Know the how to test and control the C and P states

实验器材 Atom Lab platform WinXP

实验预习要求 Review the ACPI spec 4.0 chapter 8

实验内容 Use tools to see the C states Use tools and test case to see P states different performance

Page 121: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

实验步骤

Page 122: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

I2C, SPI and CAN

Page 123: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

I2C, SPI and CAN

Please refer the programmer guide for the driver API

I2C (Programmer Guide)

SPI (Programmer Guide)

CAN (Programmer Guide)

Page 124: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Other embedded platform

Page 125: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Some potential future topics

• System resource – IO/Mem/MMIO – how the range layout comes from?

• GPIO – LED – How to create LED lab through Atom platform

• Timer/WatchDog – How to implement watchdog through Atom various timer

• IA interrupt – APIC and IOAPIC• Schematic analyze

Page 126: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Need you feedback

Uefi Bios, Dos, Linux, Meego, vxWorks?C, assemble?Software, peripheral device, EE

knowledge?Various Lab?

Page 127: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Thanks

Page 128: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Backup

Page 129: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

What is DUETDUET – Intel Platform Developer UEFI EmulaTion

Why DUET? Provide IHV an EFI/UEFI environment above legacy BIOS, to help them develop and

debug their native EFI/UEFI drivers.

Page 130: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

DUET Goal

Goal is … Export EFI/UEFI interface Support IA32 and X64 architecture Chipset/Platform independent Boot from Floppy Boot from USB (Legacy Free Consideration) Support boot to EFI/UEFI Shell

Page 131: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

DUET Goal (Cont’d)

Goal is not: Not all Framework/PI interfaces are supported

(for example: No PEI phase) Not support IPF

Page 132: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

DUET Pre-requisitePre-requisite:

Platform support USB boot. USB Key support USB boot.

How to verify that: Create DOS on USB. Boot to DOS on the platform by select USB boot.

Page 133: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

DUET Lab SetupSystem requirements:

Microsoft Windows 2000/XP/2003/Win7 256MB+ System Memory 500MB+ Free Space on Hard Drive Visual Studio .NET 2003 or 2005 Professional MASM615

Unzip CD contains EDK and EFI-Shell (May have already been done in NT32 Lab First Day) Unzip the EDK-1.04.Zip to C:\Fw Unzip the EfiShell-1.04.Zip to C:\Fw\Edk\Other\Maintained\

Application

Page 134: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Use the Visual Studio command prompt to setup the proper compiler environment

Make sure MASM6.15 is installed in C:\MASM611.

1

23

4

5

6

Duet Compiler environment

Page 135: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

CD C:\FW\Edk\Sample\Platform\DUET\Build

Update the Config.env file for VS 2005 Only Set USE_VC8 = YES

Build the DUET x64 tip SET EDK_SOURCE=C:\FW\EDK CD C:\FW\Edk\Sample\Platform\DUET\ BUILD UEFI64

Wait for Build to finish …

Build DUET

Page 136: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Build Time stamp

Build DUET (Cont’d)

Page 137: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Create DUET Boot diskPlug Bootable USB disk to the system.Check USB drive number from “My Computer”, for example: E: (See below)In command line

• SET EFI_BOOT_DISK=E:• CD UEFI64• NMAKE CREATEUSB

Unplug this USB, then plug it again• NMAKE USB

Page 138: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Create DUET Boot disk (Cont’d)

Very important

Page 139: Chipset Programming on Embedded IA (Tunnel Creek version) Shi, Steven 2011, July

Boot DUETPlug the USB to the target, and choose

boot from USB.Enjoy the EFI world on your legacy PC …

Below is my T61.