High-Speed I/O Subsystems: PHY, Controller and Three Paths

A fast port is a small team of blocks. A PHY faces the pins, a controller moves the data into memory by itself, and one interrupt tells the core. Every fast port of a large chip has this shape.

You Will Be Able To

  • Name the parts of an I/O subsystem, and say what each one owns.
  • Follow one frame on three paths: control, data and event.
  • Work out how many lanes a load needs, and choose a width that is wired.
Lesson
S10.5
Time
25 min
Runs on
Your browser
Check
5 questions

You press Record on the phone. The camera now sends 124 million bytes each second, and no core could fetch them one by one.

Yet no frame is lost, and the core is almost idle. Something else on the chip is doing the carrying.

Before You Start

You need DMA: a block that copies bytes by itself, the job description, and the done flag.

You need The Interrupt Path: how one event in a device reaches a handler.

You need From Microcontroller to Application Processor: ap_phone, its camera and the word subsystem.

It helps to know The Memory Subsystem. It has a PHY at its pins too.

Five questions this page answers
Question
1Which blocks form an I/O subsystem, and what does each one own?
2Which three paths join the subsystem to the rest of the chip?
3Why does the core not copy the data itself?
4A camera sends 995,328,000 bits each second. How many lanes does it need?
5A frame of 12 bytes arrives on 4 lanes. What does the lab print last?

The Idea: A Team at the Pins, and Three Paths

A slow device hands the core one byte at a time through a register. A fast port cannot work that way. The camera of ap_phone sends 124,416,000 bytes each second. A core that fetched each byte would do nothing else, and it would still be too slow.

So a fast port is built as a small team of blocks: an I/O subsystem. At the pins sits a PHY. The data arrives there on a few fast pairs of pins. Each pair is called a lane. The PHY turns their signals into plain bytes. Behind it sits a controller. It finds the frames in those bytes, and it writes them to memory by itself.

Three paths join this team to the rest of the chip. On the control path the core writes a few registers: where the buffer is, and how long. On the data path the bytes go from the controller straight into memory. On the event path one interrupt says that the buffer is full.

The core touches the job a handful of times for each frame. It never touches the data. Camera, display, storage and network ports all have this shape. Each one brings a PHY and a controller of its own, and the same three paths.

New Words

New words on this page
WordMeaning
I/O subsystemThe blocks that bring data across the pins of one port: a PHY, a controller, and their paths into the chip.
Serial laneA pair of pins that carries bits one after another, very fast. Lane for short. A port can use several side by side.
I/O controllerThe digital block behind the PHY. It finds the frames in the bytes, and it has registers and a DMA side. Controller for short.
Data bufferA stretch of memory that software sets aside for the data of one job. Buffer for short.
Control pathThe way of the register accesses: from the core, over the bus, to the controller.
Data pathThe way of the data: from the pins, through the PHY and the controller, into memory.
Event pathThe way of the news that a job has ended: an interrupt from the controller to the core.
PayloadThe bits that the user wants. Here: the picture data.
Lane overheadThe other bits on a lane. They mark where a line or a frame starts, and they let the receiver find errors.
Link widthThe number of lanes that a port uses together.
IOMMUA block between the DMA side of a device and memory. It checks and changes the address of every access. Short for I/O memory management unit.
The registers of the controller in the lab
RegisterWhat it holds
BUFFERThe address of the first byte of the buffer. Software writes it.
LENGTHThe number of bytes in one frame. Software writes it.
STARTA write of 1 starts the job. Software writes it last.
STATUSBit 0 is the done flag. Software reads it in the handler.

One Picture: One Fast Port, Three Paths

One Fast Port, Three PathsStep through the picture. It starts at the pins, follows the data into memory, and then adds the two paths of the core.
  • Processor
  • Peripheral
  • Memory
  • External
  • Pads
  • Bus
One Fast Port, Three PathsStep through the picture. It starts at the pins, follows the data into memory, and then adds the two paths of the core. component Core describes the job,then waits component Interruptcontroller passes one requeston component Memory holds the buffer component Camera outside the chip component PHY turns the signals ofthe lanes into bytes component Controller finds the frames, andwrites them out byDMA component IOMMU checks the addressof every write lanesbytesDMA writeschecked writesregistersinterruptone wire
  1. component Cameraoutside the chip
    • lanes → PHY
  2. component PHYturns the signals of the lanes into bytes
    • bytes → Controller
  3. component Controllerfinds the frames, and writes them out by DMA
    • DMA writes → IOMMU
    • interrupt → Interrupt controller
  4. component IOMMUchecks the address of every write
    • checked writes → Memory
  5. component Memoryholds the buffer
  6. component Coredescribes the job, then waits
    • registers → Controller
  7. component Interrupt controllerpasses one request on
    • one wire → Core
  1. At the pins

    The camera drives the lanes. The PHY samples them and hands plain bytes to the controller.

  2. The data path

    The controller writes the bytes to memory by itself. No byte of the frame passes through the core.

  3. The control path

    Before the frame, the core writes three registers of the controller: the buffer, the length and the start.

  4. The event path

    After the last write the controller raises one interrupt. It reaches the core as any interrupt does.

  5. The guard on the way

    On a large chip a block stands between the controller and memory. It checks the address that software gave. A later lesson teaches it.

