Showing posts with label Architecture. Show all posts
Showing posts with label Architecture. Show all posts

Tuesday, 21 May 2013

MESSAGE SIGNALED INTERRUPT


Hope you might have read my previous article "Interrupt journey  from hardware to software"

Due to increasing pressure on chipset and processor packages to reduce pin count, the need for interrupt pins is expected to diminish over time.Devices, due to pin constraints, may implement messages to increase performance. 

PCI Express endpoints uses INTx emulation (in-band messages) instead of IRQ pin assertion. Using INTx emulation requires interruptsharing among devices connected to the same node (PCI bridge) while MSI is unique (non-shared) and does not require BIOS configuration support. As a result, the PCI Express technology requires MSI support for better interrupt performance.


INTERRUPT DELIVERY MECHANISM


Legacy PCI Interrupt Delivery

   

This mechanism supports devices that must use PCI-Compatible interrupt signaling (i.e., INTA#, INTB#, INTC#, and INTD#) defined for the PCI bus. Legacy functions use one of the interrupt lines to signal an interrupt. An INTx# signal is asserted to request interrupt service and deasserted when the interrupt service accesses a device-specific register, thereby indicating the interrupt is being serviced.


Native PCI Express Interrupt Delivery 


Native PCI Express device use message signaled interrupt. A Message Signaled Interrupt is not a PCI express message instead it is a simple memory write transaction. This write is distinguished from normal write by target address which is reserved for MSI interrupt delivery.

           PCI Express and Legacy Interrupt Delivery




Message Signaled Interrupts (MSIs) are delivered to the Root Complex via memory write transactions. The MSI Capability register provides all the information that the device requires to signal MSIs. This register is set up by configuration software (PCI bus driver) and includes the following information:


  • Target memory address
  • Data Value to be written to the specified address location
  • The number of messages that can be encoded into the data



         MSI Capability Register



MSI Configuration Process


The following list specifies the steps taken by software (PCI bus driver) to configure MSI interrupts for a PCI Express device.

1. At startup time, the configuration software scans the PCI bus(es) (referred to as bus enumeration) and discovers devices (i.e., it performs configuration reads for valid Vendor IDs). On discovering a PCI express function, the configuration software reads the Capabilities List Pointer to obtain the location of the first Capability register within the chain of registers.

2. The software then searches the capability register sets until it discovers the MSI Capability register set (Capability ID of 05h).

3. Software assigns a dword-aligned memory address to the device's Message Address register. This is the destination address of the memory write used when delivering an interrupt request.

4. Software checks the Multiple Message Capable field in the device's Message Control register to determine how many event-specific messages the device would like assigned to it.

5. The software then allocates a number of messages equal to or less than what the device requested. At a minimum, one message will be allocated to the device.

6. The software writes the base message data pattern into the device's Message Data register.

7. Finally, the software sets the MSI Enable bit in the device's Message Control register, thereby enabling it to generate interrupts using MSI memory writes.






Memory Write Transaction (MSI):


When the device must generate an interrupt request, it writes the Message Data register contents to the memory address specified in its Message Address register. Header fields need to filled.



MSI-x is a extension to MSI which supports additional vectors per function.

Reference: PCI Express System Architecture


Friday, 3 May 2013

INTERRUPT JOURNEY FROM HARDWARE TO SOFTWARE - 1



Interrupt is a very vast topic. This post is about How Interrupt is generated from Peripheral and routed to the processor. Exactly till we get an IRQ number.

INTERRUPT
    An event external to the currently executing process that causes a change in the normal flow of instruction execution, usually generated by hardware devices external to the CPU sometimes by software.

We will deal software interrupts and exceptions in a separate post.

Hardware interrupts are asynchronous in nature.

How it is asynchronous ? 

Interrupt will not wait for nay other CPU routine to complete. It can be raised even in the middle of CPU execution.

Interrupt Vs Polling

Polling is a technique used by CPU to check for events in the peripheral device in a periodic manner.

Pros:

Efficient if interrupts arrive frequently.

Cons:

Takes precious CPU time even when there is no request from external device.

Each hardware interrupt has an interrupt level, trigger, and interrupt priority.
The following sections describe various interrupt components:

The interrupt level defines the source of the interrupt and is often referred to as the interrupt sourceThere are basically two types of interrupt levels: system and bus. The bus interrupts are generated by the devices on the buses (such as PCI, ISA, VDEVICE, and PCI-E). Examples of system interrupts are the timer and Environmental and Power Off Warning (EPOW).

There are two types of trigger mechanisms, level-triggered interrupts and edge-triggered interrupts.
Level-Triggered: A level-triggered interrupt module always generates an interrupt whenever the level of the interrupt source is asserted.

Tuesday, 30 April 2013

Memory Mapping

Many of us have heard "Memory mapping" numerous time.

Hardware registers, data buffers are mapped ? Where it is mapped? 

We might have worked on lot of PCI devices with register set used for control, status, data access.

OS with the help of device drivers used to map the register space in device into main memory that is RAM.

Device drivers, kernel code does not have direct access over hardware, they will write or read from the mapped space in RAM. OS has special memory management functions to do this 
(eg: ioremap in linux). OS needs physical Base address to perform this operation which can be obtained from PCI configuration space (BAR- Base Address Register).


   Memory space


Devices are mapped into kernel space. Application are mapped to user space which have their own privilege

But, how data written into RAM (mapped space) is copied to Register space and values updated in hardware register is visible in RAM memory space?

load/store architecture only allows memory to be accessed by load and store operations, and all values for an operation need to be loaded from memory and be present in registers. Following the operation, the result needs to be stored back to memory


  • load To load a value from memory, you copy the data from memory into a register.
  • store To store a value to memory, you copy the data from a register to memory.