Read the diagram as text
  • Core: describes the job, then waits
  • Interrupt controller: passes one request on
  • Memory: holds the buffer
  • Camera: outside the chip
  • PHY: turns the signals of the lanes into bytes
  • Controller: finds the frames, and writes them out by DMA
  • IOMMU: checks the address of every write
  • Camera → PHY: lanes
  • PHY → Controller: bytes
  • Controller → IOMMU: DMA writes
  • IOMMU → Memory: checked writes
  • Core → Controller: registers
  • Controller → Interrupt controller: interrupt
  • Interrupt controller → Core: one wire

The camera port of ap_phone, at box level. The lab of this page has no IOMMU: its writes go straight to memory.

The Smallest Example, Worked by Hand

No simulator yet. Take one second of the camera of ap_phone: 30 frames of 4,147,200 bytes each. For each frame the core writes three registers and reads one. Count what crosses each path.

One second of camera, path by path
PathWhat crosses it in one secondHow it is counted
Control120 register accesses3 writes and 1 read for each of 30 frames
Data124,416,000 bytes30 frames of 4,147,200 bytes, written by the controller
Event30 interruptsone for each frame

The data path carries about a million times more than the control path. That is why the two are built apart. The control path can use a slow, cheap bus. The data path needs the widest road on the chip.

Now the pins. The camera sends 124,416,000 bytes, which is 995,328,000 bits, each second. One lane of this port moves 500,000,000 bits each second. Only 80 percent of them are payload, so a lane carries 400,000,000 useful bits.

How many lanes?
LanesUseful bits each secondEnough for 995,328,000?
1400,000,000No
2800,000,000No
31,200,000,000Yes
41,600,000,000Yes

Three lanes are the least that will do. But the port of ap_phone is wired for a link width of 1, 2 or 4. So the camera gets 4 lanes.

The Rules

  1. Rule 1: The PHY owns the pins, and the controller owns the meaning.

    The PHY delivers bytes. The controller knows where a frame starts and ends.

  2. Rule 2: The core describes the job through registers, and writes the start last.

    That is the whole control path: a few accesses for each job.

  3. Rule 3: The controller writes the data to memory by itself.

    It is a manager on the bus. The core takes no part in the data path.

  4. Rule 4: The address of the buffer comes from software.

    So a wrong address sends the data to the wrong place. A large chip puts a check on that way.

  5. Rule 5: One interrupt ends a job, after the last write.

    Done means that memory has the data. It does not mean that the pins went quiet.

  6. Rule 6: Budget each direction by itself: payload each second, divided by useful bits for each lane, rounded up.

    Then go up to the next link width that is wired.

Sources for These Rules

A device controller that moves data to memory without the processor, and an interrupt at the end: Patterson and Hennessy, Computer Organization and Design, ARM edition, section 6.9.

The split between a PHY and the logic behind it holds for several serial protocols. See the Intel PIPE specification, revision 7.1, section 2, with its figures 2-1 and 2-2.

Rules 2, 3 and 5 repeat the DMA rules of this track on a faster device.

The numbers of the camera port (lanes of 500,000,000 bits each second, 80 percent payload, widths of 1, 2 or 4) are exercise values of ap_phone. They come from no camera standard: none is in the library of this site.

Now Run It

The lab at the end of this page sends one small frame of 8 bytes through a port with 2 lanes. It is test code: a model that keeps count, with no circuit and no real signals.

Printed by the lab on Icarus. One row for each tick, then the counts, then the budget of the real camera.
t=0 path=control core writes BUFFER=0100
t=1 path=control core writes LENGTH=0008
t=2 path=control core writes START=0001
t=3 path=data bytes=2 written_to=0100..0101
t=4 path=data bytes=2 written_to=0102..0103
t=5 path=data bytes=2 written_to=0104..0105
t=6 path=data bytes=2 written_to=0106..0107
t=7 path=event done=1 irq=1
t=8 path=control core reads STATUS=1
core_accesses=4 dma_writes=8 irqs=1 last_byte=17
budget payload_bits=995328000 useful_per_lane=400000000 minimum=3 fitted=4

Rule 2 at work, in the rows t=0 to t=2. The core writes BUFFER, LENGTH and START, in that order. Nothing moves before START.

Rule 3, in the rows t=3 to t=6. On each tick the PHY hands over one byte from each of the 2 lanes. The controller writes both, starting at address 0100. No row of the core appears here.

Rule 5, in the row t=7. The last write was on the tick before. Only now are done and irq 1. The handler then reads STATUS once.

The row of counts sums it up: core_accesses=4 and dma_writes=8. Make the frame a million times longer, and the first number stays 4.

Rule 6, in the last row. It is the hand sum: 995,328,000 bits, 400,000,000 for each lane, minimum=3, fitted=4.

This lab leaves things out. Its PHY hands over whole bytes, and a real one samples single bits and must first find where a byte starts. It has no frame marks and no IOMMU. Its bus never makes the controller wait.

Why It Is Built This Way

ChoiceThe alternativeIts cost
A PHY apart from the controllerOne block for pins and logicThe circuits at the pins are tied to one chip process. The logic is not. Apart, each can be reused and replaced.
The controller writes to memoryThe core reads each byte from a register124,416,000 register reads each second. No core has that time.
One interrupt for a frameOne interrupt for each byteEach interrupt costs a jump into a handler and back. The core would do nothing else.

The first row is also why a chip team often buys the PHY from one company and the controller from another. The boundary between the two then needs a written agreement of its own.

The Trap: The Half Lane That Was Rounded Away

A budget says 2.49 lanes, and someone orders 2. The link trains, the first pictures look fine, and the test passes. Under a full frame rate the lanes fall behind by a fifth of every second, and frames vanish. Round up, always.

The second trap adds both directions. A lane pair moves 500,000,000 bits each way. That does not give 1,000,000,000 for a frame that travels one way.

The third trap is a unit. The camera rate was in bits, and the memory budget is in bytes. Copy the number across unchanged and the load on memory looks eight times too large.

The fourth is the quiet one. Software writes a wrong value to BUFFER. The controller obeys, and 4 million bytes land on somebody else's data. No error is raised, because every write was legal on the bus.

At Scale

This lab8 bytes on 2 lanes
The camera of ap_phone124,416,000 bytes a second

This section looks ahead, to real protocols and to what a port needs before its first byte.

  1. The same shape, other names

    PCI Express is the port of expansion cards. PCI is short for peripheral component interconnect. USB (Universal Serial Bus), flash storage, a display and Ethernet are other fast ports. Each has a PHY, a controller and the three paths. What the bits on the lanes mean differs from one to the next.

  2. Who checks the address

    The guard of rule 4 gives each device a view of memory of its own, so that a wrong buffer address is refused. That is the IOMMU.

  3. Before the first byte

    A lane works only after its supply is on, its reference clock is steady and its reset is released. Then the two ends must still agree on a speed. Power, clocks and reset each have a lesson later in this module.

  4. The longest gap

    The budget is an average. When memory is busy for a moment, the controller must hold the bytes that arrive meanwhile. Its queue is sized for the longest gap, not for the mean.

The Protocols track of this site teaches what travels on the lanes. Start with Why Serial at Speed and SerDes Architecture, then Ethernet in One Picture. Its lessons on PCI Express and USB are planned and not yet written.

The guard continues in I/O Memory Management and Virtualisation.

Try It

Run the lab. Count the rows of each path: four on the control path, four on the data path, one on the event path.

Change LANES to 4 and run again. Predict how many data rows remain, and whether core_accesses changes.

Change BYTES_PER_S to 248_832_000, the camera at 60 frames a second. Read minimum and fitted in the last row.

Names Printed by the Lab
NameMeaning
tThe time of the row, in ticks. A tick is the time unit of this lab.
pathWhich of the three paths the row belongs to: control, data or event.
bytes, written_toHow many bytes the controller wrote on this tick, and the first and last address, in hex.
done, irqThe done flag of the controller, and its interrupt request.
core_accessesRegister accesses made by the core in the whole run.
dma_writesBytes that the controller wrote to memory by itself.
irqs, last_byteInterrupts raised, and the byte at the last address of the buffer.
payload_bitsBits of picture data that the camera of ap_phone sends each second.
useful_per_laneBits of picture data that one lane can carry each second.
minimum, fittedThe whole lanes needed, and the smallest wired width that holds them. A fitted value of 0 means none does.
RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: t=0 path=control core writes BUFFER=0100 t=1 path=control core writes LENGTH=0008 t=2 path=control core writes START=0001 t=3 path=data bytes=2 written_to=0100..0101 t=4 path=data bytes=2 written_to=0102..0103 t=5 path=data bytes=2 written_to=0104..0105 t=6 path=data bytes=2 written_to=0106..0107 t=7 path=event done=1 irq=1 t=8 path=control core reads STATUS=1 core_accesses=4 dma_writes=8 irqs=1 last_byte=17 budget payload_bits=995328000 useful_per_lane=400000000 minimum=3 fitted=4

Check Yourself

Predict the outputIn this run the frame has 12 bytes and the port has 4 lanes. What is the last line? Its form is: core_accesses=.. dma_writes=.. irqs=.. last_byte=..
module tb;
  // A camera port in miniature. One small frame crosses the subsystem.
  localparam int LANES = 4;         // lanes that carry the frame side by side
  localparam int FRAME_BYTES = 12;   // bytes in one frame of this lab
  // The camera port of ap_phone, for the budget in the last row.
  localparam longint BYTES_PER_S = 124_416_000;         // what the camera sends each second
  localparam longint RAW_BITS_PER_LANE = 500_000_000;   // bits that one lane moves each second
  localparam int USEFUL_PERCENT = 80;                   // the share of those bits that is picture data

  // The registers of the controller.
  int buffer_reg, length_reg;
  bit start_reg, done, irq;
  byte unsigned memory [0:1023];
  int t = 0, core_accesses = 0, dma_writes = 0, irqs = 0;

  // Control path: the core writes a register of the controller over the bus.
  task automatic core_writes(input string name, input int value);
    core_accesses++;
    $display("t=%0d path=control core writes %s=%04h", t, name, 16'(value));
    t++;
  endtask

  // Data path: on each tick the PHY hands over one byte from every lane, and the DMA side of the
  // controller writes those bytes to memory by itself. The core takes no part.
  // Event path: after the last write the controller sets done and raises its interrupt.
  task automatic receive_frame;
    int sent, first;
    sent = 0;
    while (start_reg && sent < length_reg) begin
      first = sent;
      for (int lane = 0; lane < LANES && sent < length_reg; lane++) begin
        memory[buffer_reg + sent] = 8'h10 + sent;   // the byte that the camera sent
        sent++;
        dma_writes++;
      end
      $display("t=%0d path=data bytes=%0d written_to=%04h..%04h", t, sent - first, 16'(buffer_reg + first), 16'(buffer_reg + sent - 1));
      t++;
    end
    done = 1;
    irq = 1;
    irqs++;
    $display("t=%0d path=event done=%0d irq=%0d", t, done, irq);
    t++;
  endtask

  // Control path again: the handler reads the status register once.
  task automatic core_reads_status;
    core_accesses++;
    $display("t=%0d path=control core reads STATUS=%0d", t, done);
    irq = 0;
    t++;
  endtask

  // Whole lanes needed for a load, and the smallest wired width that holds them (1, 2 or 4 lanes).
  task automatic budget;
    longint payload_bits, useful_per_lane;
    int minimum, fitted;
    payload_bits = BYTES_PER_S * 8;
    useful_per_lane = RAW_BITS_PER_LANE * USEFUL_PERCENT / 100;
    minimum = (payload_bits + useful_per_lane - 1) / useful_per_lane;
    fitted = minimum <= 1 ? 1 : minimum <= 2 ? 2 : minimum <= 4 ? 4 : 0;
    $display("budget payload_bits=%0d useful_per_lane=%0d minimum=%0d fitted=%0d", payload_bits, useful_per_lane, minimum, fitted);
  endtask

  initial begin
    buffer_reg = 'h100;
    core_writes("BUFFER", buffer_reg);
    length_reg = FRAME_BYTES;
    core_writes("LENGTH", length_reg);
    start_reg = 1;
    core_writes("START", start_reg);
    receive_frame;
    core_reads_status;
    $display("core_accesses=%0d dma_writes=%0d irqs=%0d last_byte=%02h", core_accesses, dma_writes, irqs, memory[buffer_reg + length_reg - 1]);
  end
endmodule
ConceptWhich block turns the signals on the lanes into bytes?
ConceptWhich path carries the picture data?
ConceptWhy does the core not copy the data itself?
ConceptA load of 995,328,000 bits each second meets lanes of 400,000,000 useful bits. The port is wired for 1, 2 or 4 lanes. Which width fits?

Common Mistakes

Wrong Round 2.49 lanes down to 2.

Two lanes leave a fifth of every second of picture waiting.

Fix Round up, then go up to a width that is wired.

Wrong Add the two directions of a lane for one frame.

A frame travels one way.

Fix Budget each direction by itself.

Wrong Take the interrupt for the data.

The interrupt says that a job ended. It carries no byte.

Fix Follow the writes of the controller into the buffer.

Remember

  • A fast port is a PHY at the pins and a controller behind it.
  • The core describes the job, the controller moves the data, and one interrupt ends the job.
  • Budget lanes by payload, round up, and go up to a wired width.
  • The buffer address comes from software, so a large chip checks it on the way to memory.

Practice

Report a problem with this page