Просмотр исходного кода

Bring up the Gigabyte 970A-DS3P and fix SB950 OHCI input

AMD/board: parse both MADT IOAPICs and mask their normal redirection
entries after ACPI init (ioapic.c), sample family 15h Tctl through
D18F3xA4 with the kworker under the BKL, and add a separate AMD WC MTRR
path that uses only a free variable entry with a zero high mask and never
writes MTRRdefType (the 970A reset during paging init otherwise).  Cap
the VBE/GOP mode at 1920x1080 so the full-screen RGB565 canvas still fits
the 4 MB window slot, and make vga_fb_lfb_wc() report the MTRR-backed LFB
path as well as the ION alias.

USB: the SB950's legacy OHCI DMA does not snoop dirty CPU cache lines, so
the EDs, TDs, setup packet and interrupt buffers move into a dedicated
page that paging_init maps uncacheable before paging is enabled.  Without
it the controller sometimes read an empty ED, skipped the transfer and
never re-armed the endpoint, freezing the cursor with no error.  Control
data buffers stay write-back and are flushed around the transfer.

Enumeration now starts on the USB default 8-byte EP0 and adopts the
descriptor's real bMaxPacketSize0, settles 20 ms after a port reset, and
retries a failed port three times with a fresh reset.  The boot scan gets
a second OHCI pass 60 ms after the EHCI-first walk, because the companion
handback can leave a low-speed port briefly disconnected.  HID detach is
debounced (three disconnected reads, 50 TD errors) and forces a clean
full rescan, since a false port-loss leaves no CSC to wake the per-port
path.  DoneHead/WDH is acknowledged on every poll as well.

Docs: AGENTS.md and the architecture pages cover the 970A target, IOAPIC
masking, AMD thermal/MTRR, the 1080p limits and the SB950 USB path.
Johannes Zellner 6 дней назад
Родитель
Сommit
8d63339700
27 измененных файлов с 1121 добавлено и 209 удалено
  1. 182 54
      AGENTS.md
  2. 37 6
      Makefile
  3. 24 0
      acpi.c
  4. 3 0
      acpi.h
  5. 2 2
      docs/boot.html
  6. 17 11
      docs/cpu.html
  7. 4 2
      docs/development.html
  8. 31 5
      docs/drivers.html
  9. 24 12
      docs/graphics.html
  10. 1 1
      docs/network.html
  11. 8 3
      efi/main.c
  12. 82 0
      ioapic.c
  13. 11 0
      ioapic.h
  14. 7 2
      kernel.c
  15. 108 0
      mtrr.c
  16. 7 4
      nvidia.c
  17. 241 46
      ohci.c
  18. 55 2
      paging.c
  19. 2 0
      paging.h
  20. 98 6
      thermal.c
  21. 12 4
      thermal.h
  22. 1 1
      ucmd_cpuinfo.c
  23. 3 3
      ucmd_sensors.c
  24. 123 40
      usb.c
  25. 14 2
      usbhid.c
  26. 21 2
      vesa_stage.S
  27. 3 1
      vga.c

+ 182 - 54
AGENTS.md

@@ -63,6 +63,8 @@ make run-ehci-asix # pass through a real ASIX AX88772 dongle on EHCI
 make run-net    # like `make run` + a PCI NE2000 NIC on QEMU's user network (slirp; DHCP/DNS/NAT)
 make run-net    # like `make run` + a PCI NE2000 NIC on QEMU's user network (slirp; DHCP/DNS/NAT)
 make run-rndis  # xHCI + QEMU usb-net RNDIS tethering device on slirp (rndis netdev)
 make run-rndis  # xHCI + QEMU usb-net RNDIS tethering device on slirp (rndis netdev)
 make run-ahci   # like `make run` + an ICH9 AHCI controller and a 512 MB SATA disk (sata0)
 make run-ahci   # like `make run` + an ICH9 AHCI controller and a 512 MB SATA disk (sata0)
+make run-amd    # QEMU Opteron_G5 (FX-6350 family 15h model 2), 6 CPUs, OHCI + e1000
+make test-amd   # headless AMD boot check (IOAPIC mask, 6 CPUs, PIT)
 make uefi       # build BOOTX64.EFI and the dual-boot usb-efi.img
 make uefi       # build BOOTX64.EFI and the dual-boot usb-efi.img
 make run-uefi   # boot usb-efi.img under OVMF (x86-64 UEFI; serial log in /tmp/opencode)
 make run-uefi   # boot usb-efi.img under OVMF (x86-64 UEFI; serial log in /tmp/opencode)
 make test-uefi  # headless OVMF boot test (greps the serial log for the boot line)
 make test-uefi  # headless OVMF boot test (greps the serial log for the boot line)
@@ -149,6 +151,13 @@ make clean
   BIOS never read FATSize16.  `make flash` needs the mingw toolchain because
   BIOS never read FATSize16.  `make flash` needs the mingw toolchain because
   it builds `usb-efi.img`.
   it builds `usb-efi.img`.
 
 
+The Gigabyte 970A-DS3P / FX-6350 / GTX 960 target is **UEFI-first** and
+serial-less: boot `usb-efi.img` from USB, use the 970A's SB950 AHCI/OHCI/EHCI,
+the RTL8111E (`10ec:8168`) and the GTX 960 through its GOP.  The boot console
+is the only early log; once DHCP works, `make netmon` is the serial substitute
+and `make net-dev`/`kernel-net-dev` reload over the network.  `bootlog save
+/usb0p3/BOOTLOG.TXT` writes the captured boot log to the live stick's FAT ESP.
+
 ## Boot chain
 ## Boot chain
 
 
 1. `boot.S` — 512-byte boot sector (FAT16 BPB). Loads contiguous kernel sectors
 1. `boot.S` — 512-byte boot sector (FAT16 BPB). Loads contiguous kernel sectors
@@ -172,7 +181,9 @@ make clean
    pack; the CPU copy is used instead.  `paging_prepare_cpu()` still clears
    pack; the CPU copy is used instead.  `paging_prepare_cpu()` still clears
    the CR4/EFER state a BIOS protected-mode call can leave behind.  The
    the CR4/EFER state a BIOS protected-mode call can leave behind.  The
    stage then picks the best VBE mode
    stage then picks the best VBE mode
-   (≥16 bpp, LFB, fits VRAM, ≤1280px), writes mode info to `0x600` and the
+   (≥16 bpp, LFB, fits VRAM, ≤1920px, shadow ≤8 MB and ≤2 M pixels so a
+   full-screen RGB565 canvas fits the 4 MB window slot), writes mode info
+   to `0x600` and the
    12-dword `struct boot_info` (magic/checksum/rsdp/flags/pack range) to
    12-dword `struct boot_info` (magic/checksum/rsdp/flags/pack range) to
    `0x500`, enters protected mode and jumps to `kernel_entry` (`entry.S`,
    `0x500`, enters protected mode and jumps to `kernel_entry` (`entry.S`,
    re-points ESP to the current stack top, then `kernel_main`).  The pack
    re-points ESP to the current stack top, then `kernel_main`).  The pack
@@ -293,8 +304,11 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   Ring 0 is preemptible at tick boundaries unless `preempt_count` is set (FAT
   Ring 0 is preemptible at tick boundaries unless `preempt_count` is set (FAT
   and the shadow flush) or the BKL is held; voluntary blocks/yields go through
   and the shadow flush) or the BKL is held; voluntary blocks/yields go through
   the `int 0x81` gate.
   the `int 0x81` gate.
-- **SMP / ACPI**: `acpi.c/h` (RSDP → RSDT/XSDT → MADT; CPU/LAPIC list and
-  LAPIC base; 4 MB table page mapping; malformed tables are ignored), `lapic.c/h`
+- **SMP / ACPI**: `acpi.c/h` (RSDP → RSDT/XSDT → MADT; CPU/LAPIC and IOAPIC
+  base lists; 4 MB table page mapping; malformed tables are ignored),
+  `ioapic.c/h` (masks the normal IOAPIC redirection entries after ACPI init so
+  the 8259/LINT0 path is deterministic; ExtINT entries are preserved),
+  `lapic.c/h`
   (xAPIC MMIO access, BSP/AP init, INIT/SIPI/IPI, calibrated periodic timer),
   (xAPIC MMIO access, BSP/AP init, INIT/SIPI/IPI, calibrated periodic timer),
   `smp.c/h` (trampoline copy, AP stacks via `process_init_ap`, INIT-SIPI-SIPI
   `smp.c/h` (trampoline copy, AP stacks via `process_init_ap`, INIT-SIPI-SIPI
   with a second SIPI retry, per-CPU `smp_ap_main`, `smp_stop_aps`, lazy
   with a second SIPI retry, per-CPU `smp_ap_main`, `smp_stop_aps`, lazy
@@ -413,7 +427,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `sys_wm.c` is the ABI bridge.  `SYS_WIN_CREATE` gives a command its window
   `sys_wm.c` is the ABI bridge.  `SYS_WIN_CREATE` gives a command its window
   canvas mapped RW at `USER_WIN_BASE` (`0x50000000`); the WM maps each front
   canvas mapped RW at `USER_WIN_BASE` (`0x50000000`); the WM maps each front
   canvas in its own 4 MB `WM_CONTENT_SLOT`, which covers a full-screen
   canvas in its own 4 MB `WM_CONTENT_SLOT`, which covers a full-screen
-  1280x1024 canvas minus the chrome.  `SYS_WIN_PRESENT`
+  1920x1080 RGB565 canvas (4.15 MB) minus the chrome.  `SYS_WIN_PRESENT`
   optionally takes a content-relative `struct wm_win_present`; the kernel
   optionally takes a content-relative `struct wm_win_present`; the kernel
   copies only that rectangle into the front canvas (with interrupts off, so
   copies only that rectangle into the front canvas (with interrupts off, so
   a half-drawn frame can never reach the screen), unions it into
   a half-drawn frame can never reach the screen), unions it into
@@ -445,7 +459,9 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   press/release edges with a capture window, so a click that starts in a
   press/release edges with a capture window, so a click that starts in a
   window still gets its release after the pointer leaves.  The userland
   window still gets its release after the pointer leaves.  The userland
   `ngui.c/h` immediate-mode toolkit builds on those: clipped RGB565
   `ngui.c/h` immediate-mode toolkit builds on those: clipped RGB565
-  primitives, buttons, text input, procedural icons and scrolling panes.
+  primitives, buttons, text input, procedural icons and scrolling panes
+  (`ngui_scroll`; `hide_bar` keeps wheel/key scrolling without drawing a
+  scrollbar).
   `files` (`ucmd_files.c`) is its first user; `gallery` (`gallery.c`) is the
   `files` (`ucmd_files.c`) is its first user; `gallery` (`gallery.c`) is the
   live showcase of every control and primitive the toolkit exports.  Buttons
   live showcase of every control and primitive the toolkit exports.  Buttons
   fire on the release edge and keep `active` until `ui->released`: inferring
   fire on the release edge and keep `active` until `ui->released`: inferring
@@ -503,8 +519,13 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   through that alias once a WC MTRR covers the stolen range (only then -- a
   through that alias once a WC MTRR covers the stolen range (only then -- a
   cached framebuffer would stop updating the screen).  Everything else keeps
   cached framebuffer would stop updating the screen).  Everything else keeps
   the UC LFB: `paging.c` maps LFB pages cacheable only when `mtrr_set_wc()`
   the UC LFB: `paging.c` maps LFB pages cacheable only when `mtrr_set_wc()`
-  says it covered them.  `vga_fb_lfb_wc()` reports the effective path and
-  `gfxbench` prints it. `nvidia.c`
+  says it covered them.  On AMD family 15h, `mtrr_set_wc()` uses a separate
+  path: at most eight variable MTRRs, only a free entry, a zero high mask
+  (the LFB is below 4 GB) and **no write to `MSR_MTRRdefType`**.  The Intel
+  path's read-modify-write of `MTRRdefType` reset the 970A-DS3P during the
+  first paging init; the AMD path is validated on the board and enables WC.
+  `vga_fb_lfb_wc()` reports the effective path and `gfxbench` prints it.
+  `nvidia.c`
   identifies the card, maps BAR0/BAR1/BAR3 and reads the MCP7x stolen-VRAM
   identifies the card, maps BAR0/BAR1/BAR3 and reads the MCP7x stolen-VRAM
   geometry; `nv50.c` probes the nv50-family display engine at boot (read-only,
   geometry; `nv50.c` probes the nv50-family display engine at boot (read-only,
   serial/netmon). The ION/AT3IONT-I hardware cursor is deliberately not driven:
   serial/netmon). The ION/AT3IONT-I hardware cursor is deliberately not driven:
@@ -704,7 +725,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   layout, because it has no RFCTL but QEMU stores the register, so EXTEN
   layout, because it has no RFCTL but QEMU stores the register, so EXTEN
   reads back set while the device still writes legacy descriptors),
   reads back set while the device still writes legacy descriptors),
   `r8168.c`
   `r8168.c`
-  RTL8111/8168 (PCIe, polled, C+ mode, 64-entry RX ring), `ne2000.c`
+  RTL8111/8168 family, including the RTL8111E on the Gigabyte 970A-DS3P
+  (PCIe, polled, C+ mode, 64-entry RX ring), `ne2000.c`
   RTL8029 (QEMU/ISA), `asix.c` AX88772 USB Ethernet (bulk over the USB
   RTL8029 (QEMU/ISA), `asix.c` AX88772 USB Ethernet (bulk over the USB
   core, so an EHCI/xHCI dongle is usable) and `rndis.c` USB RNDIS tethering
   core, so an EHCI/xHCI dongle is usable) and `rndis.c` USB RNDIS tethering
   (Android phones and QEMU `usb-net`; device-level config scan, RNDIS
   (Android phones and QEMU `usb-net`; device-level config scan, RNDIS
@@ -1094,10 +1116,19 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   scales as well as the top bar's bare `43C` before the clock and, on
   scales as well as the top bar's bare `43C` before the clock and, on
   ThinkPads and the HP Chromebook, the AC/battery icon at the far right (a
   ThinkPads and the HP Chromebook, the AC/battery icon at the far right (a
   plug while on AC, a level-filled battery on battery, with a percentage
   plug while on AC, a level-filled battery on battery, with a percentage
-  tooltip below it on hover) and `cpuinfo`'s value plus EIST state.  Platforms
-  without DTS (QEMU, Pentium) hide it.
+  tooltip below it on hover) and `cpuinfo`'s value plus EIST state.
+  AMD family 15h models below `0x60` (Bulldozer/Piledriver, the FX-6350)
+  read Tctl from `D18F3xA4` at PCI `0:18.3`: `raw = val >> 21`, `raw * 125`
+  m°C, minus 49 °C when bits 17:16 are both set, TjMax 70 °C.  The probe
+  runs on the BSP before the timer; the 1 Hz sample runs from the kworker's
+  `thermal_housekeeping()` under the BKL (never from the per-CPU timer
+  interrupt, where a PCI config access could race another CPU) and is
+  published to every CPU.  No AMD MSR is touched, so there is no early
+  `#GP` risk.  A platform with neither Intel DTS nor AMD `D18F3xA4` hides
+  the temperature.
 - **Board sensors**: `it87.c/h` — read-only probe of the IT87xx Super I/O
 - **Board sensors**: `it87.c/h` — read-only probe of the IT87xx Super I/O
-  (the AT3IONT-I exposes three temperatures and three fan tachometers), used
+  (the AT3IONT-I and the 970A-DS3P's IT8728F expose temperatures and fan
+  tachometers), used
   by `SYS_SENSORS` and the ring-3 `sensors` command to cross-check the DTS
   by `SYS_SENSORS` and the ring-3 `sensors` command to cross-check the DTS
   and show whether the fans turn.  Nothing is written to the fan control.
   and show whether the fans turn.  Nothing is written to the fan control.
   `tpec.c/h` adds the ThinkPad embedded controller of the X201
   `tpec.c/h` adds the ThinkPad embedded controller of the X201
@@ -1365,14 +1396,36 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   malloc/free fragmented the first-fit heap until a page of 200 icons ran
   malloc/free fragmented the first-fit heap until a page of 200 icons ran
   out of memory.  A background image is scaled to cover its laid-out box
   out of memory.  A background image is scaled to cover its laid-out box
   (an icon is decoded at 56 px, not 1000), and up to 256 bitmaps within a
   (an icon is decoded at 56 px, not 1000), and up to 256 bitmaps within a
-  4 M-pixel budget (`BR_IMG_PIXEL_BUDGET`; 512 KB files / 8 MP decodes) are
+  4 M-pixel budget (`BR_IMG_PIXEL_BUDGET`; 1 MB files / 8 MP decodes) are
   kept until the page heap is reset.  Background images load lazily like
   kept until the page heap is reset.  Background images load lazily like
   `<img>` (measure-pass `block_top[]` against the scroll position), an
   `<img>` (measure-pass `block_top[]` against the scroll position), an
   image job holds a fetch helper for at most `BR_IMG_JOB_TIMEOUT_MS` (30 s),
   image job holds a fetch helper for at most `BR_IMG_JOB_TIMEOUT_MS` (30 s),
   in-flight nodes are marked `-3` so rescans skip them, and a script that
   in-flight nodes are marked `-3` so rescans skip them, and a script that
   sets `style`/`class`/`src` later (Angular `ng-style`) re-arms a node the
   sets `style`/`class`/`src` later (Angular `ng-style`) re-arms a node the
   first scan had marked empty; DOM changes from scripts trigger a rescan.
   first scan had marked empty; DOM changes from scripts trigger a rescan.
-  Rounded boxes paint their background image inside the corner arcs.  Navigation calls `heap_reset()` and unmaps the whole
+  Rounded boxes paint their background image inside the corner arcs.
+  Images with a CSS/attribute box decode at those bounds:
+  `img_options.max_w/h` lets the JPEG decoder choose a 1/2, 1/4 or 1/8
+  scaled IDCT (Loeffler/IGJ 4x4/2x2/1x1) instead of decoding full size and
+  then box-filtering to the 1000 px layout cap.  For remote `<img>` the warm
+  `curl __serve` helper does that decode (the request carries
+  `D <max_w> <max_h>` and the bitmap arrives as `/share/bf...px`), so the UI
+  thread only reads and copies it; local files and backgrounds still decode
+  in-process.  `<img>` uses its
+  CSS/attribute width/height (or the parent layout box for
+  `max-width:100%`), backgrounds use their box, so a 1200x800 photo painted
+  at 400x267 decodes at roughly 600x400 and is scaled once.  A per-image
+  display-size bitmap (`br_image.disp`) is built lazily from the capped
+  source and `img_draw`'s 1:1 opaque-copy and integer-alpha paths make later
+  paints memcpy.  Image-driven repaints are coalesced to 100 ms;
+  helper-decoded `<img>` jobs only copy their px file, while local and
+  background jobs decode in a 40 ms batch per main-loop pass, so a page
+  no longer does a full layout+paint per image; a background decode keeps
+  the measured layout (only `page_cache_valid` is cleared) and a decode
+  below the fold does not invalidate the screen.  At batch end the status
+  line and `/share/IMGSTAT` report wall, net (TLS), io, dec, scale, paint
+  and reflow totals plus one line per image.
+  Navigation calls `heap_reset()` and unmaps the whole
   arena, so a large image no longer reserves a fixed 24 MB.  `<script>`
   arena, so a large image no longer reserves a fixed 24 MB.  `<script>`
   blocks are collected by `browser_html.c`; inline bodies run directly and
   blocks are collected by `browser_html.c`; inline bodies run directly and
   `<script src>` bodies are fetched through the same local/network path as
   `<script src>` bodies are fetched through the same local/network path as
@@ -1559,12 +1612,22 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   API (`/api/me`, `/api/channels`, `/api/dms`, `/api/channels/public`,
   API (`/api/me`, `/api/channels`, `/api/dms`, `/api/channels/public`,
   `/api/users`, messages with `?limit=50`, `&before=` and `&after=`, POST
   `/api/users`, messages with `?limit=50`, `&before=` and `&after=`, POST
   messages with a `clientId`, `/read`, `/join`, `/api/dms`) through one
   messages with a `clientId`, `/read`, `/join`, `/api/dms`) through one
-  `struct uhttp` with a cookie jar.  Message images and avatars use the same
-  uhttp connection and cookie jar, are fetched one per main-loop pass, and
-  are decoded by the in-tree image library (PNG/JPEG/GIF first
-  frame/BMP/TGA/PNM/ICO/PAM).  They live in a 16-entry, 6 MB message-image
-  LRU plus a 64-entry avatar cache.  The fetch is capped at 4 MB and the
-  decoder at 4 MP / 12 MB of scratch.
+  `struct uhttp` with a cookie jar.  Message images and avatars are
+  downloaded by a warm `curl __serve` helper (one worker, dispatched from
+  `chat_media_tick()`; its DNS/TLS log lines go to a private tty), with the
+  chat cookie jar written to `/share/bchat.jar` as the helper's optional
+  jar-path argument.  The main loop only submits a request file and polls a
+  done marker, so the window no longer freezes for the download.  Message
+  images also carry `D 480 320`, so the helper decodes them and chat only
+  copies the published bitmap; avatars still decode on the chat thread at
+  32x32 (`img_options.max_w/h`), which keeps the square source the circular
+  mask expects while a large JPEG avatar gets a reduced IDCT instead of a
+  full 512x512 decode.  The in-tree image library (PNG/JPEG/GIF first
+  frame/BMP/TGA/PNM/ICO/PAM) is the fallback for both.  They live in a
+  16-entry, 6 MB message-image LRU plus a 64-entry avatar cache.  The fetch
+  is capped at 4 MB and the decoder at 4 MP / 12 MB of scratch.  The helper
+  is stopped when the window loses focus, so its TCP socket does not pause
+  the net-dev watcher.
 
 
   No WebSocket: the open conversation is polled every 2 s (5 s
   No WebSocket: the open conversation is polled every 2 s (5 s
   unfocused), the directory every 12 s (20 s), polling waits 1 s after
   unfocused), the directory every 12 s (20 s), polling waits 1 s after
@@ -1610,9 +1673,16 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   the LZ77 history, and one checksum pass at the end (the 3.7 MB pack went
   the LZ77 history, and one checksum pass at the end (the 3.7 MB pack went
   from ~1.1 s to ~0.25 s in QEMU).  The streaming API (`inflate_gzip`
   from ~1.1 s to ~0.25 s in QEMU).  The streaming API (`inflate_gzip`
   with a source/sink and progress hook) keeps the bit-at-a-time decoder.  `img_sniff()` is a
   with a source/sink and progress hook) keeps the bit-at-a-time decoder.  `img_sniff()` is a
-  cheap header probe; `img_decode()` returns `struct img_image`; `img_draw()`
+  cheap header probe; `img_decode()` returns `struct img_image`; its
+  `struct img_options` carries `max_pixels` and optional `max_w`/`max_h`
+  output bounds.  JPEG honours the bounds with a scaled IDCT (1/2 4x4,
+  1/4 2x2, 1/8 1x1, Loeffler/IGJ); other codecs ignore them and the caller
+  scales with `img_draw()`.  The 4x4/2x2 paths are validated by
+  `test_jpeg_scaled()` against a box-filtered full decode.  `img_draw()`
   is a clipped, scaled (box-filter down, bilinear up) RGB565 blit with alpha
   is a clipped, scaled (box-filter down, bilinear up) RGB565 blit with alpha
-  over a checkerboard or over the destination (for the browser and chat).  Progressive
+  over a checkerboard or over the destination (for the browser and chat),
+  with a straight row copy for a 1:1 opaque source and an integer 5/6/5
+  blend for a 1:1 alpha source.  Progressive
   JPEG (successive approximation), EXIF orientation, ICO/CUR, PAM, SVG
   JPEG (successive approximation), EXIF orientation, ICO/CUR, PAM, SVG
   files in the browser (an SVG body is parsed into a detached subtree of
   files in the browser (an SVG body is parsed into a detached subtree of
   the page and drawn by the inline-SVG renderer into an RGB565 + alpha
   the page and drawn by the inline-SVG renderer into an RGB565 + alpha
@@ -1623,7 +1693,8 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `SYS_READ_FILE`; it uses fit/1:1/zoom/pan, shows format/dimensions/size,
   `SYS_READ_FILE`; it uses fit/1:1/zoom/pan, shows format/dimensions/size,
   animates GIFs, and gives a clear error for unsupported variants.  The chat
   animates GIFs, and gives a clear error for unsupported variants.  The chat
   client decodes fetched message images and avatars into a 480x320 / 32x32
   client decodes fetched message images and avatars into a 480x320 / 32x32
-  cache and draws them with `img_draw()`.  Host
+  cache (passing those bounds to `img_options.max_w/h`) and draws them with
+  `img_draw()`.  Host
   tests: `make test-images` (`img_test.c`, corpus in `testdata/images/`,
   tests: `make test-images` (`img_test.c`, corpus in `testdata/images/`,
   generator `tools/gen_img_tests.py`).
   generator `tools/gen_img_tests.py`).
 - **Network service**: `sys_net.c/h` — the NIC and the stack stay in the
 - **Network service**: `sys_net.c/h` — the NIC and the stack stay in the
@@ -1892,7 +1963,14 @@ UHCI, OHCI and xHCI.  A machine with EHCI and UHCI/OHCI companions therefore
 enumerates high-speed devices on EHCI and low/full-speed devices on the
 enumerates high-speed devices on EHCI and low/full-speed devices on the
 companions; a port reset hands a non-high-speed device back to its companion
 companions; a port reset hands a non-high-speed device back to its companion
 before the companion is scanned.  A single device address is per-controller,
 before the companion is scanned.  A single device address is per-controller,
-so addresses do not collide.
+so addresses do not collide.  The first `SET_ADDRESS`/`GET_DESCRIPTOR` uses
+the USB default 8-byte EP0; the descriptor's real `bMaxPacketSize0` is
+adopted afterwards (a full-speed device may have an 8-byte EP0, and the old
+64-byte guess made the 970A's OHCI drop the mouse).  A failed port
+enumeration is retried up to three times with a fresh port reset and a
+20 ms settle, and the boot scan gives OHCI a second pass 60 ms after the
+EHCI-first walk, because the EHCI handback can leave a companion port
+briefly reporting disconnected.
 
 
 - **EHCI**: MMIO BAR0, page-allocated frame list/QH/qTD/bounce buffers, QH/
 - **EHCI**: MMIO BAR0, page-allocated frame list/QH/qTD/bounce buffers, QH/
   qTD descriptors in the identity-mapped kernel space.  Control, bulk and
   qTD descriptors in the identity-mapped kernel space.  Control, bulk and
@@ -1926,15 +2004,29 @@ so addresses do not collide.
   list (`HcControlHeadED` + CLF) and are polled via each TD's condition code
   list (`HcControlHeadED` + CLF) and are polled via each TD's condition code
   — a NAKed TD stays queued and is retried by the controller. Both HID EDs
   — a NAKed TD stays queued and is retried by the controller. Both HID EDs
   (F = 0) are chained and referenced from all 32 HCCA interrupt-table slots,
   (F = 0) are chained and referenced from all 32 HCCA interrupt-table slots,
-  so their TDs are serviced every frame. No IRQs and no DoneHead handling:
-  software just harvests retired TDs. **TDs must be initialized with
+  so their TDs are serviced every frame. No IRQs: software harvests retired
+  TDs and acknowledges `WDH` (`HcInterruptStatus` + HCCA DoneHead) each pass.
+  The ED/TD/setup and interrupt-buffer structures live in the dedicated
+  `ohci_dma_page`, mapped uncacheable by `paging_init()` (PDE 0 is split
+  before paging is enabled).  The SB950's legacy OHCI DMA does not snoop
+  dirty CPU lines: without the uncached page the controller sometimes read
+  an empty ED, skipped the transfer and never re-armed the endpoint (the
+  mouse cursor froze with no error).  Control transfers still use `wbinvd`
+  around their caller-supplied data buffers, which remain write-back.
+  **TDs must be initialized with
   CC = NotAccessed (0xF)** — OHCI has no active bit, and a zero CC makes
   CC = NotAccessed (0xF)** — OHCI has no active bit, and a zero CC makes
   software think a fresh TD already completed. TD data toggles are explicit:
   software think a fresh TD already completed. TD data toggles are explicit:
   DATA0 = `0x02000000`, DATA1 = `0x03000000` (`0` means "use the ED carry
   DATA0 = `0x02000000`, DATA1 = `0x03000000` (`0` means "use the ED carry
   bit"); a wrong value makes the first control transfer fail with a toggle
   bit"); a wrong value makes the first control transfer fail with a toggle
   mismatch on real hardware while QEMU (which ignores toggles) is happy.
   mismatch on real hardware while QEMU (which ignores toggles) is happy.
   Control queues use a dummy TD as the tail anchor; the data stage is one
   Control queues use a dummy TD as the tail anchor; the data stage is one
-  TD (the controller splits it into MPS-sized packets itself).
+  TD (the controller splits it into MPS-sized packets itself).  Before the
+  first reset, if `HcControl.IR` says the SMM owns the controller, the driver
+  requests ownership (`HcCommandStatus.OCR`, clear `HcControl.IR`) with a
+  bounded 200 ms wait.  On AMD SB600/SB700/SB800/SB950 it also clears the
+  southbridge USB SMI enable (SMBus device `1002:4385`, config `0x64` bit
+  15) once, so the firmware cannot take the OHCI ports back after handoff.
+  Both are no-ops on Intel/QEMU.
 - **UHCI**: I/O ports, frame list at `0x3000`, control QH + two more QHs
 - **UHCI**: I/O ports, frame list at `0x3000`, control QH + two more QHs
   (one per interrupt slot) serviced every frame while the controller keeps
   (one per interrupt slot) serviced every frame while the controller keeps
   running. The PCI scan checks **all functions** (real PIIX3/PIIX4/VIA
   running. The PCI scan checks **all functions** (real PIIX3/PIIX4/VIA
@@ -2013,10 +2105,15 @@ so addresses do not collide.
   (500 ms delay, 33 ms rate) for the last make code; real PS/2 hardware
   (500 ms delay, 33 ms rate) for the last make code; real PS/2 hardware
   repeat keeps resetting the same timer.
   repeat keeps resetting the same timer.
   `usbhid_poll()` (from `mouse_poll_update()`) also runs the hotplug
   `usbhid_poll()` (from `mouse_poll_update()`) also runs the hotplug
-  watcher: root-port connect changes are enumerated (throttled to 250 ms),
-  `CCS` low or a few TD errors detach a device.  A full scan (`lsusb`) bumps
-  `usb_generation()`, which makes `usbhid` detach and rescan, so `lsusb`
-  can't leave the devices dead.  The BIOS PS/2 legacy emulation is
+  watcher: root-port connect changes are enumerated (throttled to 250 ms).
+  A port read must report disconnected three times in a row before the
+  device is detached, and the TD error threshold is 50, so a single CCS
+  glitch or a short low-speed error burst cannot kill a working device.
+  Any detach sets `need_rescan`, which runs a clean full `usb_scan` from the
+  watcher: a false port-loss leaves no CSC to wake the per-port path, so
+  this is the only reliable recovery on the SB950.  A full scan (`lsusb`)
+  also bumps `usb_generation()`, which makes `usbhid` detach and rescan, so
+  `lsusb` can't leave the devices dead.  The BIOS PS/2 legacy emulation is
   deliberately disabled (PCI config `0xC0`) because the kernel now owns
   deliberately disabled (PCI config `0xC0`) because the kernel now owns
   these devices.
   these devices.
 - **Debug**: `ohci:` / `uhci:` / `ehci:` / `usbhid:` lines go to COM1 (and
 - **Debug**: `ohci:` / `uhci:` / `ehci:` / `usbhid:` lines go to COM1 (and
@@ -2186,8 +2283,14 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
 
 
 ## Known issues (candidates for future tasks)
 ## Known issues (candidates for future tasks)
 
 
-1. `serial_puthex` (`serial.c`) uses `"01234589ABCDEF"` — digits **6 and 7 are
-   missing** (bug).
+1. `power.c` still has no AMD P-state path.  The FX-6350 (family 15h model 2)
+   runs at the BIOS P0 and `power`/`cpufreq` report unsupported; the CPU
+   temperature is supported through `D18F3xA4`.  A minimal family-15h
+   governor would read `MSRC001_0064..006B` (COF = `100 * (FID + 0x10) >>
+   DID`) and write the 3-bit index to `MSRC001_0062`, but it is not required
+   for boot or the desktop.  The AMD WC MTRR path is supported through the
+   separate free-entry/zero-high-mask path described above; the Intel/ION WC
+   paths are unchanged.
 2. `vga.c` `draw_flush_debug_square()` — leftover debug artifact, still draws a
 2. `vga.c` `draw_flush_debug_square()` — leftover debug artifact, still draws a
    color-cycling 32×32 square in the corner on every flush.
    color-cycling 32×32 square in the corner on every flush.
 3. No per-process address spaces or process isolation (paging is identity-mapped).
 3. No per-process address spaces or process isolation (paging is identity-mapped).
@@ -2222,8 +2325,11 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     board that exposes only MP tables stays UP (deliberate; there is no test
     board that exposes only MP tables stays UP (deliberate; there is no test
     hardware).
     hardware).
 10. There is no IOAPIC driver.  The BSP keeps the 8259 PIC in LAPIC ExtINT mode;
 10. There is no IOAPIC driver.  The BSP keeps the 8259 PIC in LAPIC ExtINT mode;
-    APs mask LINT0/LINT1 and only use their LAPIC timer/IPIs.  Device IRQs never
-    reach an AP, and `pit_irq_stub` should be treated as BSP-only.
+    after ACPI init, `ioapic_mask_all()` masks every normal IOAPIC redirection
+    entry (ExtINT entries are left alone in case the 8259 is routed through an
+    IOAPIC pin).  APs mask LINT0/LINT1 and only use their LAPIC timer/IPIs.
+    Device IRQs never reach an AP, and `pit_irq_stub` should be treated as
+    BSP-only.
 11. The BKL serializes all kernel execution: a long FAT/disk operation, a
 11. The BKL serializes all kernel execution: a long FAT/disk operation, a
     non-network driver wait or a big shadow-buffer operation can stall syscalls
     non-network driver wait or a big shadow-buffer operation can stall syscalls
     on the other CPUs for its duration.  `bkl_pause()`/`bkl_resume()` is used
     on the other CPUs for its duration.  `bkl_pause()`/`bkl_resume()` is used
@@ -2243,10 +2349,15 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     whole file is read into memory (4 MB cap in the viewer) and very large
     whole file is read into memory (4 MB cap in the viewer) and very large
     photos still need DCT-scaled/streamed decode before they fit the 64 MB
     photos still need DCT-scaled/streamed decode before they fit the 64 MB
     arena.
     arena.
-15. `img_draw()`'s box-filter downscale runs on the CPU.  It is fine for the
-    viewer's static frames, but a browser showing many large inline images
-    should cache a scaled bitmap (or use decode-at-display-scale) instead of
-    rescaling on every repaint.
+15. `img_draw()`'s box-filter downscale runs on the CPU.  The browser now
+    caches a display-size bitmap per image (`br_image.disp`) and paints 1:1;
+    remote `<img>` decodes in the warm `curl __serve` helper at the CSS box
+    (the UI only reads the published RGB565+alpha bitmap), so the UI thread
+    no longer runs the IDCT.  Local images and backgrounds still decode
+    in-process; the viewer caches one image at its window size, and chat
+    caches 480x320/32x32 bitmaps.  The in-process paths are still limited by
+    the full-size `img_estimate()` arena (24 MB browser, 12 MB chat), so an
+    image above the arena cap is rejected before the reduced decode runs.
 16. `files` recognises images by file extension only (`.png .jpg .jpeg .gif
 16. `files` recognises images by file extension only (`.png .jpg .jpeg .gif
     .bmp .tga .ppm .pgm .pbm .ico .cur .pam`); a magic-based fallback would
     .bmp .tga .ppm .pgm .pbm .ico .cur .pam`); a magic-based fallback would
     also open extensionless files in the viewer.  Automatic decode-at-scale
     also open extensionless files in the viewer.  Automatic decode-at-scale
@@ -2275,9 +2386,10 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     (8 slots x 1 KB), and the FAT listing cache another 5 KB.  The command
     (8 slots x 1 KB), and the FAT listing cache another 5 KB.  The command
     pack is out of the kernel now; after the WiFi/netmenu/install code and the
     pack is out of the kernel now; after the WiFi/netmenu/install code and the
     per-connection TCP queues moved to the frame allocator, `_end` is
     per-connection TCP queues moved to the frame allocator, `_end` is
-    ~0x897a0 (with the 6200/6300 DVM layer, the RTL8821AU driver and the
-    8×16 boot-console font), ~26 KB below the `0x90000` wall, and the
-    remaining limit is kernel code/buffers only.
+    ~0x8a440 (with the 6200/6300 DVM layer, the RTL8821AU driver, the
+    8×16 boot-console font, the IOAPIC/AMD-thermal additions and the safe
+    AMD MTRR path), ~23 KB below the `0x90000` wall, and the remaining limit
+    is kernel code/buffers only.
 
 
 22. Browser limits: JavaScript runs inline and external classic scripts on
 22. Browser limits: JavaScript runs inline and external classic scripts on
     QuickJS (ES2025) with the DOM surface described above (creation/mutation/selectors/
     QuickJS (ES2025) with the DOM surface described above (creation/mutation/selectors/
@@ -2372,12 +2484,20 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     the installed faces, and the `font` shorthand does not resolve a custom
     the installed faces, and the `font` shorthand does not resolve a custom
     family (use `font-family`).
     family (use `font-family`).
     Pages that need multi-row grid templates, `color-mix()` or full
     Pages that need multi-row grid templates, `color-mix()` or full
-    transforms can still lay out imperfectly.  Images are decoded into a per-image `img_estimate()`-sized
-    arena (reused per page) and kept as a box-sized display bitmap (256
-    images within a 4 M-pixel budget, 512 KB files / 8 MP decodes); large
-    screenshots still need a multi-megabyte decode arena that can fail on a
-    fragmented heap, and the scaled bitmaps live until navigation.  `img_draw` rescales the
-    cached bitmap on every repaint.  Lazy
+    transforms can still lay out imperfectly.  Remote `<img>` decodes in the
+    fetch helper at its CSS/attribute box (the helper request carries
+    `D <max_w> <max_h>` and publishes an RGB565+alpha bitmap), so the UI
+    only reads it; local images and backgrounds use a per-image
+    `img_estimate()`-sized arena in-process (`<img>` passes its box through
+    `img_options.max_w/h`, backgrounds decode at their box), and the browser
+    keeps a lazily built display-size bitmap (`br_image.disp`) for 1:1
+    repaints (256 source images within a 4 M-pixel budget plus a 6 M-pixel
+    display-cache budget, 1 MB files / 8 MP decodes).  The in-process
+    paths still size the arena for the full image, so a very large local or
+    background photo can fail the 24 MB cap before the reduced decode runs;
+    the scaled bitmaps live until navigation.  Image repaints are coalesced
+    (100 ms) and jobs decode in 40 ms batches; `/share/IMGSTAT` records
+    net/io/dec/scale/paint/reflow.  Lazy
     image loading uses the last measured positions; adding an image can
     image loading uses the last measured positions; adding an image can
     reflow the content above it, and images below the viewport stay as
     reflow the content above it, and images below the viewport stay as
     `[image]` until scrolled into range.  The browser keeps up to four
     `[image]` until scrolled into range.  The browser keeps up to four
@@ -2401,18 +2521,23 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
 
 
 23. UEFI boot is x86-64 firmware only (no `BOOTIA32.EFI` yet) and the loader
 23. UEFI boot is x86-64 firmware only (no `BOOTIA32.EFI` yet) and the loader
     is unsigned, so Secure Boot must be off.  The loader needs a GOP mode with
     is unsigned, so Secure Boot must be off.  The loader needs a GOP mode with
-    BGRX or RGBX 32bpp, width ≤ 1280, `pitch * height` ≤ 8 MB and the
-    framebuffer below 4 GB; otherwise the kernel starts headless (serial only).
+    BGRX or RGBX 32bpp, width ≤ 1920, `pitch * height` ≤ 8 MB (1920x1080
+    fits at 8.29 MB) and the framebuffer below 4 GB; otherwise the kernel
+    starts headless (serial only).  The same 2 M-pixel cap keeps a
+    full-screen RGB565 canvas inside the 4 MB window slot.
     xHCI drives USB2 and USB3 root ports (USB3 hubs are not decoded), and
     xHCI drives USB2 and USB3 root ports (USB3 hubs are not decoded), and
     EHCI only high-speed root ports (no transaction translator for
     EHCI only high-speed root ports (no transaction translator for
     low/full-speed devices behind a high-speed hub), so a full-speed device
     low/full-speed devices behind a high-speed hub), so a full-speed device
     behind a USB2 hub can still leave the UI without input (PS/2 may still
     behind a USB2 hub can still leave the UI without input (PS/2 may still
     work).
     work).
-    There is no IOAPIC setup: OVMF delivers the ISA IRQs through the 8259
-    path, but a platform that routes them through the IOAPIC may need a
-    mask-all step after ACPI init.  UEFI runtime services are not used, so
+    OVMF delivers the ISA IRQs through the 8259 path; the kernel nevertheless
+    masks the IOAPIC's normal redirection entries after ACPI init, so
+    firmware-left vectors cannot collide with the PIC or LAPIC timer.
+    UEFI runtime services are not used, so
     `reboot`/`poweroff` still use the legacy ports.  The image is 17 MB: the
     `reboot`/`poweroff` still use the legacy ports.  The image is 17 MB: the
-    9 MB kernel + rootfs disk and the 8 MB ESP.
+    9 MB kernel + rootfs disk and the 8 MB ESP.  Maxwell GPUs such as the
+    GTX 960 use the firmware VBE/GOP framebuffer only; there is no native
+    NVIDIA driver, and `nv50_probe()` is gated to the ION/nv50 chipsets.
 
 
 24. ThinkPad EC sensor and battery access (`tpec.c`) runs in legacy/SMM mode
 24. ThinkPad EC sensor and battery access (`tpec.c`) runs in legacy/SMM mode
     because there is no ACPI interpreter: an SMI that touches the EC between
     because there is no ACPI interpreter: an SMI that touches the EC between
@@ -2553,7 +2678,10 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     render inline up to the 4 MB fetch / 4 MP decode caps (first GIF frame;
     render inline up to the 4 MB fetch / 4 MP decode caps (first GIF frame;
     WebP/AVIF/SVG are not decoded), file attachments are still text-only,
     WebP/AVIF/SVG are not decoded), file attachments are still text-only,
     messages over 4 KB are truncated, history holds 240 messages, times are
     messages over 4 KB are truncated, history holds 240 messages, times are
-    UTC and text is Latin-1.  Network calls block the UI for their duration.
+    UTC and text is Latin-1.  REST calls still block the UI for their
+    duration; message images decode in the `curl __serve` helper (480x320
+    bounds) and chat only copies the bitmap, while avatars decode on the
+    chat thread at 32x32.
 
 
 35. WiFi limits (`iwl_trans.c`, `iwl_mvm.c`, `iwl_dvm.c`, `wifi.c`): Intel
 35. WiFi limits (`iwl_trans.c`, `iwl_mvm.c`, `iwl_dvm.c`, `wifi.c`): Intel
     7265 rev D/3165 (`iwlwifi-7265D-29`) and 6200/6300 (`iwlwifi-6000-4`)
     7265 rev D/3165 (`iwlwifi-7265D-29`) and 6200/6300 (`iwlwifi-6000-4`)

Разница между файлами не показана из-за своего большого размера
+ 37 - 6
Makefile


+ 24 - 0
acpi.c

@@ -43,6 +43,8 @@ static unsigned int ids[ACPI_MAX_CPUS];
 static unsigned int ncpu;
 static unsigned int ncpu;
 static unsigned int bsp_apic;
 static unsigned int bsp_apic;
 static unsigned int lapic_base;
 static unsigned int lapic_base;
+static unsigned int ioapic_bases[ACPI_MAX_IOAPICS];
+static unsigned int nioapics;
 static int acpi_ok;
 static int acpi_ok;
 /* FADT "century" register (offset 108), 0 when absent.  The RTC uses it to
 /* FADT "century" register (offset 108), 0 when absent.  The RTC uses it to
  * keep the two-digit CMOS year in the right century; rtc.c only writes it
  * keep the two-digit CMOS year in the right century; rtc.c only writes it
@@ -256,6 +258,12 @@ static void parse_madt(const struct acpi_sdt *madt)
 			/* Processor Local APIC: flags bit 0 = enabled. */
 			/* Processor Local APIC: flags bit 0 = enabled. */
 			if ((p[i + 4] & 1) && ncpu < ACPI_MAX_CPUS)
 			if ((p[i + 4] & 1) && ncpu < ACPI_MAX_CPUS)
 				ids[ncpu++] = p[i + 3];
 				ids[ncpu++] = p[i + 3];
+		} else if (type == 1 && elen >= 12) {
+			/* I/O APIC: id, 32-bit MMIO base, GSI base. */
+			unsigned int base = *(const unsigned int *)(p + i + 4);
+
+			if (base && nioapics < ACPI_MAX_IOAPICS)
+				ioapic_bases[nioapics++] = base;
 		} else if (type == 5 && elen >= 12) {
 		} else if (type == 5 && elen >= 12) {
 			/* Local APIC Address Override (64-bit). */
 			/* Local APIC Address Override (64-bit). */
 			unsigned int lo = *(const unsigned int *)(p + i + 4);
 			unsigned int lo = *(const unsigned int *)(p + i + 4);
@@ -277,6 +285,7 @@ int acpi_init(void)
 
 
 	acpi_ok = 0;
 	acpi_ok = 0;
 	ncpu = 0;
 	ncpu = 0;
+	nioapics = 0;
 	rtc_century_reg = 0;
 	rtc_century_reg = 0;
 	bsp_apic = cpuid_apic_id();
 	bsp_apic = cpuid_apic_id();
 	if (bsp_apic == 0xFFFFFFFFu)
 	if (bsp_apic == 0xFFFFFFFFu)
@@ -333,6 +342,16 @@ unsigned int acpi_lapic_base(void)
 	return lapic_base;
 	return lapic_base;
 }
 }
 
 
+unsigned int acpi_ioapic_count(void)
+{
+	return acpi_ok ? nioapics : 0;
+}
+
+unsigned int acpi_ioapic_base(unsigned int index)
+{
+	return (acpi_ok && index < nioapics) ? ioapic_bases[index] : 0;
+}
+
 unsigned int acpi_rtc_century_reg(void)
 unsigned int acpi_rtc_century_reg(void)
 {
 {
 	return rtc_century_reg;
 	return rtc_century_reg;
@@ -356,4 +375,9 @@ void acpi_dump(void)
 		serial_putdec(SERIAL_COM1, ids[i]);
 		serial_putdec(SERIAL_COM1, ids[i]);
 	}
 	}
 	serial_puts(SERIAL_COM1, "\n");
 	serial_puts(SERIAL_COM1, "\n");
+	for (i = 0; i < nioapics; i++) {
+		serial_puts(SERIAL_COM1, "acpi: ioapic ");
+		serial_puthex(SERIAL_COM1, ioapic_bases[i]);
+		serial_puts(SERIAL_COM1, "\n");
+	}
 }
 }

+ 3 - 0
acpi.h

@@ -7,6 +7,7 @@
 #define ACPI_H
 #define ACPI_H
 
 
 #define ACPI_MAX_CPUS 8
 #define ACPI_MAX_CPUS 8
+#define ACPI_MAX_IOAPICS 4
 
 
 /* Returns 1 when a usable MADT with at least one local APIC entry was found.
 /* Returns 1 when a usable MADT with at least one local APIC entry was found.
  * acpi_cpu_count() then includes the BSP as entry 0. */
  * acpi_cpu_count() then includes the BSP as entry 0. */
@@ -16,6 +17,8 @@ unsigned int acpi_cpu_count(void);
 unsigned int acpi_cpu_apic_id(unsigned int index);
 unsigned int acpi_cpu_apic_id(unsigned int index);
 unsigned int acpi_bsp_apic_id(void);
 unsigned int acpi_bsp_apic_id(void);
 unsigned int acpi_lapic_base(void);
 unsigned int acpi_lapic_base(void);
+unsigned int acpi_ioapic_count(void);
+unsigned int acpi_ioapic_base(unsigned int index);
 
 
 /* CMOS register holding the RTC century byte from the FADT, or 0 when the
 /* CMOS register holding the RTC century byte from the FADT, or 0 when the
  * firmware does not provide one (old non-ACPI hardware). */
  * firmware does not provide one (old non-ACPI hardware). */

+ 2 - 2
docs/boot.html

@@ -171,7 +171,7 @@
 			<li>Probe the <code>INT 15h</code> E820 memory map into <code>0x1000</code>.</li>
 			<li>Probe the <code>INT 15h</code> E820 memory map into <code>0x1000</code>.</li>
 			<li>Enable A20 and read the <code>NBROOT1</code> rootfs header at the boot sector's <code>pack_lba</code> field.</li>
 			<li>Enable A20 and read the <code>NBROOT1</code> rootfs header at the boot sector's <code>pack_lba</code> field.</li>
 			<li>Copy the compressed pack directly to <code>0x900000</code> above the 8 MB VGA-shadow reserve, in 16 KB staging chunks at <code>0x3000</code> (one <code>INT 13h</code> per chunk: 32 sectors over EDD, or up to the end of the track over CHS, which never crosses a 64 KB DMA boundary; a BIOS that refuses a multi-sector request falls back to one sector per call), using a temporary flat protected-mode <code>rep movsb</code>. The X201 BIOS's <code>INT 15h AH=87h</code> block move silently copies zeros to this range, so the CPU copy is used instead.</li>
 			<li>Copy the compressed pack directly to <code>0x900000</code> above the 8 MB VGA-shadow reserve, in 16 KB staging chunks at <code>0x3000</code> (one <code>INT 13h</code> per chunk: 32 sectors over EDD, or up to the end of the track over CHS, which never crosses a 64 KB DMA boundary; a BIOS that refuses a multi-sector request falls back to one sector per call), using a temporary flat protected-mode <code>rep movsb</code>. The X201 BIOS's <code>INT 15h AH=87h</code> block move silently copies zeros to this range, so the CPU copy is used instead.</li>
-			<li>Pick the best VBE mode: at least 16 bpp, a linear framebuffer, it must fit the card's VRAM, and the width must be at most 1280 pixels. Mode information is written to <code>0x600</code>; the 12-dword boot-info block goes to <code>0x500</code>.</li>
+			<li>Pick the best VBE mode: at least 16 bpp, a linear framebuffer, it must fit the card's VRAM, at most 1920 pixels wide, its pitch × height must fit the 8 MB VGA-shadow reserve, and it must stay within 2 M pixels so a full-screen RGB565 canvas fits the 4 MB window slot. Mode information is written to <code>0x600</code>; the 12-dword boot-info block goes to <code>0x500</code>.</li>
 			<li>Enter protected mode and jump to <code>kernel_entry</code>.</li>
 			<li>Enter protected mode and jump to <code>kernel_entry</code>.</li>
 		</ol>
 		</ol>
 		<p>
 		<p>
@@ -204,7 +204,7 @@
 			not execute any of the legacy boot chain. Instead it:
 			not execute any of the legacy boot chain. Instead it:
 		</p>
 		</p>
 		<ol>
 		<ol>
-			<li>Selects a GOP mode with BGRX or RGBX 32bpp, width at most 1280, <code>pitch × height</code> at most 8 MB, and a framebuffer below 4 GB.</li>
+			<li>Selects a GOP mode with BGRX or RGBX 32bpp, width at most 1920, <code>pitch × height</code> at most 8 MB (1920×1080 fits at 8.29 MB), and a framebuffer below 4 GB. With 32bpp, that size limit also keeps a full-screen RGB565 canvas inside the 4 MB window slot; the VBE stage additionally checks 2 M pixels because a 24bpp 1920×1200 mode would otherwise pass the shadow check.</li>
 			<li>Calls <code>GetMemoryMap</code> and converts the firmware map into the kernel's E820 format at <code>0x1000</code>.</li>
 			<li>Calls <code>GetMemoryMap</code> and converts the firmware map into the kernel's E820 format at <code>0x1000</code>.</li>
 			<li>Locates the parent whole-disk Block I/O handle from the ESP device path, reads the P1 boot sector and P2 <code>NBROOT1</code> header, and stages the kernel below 4 GB and the gzip pack below the 512 MB identity window. The kernel/pack embedded in <code>BOOTX64.EFI</code> are a fallback only.</li>
 			<li>Locates the parent whole-disk Block I/O handle from the ESP device path, reads the P1 boot sector and P2 <code>NBROOT1</code> header, and stages the kernel below 4 GB and the gzip pack below the 512 MB identity window. The kernel/pack embedded in <code>BOOTX64.EFI</code> are a fallback only.</li>
 			<li>Writes the boot-info and framebuffer blocks, calls <code>ExitBootServices</code>, then copies a 192-byte trampoline to <code>0x800</code>.</li>
 			<li>Writes the boot-info and framebuffer blocks, calls <code>ExitBootServices</code>, then copies a 192-byte trampoline to <code>0x800</code>.</li>

+ 17 - 11
docs/cpu.html

@@ -4,7 +4,7 @@
 <meta charset="utf-8">
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title>CPU &amp; Scheduling | NebOS Architecture</title>
 <title>CPU &amp; Scheduling | NebOS Architecture</title>
-<meta name="description" content="NebOS CPU architecture: GDT/TSS, PIC/PIT and LAPIC interrupts, ACPI SMP bring-up, CFS-lite scheduling, wait queues, the big kernel lock, idle and power management.">
+<meta name="description" content="NebOS CPU architecture: GDT/TSS, PIC/PIT and LAPIC interrupts, IOAPIC masking, ACPI SMP bring-up, CFS-lite scheduling, wait queues, the big kernel lock, idle, power and AMD/Intel thermal management.">
 <link rel="icon" href="favicon.svg" type="image/svg+xml">
 <link rel="icon" href="favicon.svg" type="image/svg+xml">
 <link rel="stylesheet" href="style.css">
 <link rel="stylesheet" href="style.css">
 </head>
 </head>
@@ -81,9 +81,12 @@
 	<section id="interrupts">
 	<section id="interrupts">
 		<h2>Interrupts &amp; timers</h2>
 		<h2>Interrupts &amp; timers</h2>
 		<p>
 		<p>
-			The BSP keeps the legacy 8259 PIC and PIT. Device IRQs stay on the
-			BSP because there is no IOAPIC driver. APs mask their LINT0/LINT1
-			inputs and use only their local APIC timer and IPIs.
+			The BSP keeps the legacy 8259 PIC and PIT; there is no IOAPIC
+			driver. After ACPI init the kernel masks every normal IOAPIC
+			redirection entry (leaving ExtINT entries alone, in case the 8259
+			is routed through an IOAPIC pin), so firmware-left vectors cannot
+			collide with the PIC vectors or the LAPIC timer. APs mask their
+			LINT0/LINT1 inputs and use only their local APIC timer and IPIs.
 		</p>
 		</p>
 		<div class="table-wrap">
 		<div class="table-wrap">
 			<table>
 			<table>
@@ -169,9 +172,12 @@
 			drawing fast paths would <code>#UD</code>.
 			drawing fast paths would <code>#UD</code>.
 		</p>
 		</p>
 		<div class="warn">
 		<div class="warn">
-			<p><strong>No IOAPIC.</strong> Device IRQs never reach an AP, and
-			<code>pit_irq_stub</code> is BSP-only. A platform that routes ISA IRQs
-			through the IOAPIC would need a mask-all setup step after ACPI init.</p>
+			<p><strong>No IOAPIC driver.</strong> Device IRQs never reach an AP,
+			and <code>pit_irq_stub</code> is BSP-only. The kernel masks the
+			IOAPIC's normal redirection entries after ACPI init
+			(<span class="file">ioapic.c</span>) and keeps the 8259 path on
+			LAPIC LINT0; ExtINT entries survive so firmware that routes the
+			8259 through an IOAPIC pin still works.</p>
 		</div>
 		</div>
 	</section>
 	</section>
 
 
@@ -349,8 +355,8 @@
 			<li><strong>Nehalem/Westmere P-states.</strong> <code>power_init</code> enables SpeedStep, raises the package C-state limit to C6 when unlocked, reads min/max ratios from <code>PLATFORM_INFO</code> and starts at the maximum non-turbo ratio. The target ratio goes in bits 15:8 of <code>IA32_PERF_CTL</code> with the low byte zero.</li>
 			<li><strong>Nehalem/Westmere P-states.</strong> <code>power_init</code> enables SpeedStep, raises the package C-state limit to C6 when unlocked, reads min/max ratios from <code>PLATFORM_INFO</code> and starts at the maximum non-turbo ratio. The target ratio goes in bits 15:8 of <code>IA32_PERF_CTL</code> with the low byte zero.</li>
 			<li><strong>Airmont/Braswell P-states.</strong> Family 6 model <code>0x4C</code> reads the Atom ratio/VID MSRs (<code>0x66A..0x66D</code>), <code>MSR_FSB_FREQ</code> and the FSB table. The N3060 reports pstates 6..20, BCLK 80 MHz (1600 MHz nominal), turbo pstate 31 (2480 MHz) and VID 0x2D..0x3C. <code>power_init</code> enters at max non-turbo and the governor drops to pstate 6 (480 MHz); <code>IA32_PERF_CTL</code> carries the pstate in 15:8 and the Linux-interpolated VID in 7:0. Turbo is detected but not requested. The probe deliberately avoids package/power-SKU MSRs; an unsupported <code>rdmsr</code> before the IDT triple-faults.</li>
 			<li><strong>Airmont/Braswell P-states.</strong> Family 6 model <code>0x4C</code> reads the Atom ratio/VID MSRs (<code>0x66A..0x66D</code>), <code>MSR_FSB_FREQ</code> and the FSB table. The N3060 reports pstates 6..20, BCLK 80 MHz (1600 MHz nominal), turbo pstate 31 (2480 MHz) and VID 0x2D..0x3C. <code>power_init</code> enters at max non-turbo and the governor drops to pstate 6 (480 MHz); <code>IA32_PERF_CTL</code> carries the pstate in 15:8 and the Linux-interpolated VID in 7:0. Turbo is detected but not requested. The probe deliberately avoids package/power-SKU MSRs; an unsupported <code>rdmsr</code> before the IDT triple-faults.</li>
 			<li><strong>Governor.</strong> A 100 ms window picks min/max/linear target pstates; short busy streaks jump to max immediately. Each CPU writes its own <code>IA32_PERF_CTL</code>; <code>cpufreq [auto|min|max|off|&lt;pstate&gt;]</code> overrides it, and <code>SYS_CPUFREQ</code> exposes the same auto/min/max/off mode to the control panel's Power mode tile.</li>
 			<li><strong>Governor.</strong> A 100 ms window picks min/max/linear target pstates; short busy streaks jump to max immediately. Each CPU writes its own <code>IA32_PERF_CTL</code>; <code>cpufreq [auto|min|max|off|&lt;pstate&gt;]</code> overrides it, and <code>SYS_CPUFREQ</code> exposes the same auto/min/max/off mode to the control panel's Power mode tile.</li>
-			<li><strong>Telemetry.</strong> <code>power</code> prints effective MHz from APERF/MPERF, the current/requested pstate and, on Airmont, the FSB, nominal MHz, turbo pstate/VID, VID range and live <code>PERF_CTL</code>; <code>sensors</code> prints DTS, board sensors and both EC types; <code>powerinfo</code> prints the AC adapter and battery state, and the WM top bar shows the temperature plus a far-right AC plug or level-filled battery icon (percentage tooltip below it on hover) on ThinkPads and Chromebooks.</li>
-			<li><strong>Thermal.</strong> Each CPU samples its DTS once a second from its scheduler tick; the hottest core is exposed to ring 3. TjMax comes from <code>IA32_TEMPERATURE_TARGET</code> on Nehalem/Westmere, the coretemp 90 °C table on Airmont, and the Bonnell table on older Atoms.</li>
+			<li><strong>Telemetry.</strong> <code>power</code> prints effective MHz from APERF/MPERF, the current/requested pstate and, on Airmont, the FSB, nominal MHz, turbo pstate/VID, VID range and live <code>PERF_CTL</code>; <code>sensors</code> prints the CPU temperature, board sensors and both EC types; <code>powerinfo</code> prints the AC adapter and battery state, and the WM top bar shows the temperature plus a far-right AC plug or level-filled battery icon (percentage tooltip below it on hover) on ThinkPads and Chromebooks.</li>
+			<li><strong>Thermal.</strong> On Intel, each CPU samples its DTS once a second from its scheduler tick; the hottest core is exposed to ring 3. TjMax comes from <code>IA32_TEMPERATURE_TARGET</code> on Nehalem/Westmere, the coretemp 90 °C table on Airmont, and the Bonnell table on older Atoms. On AMD family 15h models below <code>0x60</code> (Bulldozer/Piledriver/Steamroller), <span class="file">thermal.c</span> reads the package Tctl from <code>D18F3xA4</code> at PCI <code>0:18.3</code> (k10temp's <code>(raw × 125) m°C</code>, with the 49 °C range offset when bits 17:16 are both set) and publishes it to every CPU from the kworker under the BKL; PCI config space is deliberately not touched from the per-CPU timer interrupt.</li>
 			<li><strong>Limits.</strong> Package C-states/S0ix remain firmware-managed; Airmont reports no C3/C6 residency and does not request the turbo pstate. The explicit <code>idle c6</code> override is the Nehalem <code>0x20</code> hint; use <code>idle auto</code> for the Airmont C6N (<code>0x58</code>) path.</li>
 			<li><strong>Limits.</strong> Package C-states/S0ix remain firmware-managed; Airmont reports no C3/C6 residency and does not request the turbo pstate. The explicit <code>idle c6</code> override is the Nehalem <code>0x20</code> hint; use <code>idle auto</code> for the Airmont C6N (<code>0x58</code>) path.</li>
 		</ul>
 		</ul>
 	</section>
 	</section>
@@ -362,10 +368,10 @@
 			<li><code>process.c</code>, <code>process.h</code> — PCBs and lifecycle</li>
 			<li><code>process.c</code>, <code>process.h</code> — PCBs and lifecycle</li>
 			<li><code>switch.S</code> — context switch</li>
 			<li><code>switch.S</code> — context switch</li>
 			<li><code>tss.c</code>, <code>tss.h</code> — per-CPU TSS</li>
 			<li><code>tss.c</code>, <code>tss.h</code> — per-CPU TSS</li>
-			<li><code>acpi.c</code>, <code>lapic.c</code>, <code>smp.c</code> — SMP</li>
+			<li><code>acpi.c</code>, <code>ioapic.c</code>, <code>lapic.c</code>, <code>smp.c</code> — SMP and IOAPIC masking</li>
 			<li><code>ap_tramp.S</code> — AP startup blob</li>
 			<li><code>ap_tramp.S</code> — AP startup blob</li>
 			<li><code>timer.S</code>, <code>idle.c</code>, <code>power.c</code></li>
 			<li><code>timer.S</code>, <code>idle.c</code>, <code>power.c</code></li>
-			<li><code>thermal.c</code> — DTS sampling</li>
+			<li><code>thermal.c</code> — Intel DTS and AMD D18F3xA4 sampling</li>
 			<li><code>spinlock.h</code> — IRQ-safe spinlocks</li>
 			<li><code>spinlock.h</code> — IRQ-safe spinlocks</li>
 		</ul>
 		</ul>
 	</section>
 	</section>

+ 4 - 2
docs/development.html

@@ -168,6 +168,7 @@
 					<tr><td><code>make run-net</code></td><td>Add a PCI NE2000 on QEMU's slirp network with host port 8080 forwarded.</td></tr>
 					<tr><td><code>make run-net</code></td><td>Add a PCI NE2000 on QEMU's slirp network with host port 8080 forwarded.</td></tr>
 					<tr><td><code>make run-rndis</code></td><td>Boot with <code>qemu-xhci</code> and QEMU's full-speed <code>usb-net</code> RNDIS device on slirp; the tethering link gets DHCP from QEMU.</td></tr>
 					<tr><td><code>make run-rndis</code></td><td>Boot with <code>qemu-xhci</code> and QEMU's full-speed <code>usb-net</code> RNDIS device on slirp; the tethering link gets DHCP from QEMU.</td></tr>
 					<tr><td><code>make run-ahci</code></td><td>Add an ICH9 AHCI controller and a 512 MB SATA disk.</td></tr>
 					<tr><td><code>make run-ahci</code></td><td>Add an ICH9 AHCI controller and a 512 MB SATA disk.</td></tr>
+					<tr><td><code>make run-amd</code> / <code>test-amd</code></td><td>Boot QEMU with <code>-cpu Opteron_G5 -smp 6</code> (the FX-6350's family 15h model 2), OHCI, six CPUs and an e1000; the headless test also checks <code>ioapic: masked</code>, <code>smp cpus: 6</code> and the PIT.</td></tr>
 					<tr><td><code>make uefi</code> / <code>run-uefi</code> / <code>test-uefi</code></td><td>Build the dual-boot image, boot it under OVMF, or run the headless serial check.</td></tr>
 					<tr><td><code>make uefi</code> / <code>run-uefi</code> / <code>test-uefi</code></td><td>Build the dual-boot image, boot it under OVMF, or run the headless serial check.</td></tr>
 					<tr><td><code>make rootfs</code></td><td>Rebuild <code>cmds.img</code> only.</td></tr>
 					<tr><td><code>make rootfs</code></td><td>Rebuild <code>cmds.img</code> only.</td></tr>
 					<tr><td><code>make nowm</code></td><td>Diagnostic kernel with the WM disabled; the boot console stays visible.</td></tr>
 					<tr><td><code>make nowm</code></td><td>Diagnostic kernel with the WM disabled; the boot console stays visible.</td></tr>
@@ -179,7 +180,7 @@
 					<tr><td><code>make flash</code></td><td>Write the dual-boot image to a USB stick (needs mingw and prompts for the device).</td></tr>
 					<tr><td><code>make flash</code></td><td>Write the dual-boot image to a USB stick (needs mingw and prompts for the device).</td></tr>
 					<tr><td><code>make test-usb</code></td><td>Headless QEMU mouse/keyboard regression tests using QMP and screen dumps.</td></tr>
 					<tr><td><code>make test-usb</code></td><td>Headless QEMU mouse/keyboard regression tests using QMP and screen dumps.</td></tr>
 					<tr><td><code>make test-install</code></td><td>Boots the dual image with a USB mass-storage source and a blank target, types <code>install ide1</code>, verifies the clone and boots the target in BIOS and UEFI.</td></tr>
 					<tr><td><code>make test-install</code></td><td>Boots the dual image with a USB mass-storage source and a blank target, types <code>install ide1</code>, verifies the clone and boots the target in BIOS and UEFI.</td></tr>
-					<tr><td><code>make test-images</code> / <code>test-images-asan</code></td><td>Host image-decoder and blit tests, with an AddressSanitizer variant.</td></tr>
+					<tr><td><code>make test-images</code> / <code>test-images-asan</code></td><td>Host image-decoder and blit tests, including reduced-IDCT JPEG decode against a box-filtered reference; AddressSanitizer variant included.</td></tr>
 					<tr><td><code>make test-crypto</code></td><td>Host vectors for SHA-256, ChaCha20-Poly1305, X25519, AES-128-GCM, P-256, the TLS 1.2 PRF and TLS helpers.</td></tr>
 					<tr><td><code>make test-crypto</code></td><td>Host vectors for SHA-256, ChaCha20-Poly1305, X25519, AES-128-GCM, P-256, the TLS 1.2 PRF and TLS helpers.</td></tr>
 					<tr><td><code>make test-wpa</code></td><td>Host vectors for the WPA2 supplicant: SHA-1, RFC 6070 PBKDF2, the 802.11 PSK and PRF examples, FIPS-197 AES, RFC 3394 unwrap, plus a simulated 4-way handshake, group rekey, replay and wrong-passphrase case.</td></tr>
 					<tr><td><code>make test-wpa</code></td><td>Host vectors for the WPA2 supplicant: SHA-1, RFC 6070 PBKDF2, the 802.11 PSK and PRF examples, FIPS-197 AES, RFC 3394 unwrap, plus a simulated 4-way handshake, group rekey, replay and wrong-passphrase case.</td></tr>
 					<tr><td><code>make test-wifi-store</code></td><td>Host test for the saved-network file: newest-first ordering, passphrase update, LRU eviction at the 16-entry cap, per-SSID forget, the old one-record format and malformed or duplicate lists.</td></tr>
 					<tr><td><code>make test-wifi-store</code></td><td>Host test for the saved-network file: newest-first ordering, passphrase update, LRU eviction at the 16-entry cap, per-SSID forget, the old one-record format and malformed or duplicate lists.</td></tr>
@@ -299,7 +300,7 @@ make net-cmds                   # replace /ramfs only</code></pre>
 			<li><strong>Chat client.</strong> <code>make test-chat</code> covers the pure modules on the host.  <code>tools/mock_chat.py</code> is a two-origin mock of Cloudron Chat (port 18080) and the Cloudron OIDC login (18081) with <code>test</code>, <code>totp</code> (code 123456), <code>passkey</code> and <code>consent</code> accounts (password <code>test</code>) and <code>/debug/state</code>, <code>/debug/inject</code> endpoints; run it alone and enter <code>http://10.0.2.2:18080</code> in a QEMU guest's chat, or let <code>make test-chat-e2e</code> drive it.  Screenshots land in <code>chat-test-out/</code>.</li>
 			<li><strong>Chat client.</strong> <code>make test-chat</code> covers the pure modules on the host.  <code>tools/mock_chat.py</code> is a two-origin mock of Cloudron Chat (port 18080) and the Cloudron OIDC login (18081) with <code>test</code>, <code>totp</code> (code 123456), <code>passkey</code> and <code>consent</code> accounts (password <code>test</code>) and <code>/debug/state</code>, <code>/debug/inject</code> endpoints; run it alone and enter <code>http://10.0.2.2:18080</code> in a QEMU guest's chat, or let <code>make test-chat-e2e</code> drive it.  Screenshots land in <code>chat-test-out/</code>.</li>
 			<li><strong>Browser compatibility.</strong> <code>make compat-serve</code> serves the numbered A/B ladder in <code>testdata/browser/compat/</code>. Open the index on the board (or at <code>http://10.0.2.2:8000/</code> from a QEMU guest with user networking) and compare each pair; the index table records the current status.</li>
 			<li><strong>Browser compatibility.</strong> <code>make compat-serve</code> serves the numbered A/B ladder in <code>testdata/browser/compat/</code>. Open the index on the board (or at <code>http://10.0.2.2:8000/</code> from a QEMU guest with user networking) and compare each pair; the index table records the current status.</li>
 			<li><strong>Host browser harness.</strong> <code>make browser-host</code> builds the real browser, ngui, image/TLS code and QuickJS as a 32-bit Linux program against the same <code>SYS_*</code> ABI. <code>./browser-host testdata/browser/compat/010-block-width.html</code> opens an SDL3 window (native Wayland on this desktop); the address bar, wheel, links and keys use the normal browser paths. <code>./browser-host --headless --wait 3000 --shot /tmp/opencode/page.ppm URL</code> renders without a display for scripts and screenshots. The harness uses host sockets rather than the NebOS TCP stack, and an <code>mmap</code> arena with the ring-3 allocator, so it tests browser/HTML/CSS/JS/image/font/TLS logic rather than drivers.</li>
 			<li><strong>Host browser harness.</strong> <code>make browser-host</code> builds the real browser, ngui, image/TLS code and QuickJS as a 32-bit Linux program against the same <code>SYS_*</code> ABI. <code>./browser-host testdata/browser/compat/010-block-width.html</code> opens an SDL3 window (native Wayland on this desktop); the address bar, wheel, links and keys use the normal browser paths. <code>./browser-host --headless --wait 3000 --shot /tmp/opencode/page.ppm URL</code> renders without a display for scripts and screenshots. The harness uses host sockets rather than the NebOS TCP stack, and an <code>mmap</code> arena with the ring-3 allocator, so it tests browser/HTML/CSS/JS/image/font/TLS logic rather than drivers.</li>
-			<li><strong>UEFI.</strong> <code>make test-uefi</code> boots the dual image under OVMF headless and greps the serial log for the boot line.</li>
+			<li><strong>UEFI.</strong> <code>make test-uefi</code> boots the dual image under OVMF headless and greps the serial log for the boot line. <code>make test-amd</code> does the same with QEMU's Piledriver CPU model and checks the IOAPIC mask and six-core ACPI SMP.</li>
 			<li><strong>Compositor stats.</strong> The ring-3 WM overwrites <code>/share/wmstats</code> every two seconds with <code>frames</code>, total and worst compositing time in milliseconds, and the pixels drawn in the interval. Read it in a terminal or fetch it over WebDAV to measure a target.</li>
 			<li><strong>Compositor stats.</strong> The ring-3 WM overwrites <code>/share/wmstats</code> every two seconds with <code>frames</code>, total and worst compositing time in milliseconds, and the pixels drawn in the interval. Read it in a terminal or fetch it over WebDAV to measure a target.</li>
 		</ul>
 		</ul>
 	</section>
 	</section>
@@ -309,6 +310,7 @@ make net-cmds                   # replace /ramfs only</code></pre>
 		<ul>
 		<ul>
 			<li><strong>Serial log.</strong> <code>make monitor</code> shows the boot trace and printf-style driver output. The <code>NebOS v… booted</code> line is written before the framebuffer is ready.</li>
 			<li><strong>Serial log.</strong> <code>make monitor</code> shows the boot trace and printf-style driver output. The <code>NebOS v… booted</code> line is written before the framebuffer is ready.</li>
 			<li><strong>Boot time.</strong> Timestamp COM1 on the host (QEMU <code>-serial stdio</code>): the kernel starts at <code>NebOS v… booted</code>, the desktop at <code>wm: first frame</code>, and the terminal is on screen at <code>wm: first window frame (term) at N ms</code> (kernel uptime).  On QEMU the USB image reaches it about 0.4 s after the kernel starts; USB, the NIC and the disks are probed after that (<code>[boot] usb/net/storage</code> lines).</li>
 			<li><strong>Boot time.</strong> Timestamp COM1 on the host (QEMU <code>-serial stdio</code>): the kernel starts at <code>NebOS v… booted</code>, the desktop at <code>wm: first frame</code>, and the terminal is on screen at <code>wm: first window frame (term) at N ms</code> (kernel uptime).  On QEMU the USB image reaches it about 0.4 s after the kernel starts; USB, the NIC and the disks are probed after that (<code>[boot] usb/net/storage</code> lines).</li>
+			<li><strong>No serial port.</strong> The boot console is the early log. After the desktop, <code>bootlog</code> prints the captured text and <code>bootlog save /usb0p3/BOOTLOG.TXT</code> writes it to the live stick's FAT ESP (mount that partition on the host to read it). Once DHCP works, <code>make netmon</code> mirrors serial and terminal output to UDP 19290, so it becomes the serial console.</li>
 			<li><strong>Network console.</strong> <code>make netmon</code> listens to UDP 19290 for serial and terminal output; <code>netconsole host &lt;ip&gt;</code> narrows the target.</li>
 			<li><strong>Network console.</strong> <code>make netmon</code> listens to UDP 19290 for serial and terminal output; <code>netconsole host &lt;ip&gt;</code> narrows the target.</li>
 			<li><strong>dbg.</strong> The ring-0 serial monitor accepts <code>r addr len</code>, <code>w addr b0 …</code>, <code>i port</code>, <code>o port val</code>, <code>h</code> and <code>q</code>.</li>
 			<li><strong>dbg.</strong> The ring-0 serial monitor accepts <code>r addr len</code>, <code>w addr b0 …</code>, <code>i port</code>, <code>o port val</code>, <code>h</code> and <code>q</code>.</li>
 			<li><strong>Keys.</strong> <code>keytest</code> drains the raw scancode tap in <span class="file">io.c</span> and prints every byte with its E0-prefix state, make/break kind and decoded <code>IO_KEY_*</code>/ASCII value; Ctrl+C stops it.  It sees releases and keys the decoder ignores, so an unknown action-row key is easy to identify.</li>
 			<li><strong>Keys.</strong> <code>keytest</code> drains the raw scancode tap in <span class="file">io.c</span> and prints every byte with its E0-prefix state, make/break kind and decoded <code>IO_KEY_*</code>/ASCII value; Ctrl+C stops it.  It sees releases and keys the decoder ignores, so an unknown action-row key is easy to identify.</li>

+ 31 - 5
docs/drivers.html

@@ -84,7 +84,7 @@
 					<tr><td>SATA</td><td><span class="file">ahci.c</span></td><td>PCI AHCI MMIO</td><td>Polled, READ/WRITE DMA EXT</td></tr>
 					<tr><td>SATA</td><td><span class="file">ahci.c</span></td><td>PCI AHCI MMIO</td><td>Polled, READ/WRITE DMA EXT</td></tr>
 					<tr><td>eMMC</td><td><span class="file">sdhci.c</span></td><td>Intel Braswell SDHCI, PCI <code>00:10.0</code> (<code>8086:2294</code>)</td><td>Polled PIO, 1-bit/25 MHz; no DMA/IRQ</td></tr>
 					<tr><td>eMMC</td><td><span class="file">sdhci.c</span></td><td>Intel Braswell SDHCI, PCI <code>00:10.0</code> (<code>8086:2294</code>)</td><td>Polled PIO, 1-bit/25 MHz; no DMA/IRQ</td></tr>
 					<tr><td>USB</td><td><span class="file">usb.c</span> + <span class="file">uhci.c</span> <span class="file">ohci.c</span> <span class="file">ehci.c</span> <span class="file">xhci.c</span></td><td>PCI I/O ports or MMIO</td><td>Polled; hotplug watcher in the WM loop</td></tr>
 					<tr><td>USB</td><td><span class="file">usb.c</span> + <span class="file">uhci.c</span> <span class="file">ohci.c</span> <span class="file">ehci.c</span> <span class="file">xhci.c</span></td><td>PCI I/O ports or MMIO</td><td>Polled; hotplug watcher in the WM loop</td></tr>
-					<tr><td>Network</td><td><span class="file">e1000e.c</span> <span class="file">r8168.c</span> <span class="file">ne2000.c</span> <span class="file">asix.c</span> <span class="file">rndis.c</span></td><td>PCI or USB</td><td>Polled, one active receiver</td></tr>
+					<tr><td>Network</td><td><span class="file">e1000e.c</span> <span class="file">r8168.c</span> <span class="file">ne2000.c</span> <span class="file">asix.c</span> <span class="file">rndis.c</span></td><td>PCI or USB</td><td>Polled, one active receiver; <code>r8168</code> covers the RTL8111E/8168 family (970A-DS3P) as well as the AT3IONT-I's RTL8112L.</td></tr>
 					<tr><td>WiFi</td><td><span class="file">iwl_trans.c</span> <span class="file">iwl_mvm.c</span> <span class="file">iwl_dvm.c</span> <span class="file">wifi.c</span></td><td>PCIe, Intel 7265D/3165 (<code>8086:095a/095b/3165/3166</code>) and 6200/6300 (<code>8086:4239/422c</code>, <code>4238/422b</code>)</td><td>Polled RX ring; firmware from <code>/ramfs/firmware</code>, loaded on first use</td></tr>
 					<tr><td>WiFi</td><td><span class="file">iwl_trans.c</span> <span class="file">iwl_mvm.c</span> <span class="file">iwl_dvm.c</span> <span class="file">wifi.c</span></td><td>PCIe, Intel 7265D/3165 (<code>8086:095a/095b/3165/3166</code>) and 6200/6300 (<code>8086:4239/422c</code>, <code>4238/422b</code>)</td><td>Polled RX ring; firmware from <code>/ramfs/firmware</code>, loaded on first use</td></tr>
 					<tr><td>USB WiFi</td><td><span class="file">rtl8821au.c</span> <span class="file">wifi.c</span></td><td>USB 2.0 high speed, Realtek RTL8821AU/8811AU (TP-Link Archer T2U Nano <code>2357:011f</code> and the other Linux <code>rtw88_8821au</code> IDs)</td><td>Vendor control requests for registers, one bulk-IN/one bulk-OUT endpoint; firmware + register tables from <code>/ramfs/firmware</code></td></tr>
 					<tr><td>USB WiFi</td><td><span class="file">rtl8821au.c</span> <span class="file">wifi.c</span></td><td>USB 2.0 high speed, Realtek RTL8821AU/8811AU (TP-Link Archer T2U Nano <code>2357:011f</code> and the other Linux <code>rtw88_8821au</code> IDs)</td><td>Vendor control requests for registers, one bulk-IN/one bulk-OUT endpoint; firmware + register tables from <code>/ramfs/firmware</code></td></tr>
 					<tr><td>Panel backlight</td><td><span class="file">backlight.c</span></td><td>Intel Braswell/Cherryview graphics MMIO, PCI <code>00:02.0</code> (<code>8086:22b0/22b1</code>)</td><td>Polled register writes; F6/F7 and <code>E0 14</code>/<code>E0 15</code> step 10%; <code>SYS_BACKLIGHT</code> drives the control-panel slider</td></tr>
 					<tr><td>Panel backlight</td><td><span class="file">backlight.c</span></td><td>Intel Braswell/Cherryview graphics MMIO, PCI <code>00:02.0</code> (<code>8086:22b0/22b1</code>)</td><td>Polled register writes; F6/F7 and <code>E0 14</code>/<code>E0 15</code> step 10%; <code>SYS_BACKLIGHT</code> drives the control-panel slider</td></tr>
@@ -284,13 +284,38 @@
 				</thead>
 				</thead>
 				<tbody>
 				<tbody>
 					<tr><td>UHCI</td><td>PCI I/O ports</td><td>1</td><td>Frame list at <code>0x3000</code>; control QH plus one QH per interrupt slot.</td></tr>
 					<tr><td>UHCI</td><td>PCI I/O ports</td><td>1</td><td>Frame list at <code>0x3000</code>; control QH plus one QH per interrupt slot.</td></tr>
-					<tr><td>OHCI</td><td>PCI MMIO</td><td>up to 4</td><td>HCCA from the page allocator, static ED/TD sets, TDs start at <code>CC = NotAccessed</code>.</td></tr>
+					<tr><td>OHCI</td><td>PCI MMIO</td><td>up to 4</td><td>HCCA from the page allocator, static ED/TD sets in the uncacheable <code>ohci_dma_page</code>, TDs start at <code>CC = NotAccessed</code>. Before reset it requests SMM ownership (<code>HcCommandStatus.OCR</code>, clear <code>HcControl.IR</code>) and disables the AMD southbridge USB SMI on <code>1002:4385</code>.</td></tr>
 					<tr><td>EHCI</td><td>PCI MMIO</td><td>up to 4</td><td>Async QH/qTD schedule, page-allocated descriptors, polling only, no periodic list.</td></tr>
 					<tr><td>EHCI</td><td>PCI MMIO</td><td>up to 4</td><td>Async QH/qTD schedule, page-allocated descriptors, polling only, no periodic list.</td></tr>
 					<tr><td>xHCI</td><td>PCI MMIO</td><td>—</td><td>USB2 and USB3 root ports; direct SuperSpeed devices use a 512-byte EP0 and the port speed in the slot context (USB3 hubs are not decoded). Halts and waits for <code>HCH</code> around <code>HCRST</code>; EP0 max packet comes from the port speed; EP0 stages are encoded as one TD per stage (EDK2 style) because chained control TDs stall on Braswell.</td></tr>
 					<tr><td>xHCI</td><td>PCI MMIO</td><td>—</td><td>USB2 and USB3 root ports; direct SuperSpeed devices use a 512-byte EP0 and the port speed in the slot context (USB3 hubs are not decoded). Halts and waits for <code>HCH</code> around <code>HCRST</code>; EP0 max packet comes from the port speed; EP0 stages are encoded as one TD per stage (EDK2 style) because chained control TDs stall on Braswell.</td></tr>
 				</tbody>
 				</tbody>
 			</table>
 			</table>
 		</div>
 		</div>
 
 
+		<p>
+			AMD SB600/SB700/SB800/SB950 firmware can leave the OHCI controllers
+			owned by the SMM and keep the southbridge USB SMI enabled. The
+			driver requests ownership and clears the SMI enable before scanning
+			(<code>ohci.c</code>), so USB2 ports on the 970A-DS3P's SB950 work
+			after the firmware handoff. The SB950's legacy OHCI DMA does not
+			snoop dirty CPU cache lines, so the EDs, TDs, setup packet and
+			interrupt buffers live in one page that <code>paging_init</code>
+			maps uncacheable (PDE 0 is split before paging is enabled). Without
+			it the controller occasionally read an empty ED, skipped the
+			transfer and never re-armed the interrupt endpoint; the cursor
+			froze with no error. Control transfers still flush their
+			write-back data buffers around the transfer.
+		</p>
+		<p>
+			Enumeration starts every device on the USB default 8-byte EP0 and
+			adopts the descriptor's real <code>bMaxPacketSize0</code>
+			afterwards. A failed port attempt is retried three times with a
+			fresh port reset and a 20 ms settle, and OHCI gets a second boot
+			pass 60 ms after the EHCI-first walk so a companion handback
+			cannot leave a low-speed device unseen. HID detach is debounced
+			(three consecutive disconnected reads, 50 TD errors) and a detach
+			forces a clean full rescan, because a false port-loss leaves no
+			connect-change bit to wake the per-port path.
+		</p>
 		<p>
 		<p>
 			Hubs are class-9 devices: <code>usb.c</code> sets their configuration,
 			Hubs are class-9 devices: <code>usb.c</code> sets their configuration,
 			powers every downstream port (honouring <code>bPwrOn2PwrGood</code>),
 			powers every downstream port (honouring <code>bPwrOn2PwrGood</code>),
@@ -594,14 +619,15 @@
 	<section id="sensors">
 	<section id="sensors">
 		<h2>Sensors, power &amp; thermals</h2>
 		<h2>Sensors, power &amp; thermals</h2>
 		<ul>
 		<ul>
-			<li><strong>DTS.</strong> <span class="file">thermal.c</span> reads <code>IA32_THERM_STATUS</code> on an allowlist of Core/Core 2, Nehalem/Westmere, Bonnell and Airmont/Braswell models. TjMax comes from <code>IA32_TEMPERATURE_TARGET</code> on Nehalem/Westmere; Airmont uses coretemp's 90 °C table (the kernel does not read the MSR before the IDT exists), and Bonnell uses the table.</li>
-			<li><strong>IT87xx.</strong> <span class="file">it87.c</span> reads the Super I/O temperatures and fan tachometers on the ASUS AT3IONT-I. Nothing is written to fan control.</li>
+			<li><strong>DTS / AMD Tctl.</strong> <span class="file">thermal.c</span> reads <code>IA32_THERM_STATUS</code> on an allowlist of Core/Core 2, Nehalem/Westmere, Bonnell and Airmont/Braswell models. TjMax comes from <code>IA32_TEMPERATURE_TARGET</code> on Nehalem/Westmere; Airmont uses coretemp's 90 °C table (the kernel does not read the MSR before the IDT exists), and Bonnell uses the table. AMD family 15h models below <code>0x60</code> (Bulldozer/Piledriver) read <code>D18F3xA4</code> at PCI <code>0:18.3</code>; the package value is sampled from the kworker under the BKL and copied to every CPU.</li>
+			<li><strong>IT87xx.</strong> <span class="file">it87.c</span> reads the Super I/O temperatures and fan tachometers on the ASUS AT3IONT-I and the Gigabyte 970A-DS3P (IT8728F). Nothing is written to fan control.</li>
 			<li><strong>ThinkPad EC.</strong> <span class="file">tpec.c</span> is gated on an SMBIOS Lenovo/IBM match and reads temperatures and fan mode through the shared ACPI EC protocol in <span class="file">ec.c</span> (ports <code>0x62/0x66</code>, command <code>0x80</code> read / <code>0x81</code> write, OBF/IBF waits, stale-byte drain, bounded polls). Battery/AC state comes from <code>0x38/0x39</code> (present, charging, discharging), <code>0x46</code> bit 4 (AC online), and the page-selected 16-byte window at <code>0xA0..0xAF</code>; <code>0x81</code> selects the battery and page (0 dynamic, 1 mode, 2 design, 5 manufacturer, 6 model). That page selector is the only EC write, and it is restored when it changed.</li>
 			<li><strong>ThinkPad EC.</strong> <span class="file">tpec.c</span> is gated on an SMBIOS Lenovo/IBM match and reads temperatures and fan mode through the shared ACPI EC protocol in <span class="file">ec.c</span> (ports <code>0x62/0x66</code>, command <code>0x80</code> read / <code>0x81</code> write, OBF/IBF waits, stale-byte drain, bounded polls). Battery/AC state comes from <code>0x38/0x39</code> (present, charging, discharging), <code>0x46</code> bit 4 (AC online), and the page-selected 16-byte window at <code>0xA0..0xAF</code>; <code>0x81</code> selects the battery and page (0 dynamic, 1 mode, 2 design, 5 manufacturer, 6 model). That page selector is the only EC write, and it is restored when it changed.</li>
 			<li><strong>Chrome EC.</strong> <span class="file">cros_ec.c</span> probes the Chrome OS EC, gated on the ACPI memory version, the <code>'E','C'</code> memmap id and the device feature bits; it skips the probe when the ThinkPad EC is present. Its ACPI window <code>0x20..0xFF</code> mirrors memmap <code>0x00..0xDF</code>: temperature sensors <code>0x00..0x0f</code>/<code>0x18..0x1f</code> (raw − 73 °C), fans <code>0x10..0x17</code> (<code>0xffff</code> absent), switches <code>0x30</code> (lid/power button), and the battery block <code>0x40..0x7f</code> (AC/present/charging flags at <code>0x4c</code>, voltage/rate/remaining/design/last-full/cycle count, and the 8-byte strings). <code>EC_ACPI_MEM_BATTERY_INDEX</code> <code>0x12</code> selects the battery and waits for <code>BATT_INDEX</code> <code>0x4e</code>; <code>EC_ACPI_MEM_STRINGS_FIFO</code> <code>0x16</code> returns longer strings when supported. The Cyan full-charge workaround is applied, and the units are mAh/mA. <span class="file">power_src.c</span> picks the ThinkPad backend first, then the Chrome EC; <code>SYS_CROS_EC_SENSORS</code> (107) exposes the EC temperature/fan/switch snapshot.</li>
 			<li><strong>Chrome EC.</strong> <span class="file">cros_ec.c</span> probes the Chrome OS EC, gated on the ACPI memory version, the <code>'E','C'</code> memmap id and the device feature bits; it skips the probe when the ThinkPad EC is present. Its ACPI window <code>0x20..0xFF</code> mirrors memmap <code>0x00..0xDF</code>: temperature sensors <code>0x00..0x0f</code>/<code>0x18..0x1f</code> (raw − 73 °C), fans <code>0x10..0x17</code> (<code>0xffff</code> absent), switches <code>0x30</code> (lid/power button), and the battery block <code>0x40..0x7f</code> (AC/present/charging flags at <code>0x4c</code>, voltage/rate/remaining/design/last-full/cycle count, and the 8-byte strings). <code>EC_ACPI_MEM_BATTERY_INDEX</code> <code>0x12</code> selects the battery and waits for <code>BATT_INDEX</code> <code>0x4e</code>; <code>EC_ACPI_MEM_STRINGS_FIFO</code> <code>0x16</code> returns longer strings when supported. The Cyan full-charge workaround is applied, and the units are mAh/mA. <span class="file">power_src.c</span> picks the ThinkPad backend first, then the Chrome EC; <code>SYS_CROS_EC_SENSORS</code> (107) exposes the EC temperature/fan/switch snapshot.</li>
 			<li><strong>MTRRs.</strong> <span class="file">mtrr.c</span> manages write-combining ranges for the framebuffer and reports the effective mapping.</li>
 			<li><strong>MTRRs.</strong> <span class="file">mtrr.c</span> manages write-combining ranges for the framebuffer and reports the effective mapping.</li>
 		</ul>
 		</ul>
 		<p>
 		<p>
-			<code>sensors</code> prints DTS values on the 90/100/125 °C scales,
+			<code>sensors</code> prints supported CPU temperatures (and the
+			Intel 90/100/125 °C delta scales when there is no published TjMax),
 			board sensors and both EC types; <code>powerinfo</code> prints the
 			board sensors and both EC types; <code>powerinfo</code> prints the
 			source (<code>thinkpad</code> or <code>chrome ec</code>), the AC
 			source (<code>thinkpad</code> or <code>chrome ec</code>), the AC
 			adapter, battery model/manufacturer/serial, capacities, voltage,
 			adapter, battery model/manufacturer/serial, capacities, voltage,

+ 24 - 12
docs/graphics.html

@@ -73,14 +73,19 @@
 			<code>0x600</code>: LFB base, pitch, width, height, bits per pixel
 			<code>0x600</code>: LFB base, pitch, width, height, bits per pixel
 			and an RGBX flag for GOP's byte order. The legacy VESA stage chooses
 			and an RGBX flag for GOP's byte order. The legacy VESA stage chooses
 			a mode with at least 16 bpp, a linear framebuffer, it must fit the
 			a mode with at least 16 bpp, a linear framebuffer, it must fit the
-			card's VRAM, and width at most 1280 pixels. The UEFI loader imposes
-			its own GOP constraints.
+			card's VRAM, at most 1920 pixels wide, and its shadow (pitch ×
+			height) must fit the 8 MB reserve. 1920×1080 is the practical
+			maximum: its 8.29 MB shadow fits, and its 4.15 MB RGB565 canvas
+			fits the 4 MB window slot; 1920×1200 is rejected because its
+			canvas would need 4.6 MB. The UEFI loader applies the same GOP
+			limits.
 		</p>
 		</p>
 		<p>
 		<p>
 			<span class="file">vga.c</span> owns the visible surface. On a
 			<span class="file">vga.c</span> owns the visible surface. On a
 			normal boot the render target is a RAM shadow buffer at
 			normal boot the render target is a RAM shadow buffer at
-			<code>0x100000</code>, not the LFB; the 8 MB reserve leaves room for
-			future modes. A surface carries width, height, pitch, format and a
+			<code>0x100000</code>, not the LFB; the 8 MB reserve holds a
+			1920×1080×32 frame (8.29 MB) with about 94 KB to spare. A surface
+			carries width, height, pitch, format and a
 			pixel-pointer, so the same drawing code can target a window layer or
 			pixel-pointer, so the same drawing code can target a window layer or
 			a canvas.
 			a canvas.
 		</p>
 		</p>
@@ -181,7 +186,9 @@
 			an inline date/time editor with Set, Now and Sync NTP (no separate
 			an inline date/time editor with Set, Now and Sync NTP (no separate
 			window).  <code>SYS_WIN_RESIZE_SELF</code> grows or shrinks the
 			window).  <code>SYS_WIN_RESIZE_SELF</code> grows or shrinks the
 			popover to the section, clamped to <code>SYS_SCREEN_INFO</code>'s
 			popover to the section, clamped to <code>SYS_SCREEN_INFO</code>'s
-			framebuffer; the section scrolls when it is taller than the screen.
+			framebuffer; the section scrolls with the wheel, touchpad or page
+			keys when it is taller than the screen, without drawing a
+			scrollbar.
 		</p>
 		</p>
 		<p>
 		<p>
 			The WM is the ring-3 process loaded from
 			The WM is the ring-3 process loaded from
@@ -287,13 +294,17 @@
 			(<code>+dy</code> is later content). A click that starts
 			(<code>+dy</code> is later content). A click that starts
 			in a window still receives its release after the pointer leaves.
 			in a window still receives its release after the pointer leaves.
 			The ngui helper <code>ngui_scroll_wheel()</code> applies the delta
 			The ngui helper <code>ngui_scroll_wheel()</code> applies the delta
-			to a pane when the pointer is over it.
+			to a pane when the pointer is over it; a pane can set
+			<code>hide_bar</code> to keep wheel/key scrolling without a visible
+			scrollbar (the control panel does this so every card uses the full
+			width).
 			The WM process itself is special: it maps the screen shadow at
 			The WM process itself is special: it maps the screen shadow at
 			<code>0x58000000</code> and each front canvas at
 			<code>0x58000000</code> and each front canvas at
 			<code>0x59000000 + index × 4 MB</code>, which is how it composites
 			<code>0x59000000 + index × 4 MB</code>, which is how it composites
 			without reading another process's memory. The 4 MB slot covers a
 			without reading another process's memory. The 4 MB slot covers a
-			full-screen 1280×1024 canvas minus the chrome; the old 2 MB slot
-			capped a full-height window at roughly 1050 px wide.
+			full-screen 1920×1080 RGB565 canvas (4.15 MB) minus the chrome;
+			the old 2 MB slot capped a full-height window at roughly 1050 px
+			wide.
 			<code>SYS_WM_RESIZE</code> (WM side) and
 			<code>SYS_WM_RESIZE</code> (WM side) and
 			<code>SYS_WIN_ACK_RESIZE</code> (client side) swap in a resized
 			<code>SYS_WIN_ACK_RESIZE</code> (client side) swap in a resized
 			canvas; the content size is bounded by the framebuffer, so a
 			canvas; the content size is bounded by the framebuffer, so a
@@ -391,7 +402,7 @@
 			</div>
 			</div>
 			<div class="card">
 			<div class="card">
 				<h3>chat</h3>
 				<h3>chat</h3>
-				<p>Cloudron Chat client: native OIDC login, channel/DM sidebar with unread badges and presence dots, a wrapped timeline with avatars, day headers and reply snippets, a composer and browse/new-DM pickers. The top-bar <em>Chat</em> button launches it.</p>
+				<p>Cloudron Chat client: native OIDC login, channel/DM sidebar with unread badges and presence dots, a wrapped timeline with avatars, day headers and reply snippets, a composer and browse/new-DM pickers. Media downloads use a warm <code>curl __serve</code> helper; message images are also decoded there (480&times;320 bounds), while avatars decode at 32&times;32 on the chat thread, so the window keeps drawing. Saved sessions resume from <code>/data</code>. The top-bar <em>Chat</em> button launches it.</p>
 			</div>
 			</div>
 			<div class="card">
 			<div class="card">
 				<h3>solitaire</h3>
 				<h3>solitaire</h3>
@@ -423,9 +434,10 @@
 		</p>
 		</p>
 		<ul>
 		<ul>
 			<li><strong>Formats.</strong> PNG, baseline and progressive JPEG, animated GIF, BMP, TGA, PNM, ICO/CUR and PAM. The browser also takes SVG files (<code>&lt;img src="logo.svg"&gt;</code>, CSS backgrounds): the markup is parsed into a detached subtree and drawn by its inline-SVG renderer into an RGB565 + alpha bitmap.</li>
 			<li><strong>Formats.</strong> PNG, baseline and progressive JPEG, animated GIF, BMP, TGA, PNM, ICO/CUR and PAM. The browser also takes SVG files (<code>&lt;img src="logo.svg"&gt;</code>, CSS backgrounds): the markup is parsed into a detached subtree and drawn by its inline-SVG renderer into an RGB565 + alpha bitmap.</li>
-			<li><strong>Drawing.</strong> <code>img_draw()</code> is a clipped, scaled RGB565 blit: box-filter downscale, bilinear upscale, alpha over a checkerboard or over the destination.</li>
+			<li><strong>Drawing.</strong> <code>img_draw()</code> is a clipped, scaled RGB565 blit: box-filter downscale, bilinear upscale, alpha over a checkerboard or over the destination.  A 1:1 opaque source takes a row copy, and a 1:1 alpha source blends in RGB565 without the 8-bit round trip.</li>
+			<li><strong>Display-size decode.</strong> <code>struct img_options</code> carries optional <code>max_w</code>/<code>max_h</code> bounds.  JPEG honours them with a scaled IDCT (1/2 4x4, 1/4 2x2, 1/8 1x1, Loeffler/IGJ), so a 1200x800 photo painted at 400&times;267 is decoded at roughly 600&times;400 instead of full size and then box-filtered.  PNG/GIF/other codecs ignore the bounds and the caller scales them with <code>img_draw()</code>.  The browser's <code>curl __serve</code> helper runs this decode for remote <code>&lt;img&gt;</code> and publishes the finished RGB565+alpha bitmap, so the UI thread only copies it.</li>
 			<li><strong>Orientation.</strong> EXIF orientation is applied; arithmetic JPEG and CMYK are rejected.</li>
 			<li><strong>Orientation.</strong> EXIF orientation is applied; arithmetic JPEG and CMYK are rejected.</li>
-			<li><strong>Cost.</strong> Downscaling runs on the CPU. The viewer caches one image; the browser keeps a display bitmap but still rescales on repaint; the chat client caches up to 480x320 message images and 32x32 circular avatars.</li>
+			<li><strong>Cost.</strong> Downscaling runs on the CPU.  The browser decodes at the CSS/attribute box and caches one display-size bitmap per image, so a repaint is a 1:1 blit; the viewer caches one image; the chat client caches 480&times;320 message images and 32&times;32 circular avatars.  <code>/share/IMGSTAT</code> records the browser's net, io, decode, scale, paint and reflow times.</li>
 		</ul>
 		</ul>
 	</section>
 	</section>
 
 
@@ -433,7 +445,7 @@
 		<h2>GPU quirks</h2>
 		<h2>GPU quirks</h2>
 		<ul>
 		<ul>
 			<li><strong>ATI Mach64.</strong> A CRTC fixup is applied after mode set. The legacy CRTC is skipped under UEFI.</li>
 			<li><strong>ATI Mach64.</strong> A CRTC fixup is applied after mode set. The legacy CRTC is skipped under UEFI.</li>
-			<li><strong>NVIDIA.</strong> VBE-only. The legacy VGA CRTC is never touched. On the ION, the framebuffer is stolen DRAM behind a BAR3 aperture; <span class="file">nvidia.c</span> finds the stolen range and writes through a cached alias once a WC MTRR covers it.</li>
+			<li><strong>NVIDIA.</strong> VBE/GOP only; the kernel never touches the legacy VGA CRTC. On the ION, the framebuffer is stolen DRAM behind a BAR3 aperture; <span class="file">nvidia.c</span> finds the stolen range and writes through a cached alias once a WC MTRR covers it. The nv50 display-engine probe is gated to the ION/nv50 chipsets so Maxwell parts (the GM206 GTX 960) are not poked through nv50 registers.  On AMD family 15h the WC MTRR path uses only a free variable entry, leaves <code>MTRRdefType</code> untouched and writes a zero high mask (the LFB is below 4 GB); this is validated on the 970A-DS3P.</li>
 			<li><strong>Intel.</strong> The Ironlake-era path supports a hardware cursor where available; the software cursor is the common fallback. Cherryview/Braswell also exposes the panel backlight (below).</li>
 			<li><strong>Intel.</strong> The Ironlake-era path supports a hardware cursor where available; the software cursor is the common fallback. Cherryview/Braswell also exposes the panel backlight (below).</li>
 			<li><strong>UEFI.</strong> <code>vga.c</code> honours the RGBX flag and skips the VBE-only ATI CRTC reset and NVIDIA stolen-VRAM alias. <span class="file">mouse.c</span> forces the software cursor.</li>
 			<li><strong>UEFI.</strong> <code>vga.c</code> honours the RGBX flag and skips the VBE-only ATI CRTC reset and NVIDIA stolen-VRAM alias. <span class="file">mouse.c</span> forces the software cursor.</li>
 		</ul>
 		</ul>

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
docs/network.html


+ 8 - 3
efi/main.c

@@ -253,7 +253,7 @@ static int gop_init(EFI_SYSTEM_TABLE *st, EFI_GRAPHICS_OUTPUT_PROTOCOL **out_gop
 		if (info->HorizontalResolution < 320 ||
 		if (info->HorizontalResolution < 320 ||
 		    info->VerticalResolution < 200)
 		    info->VerticalResolution < 200)
 			continue;
 			continue;
-		if (info->HorizontalResolution > 1280 ||
+		if (info->HorizontalResolution > 1920 ||
 		    info->VerticalResolution > 65535)
 		    info->VerticalResolution > 65535)
 			continue;
 			continue;
 		if (info->PixelsPerScanLine < info->HorizontalResolution)
 		if (info->PixelsPerScanLine < info->HorizontalResolution)
@@ -286,7 +286,7 @@ static int gop_init(EFI_SYSTEM_TABLE *st, EFI_GRAPHICS_OUTPUT_PROTOCOL **out_gop
 	    info->PixelFormat != EFI_PIXEL_RGBX)
 	    info->PixelFormat != EFI_PIXEL_RGBX)
 		return 0;
 		return 0;
 	if (info->HorizontalResolution < 320 ||
 	if (info->HorizontalResolution < 320 ||
-	    info->HorizontalResolution > 1280 ||
+	    info->HorizontalResolution > 1920 ||
 	    info->VerticalResolution < 200 ||
 	    info->VerticalResolution < 200 ||
 	    info->VerticalResolution > 65535 ||
 	    info->VerticalResolution > 65535 ||
 	    info->PixelsPerScanLine < info->HorizontalResolution ||
 	    info->PixelsPerScanLine < info->HorizontalResolution ||
@@ -501,7 +501,10 @@ static void write_fbinfo(const struct fb_saved *fb)
 	info->bpp = (unsigned char)fb->bpp;
 	info->bpp = (unsigned char)fb->bpp;
 	info->lfb_base = (unsigned int)fb->base;
 	info->lfb_base = (unsigned int)fb->base;
 	{
 	{
-		UINT64 blocks = fb->size >> 16;
+		/* GOP reports the mode buffer size, not total VRAM.  Round up
+		 * so the kernel's VBE-era height clamp (vram_64k * 64K /
+		 * pitch) cannot shave rows off a 1920x1080 frame. */
+		UINT64 blocks = (fb->size + 0xFFFFull) >> 16;
 
 
 		info->vram_64k = (unsigned short)(blocks > 0xFFFF ? 0xFFFF :
 		info->vram_64k = (unsigned short)(blocks > 0xFFFF ? 0xFFFF :
 						  blocks);
 						  blocks);
@@ -728,6 +731,8 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *st)
 		com1_puts("\n");
 		com1_puts("\n");
 	} else {
 	} else {
 		com1_puts("nebos-efi: no usable GOP mode, booting headless\n");
 		com1_puts("nebos-efi: no usable GOP mode, booting headless\n");
+		conout_puts(st,
+			    "NebOS EFI loader: no usable GOP mode, booting headless\n");
 	}
 	}
 
 
 	rsdp = find_rsdp(st);
 	rsdp = find_rsdp(st);

+ 82 - 0
ioapic.c

@@ -0,0 +1,82 @@
+/* I/O APIC masking.
+ *
+ * This kernel has no IOAPIC driver: the BSP keeps the 8259 PIC and delivers
+ * its interrupts through LAPIC LINT0 in ExtINT mode (lapic.c).  Firmware may
+ * still leave IOAPIC redirection entries programmed, and their vectors can
+ * collide with the PIC vectors (0x20..0x2f) or the LAPIC timer vector 0x30.
+ * Masking every normal entry makes the 8259 path deterministic.
+ *
+ * ExtINT-delivery entries are deliberately left unmasked: a few boards route
+ * the 8259 output through an IOAPIC pin instead of LINT0, and that entry must
+ * keep working.  Entries that are already masked are skipped.
+ */
+#include "ioapic.h"
+#include "acpi.h"
+#include "paging.h"
+#include "serial.h"
+
+#define IOAPIC_REGSEL   0x00
+#define IOAPIC_IOWIN    0x10
+#define IOAPIC_VER      0x01
+#define IOAPIC_REDTBL   0x10
+
+#define IOAPIC_MASK          0x00010000u
+#define IOAPIC_DELMODE_MASK  0x00000700u
+#define IOAPIC_DELMODE_EXTINT 0x00000700u
+
+static unsigned int ioapic_read(volatile unsigned int *base, unsigned int reg)
+{
+	base[IOAPIC_REGSEL / 4] = reg;
+	return base[IOAPIC_IOWIN / 4];
+}
+
+static void ioapic_write(volatile unsigned int *base, unsigned int reg,
+			 unsigned int val)
+{
+	base[IOAPIC_REGSEL / 4] = reg;
+	base[IOAPIC_IOWIN / 4] = val;
+}
+
+void ioapic_mask_all(void)
+{
+	unsigned int n = acpi_ioapic_count();
+	unsigned int i;
+
+	for (i = 0; i < n; i++) {
+		unsigned int addr = acpi_ioapic_base(i);
+		volatile unsigned int *base;
+		unsigned int ver, entries, j, masked = 0;
+
+		if (!addr)
+			continue;
+		paging_map_mmio(addr, 0x1000);
+		base = (volatile unsigned int *)addr;
+
+		ver = ioapic_read(base, IOAPIC_VER);
+		if (ver == 0xFFFFFFFFu)
+			continue;
+		entries = ((ver >> 16) & 0xFFu) + 1u;
+
+		for (j = 0; j < entries; j++) {
+			unsigned int lo = ioapic_read(base,
+						      IOAPIC_REDTBL + 2u * j);
+
+			if (lo & IOAPIC_MASK)
+				continue;
+			if ((lo & IOAPIC_DELMODE_MASK) ==
+			    IOAPIC_DELMODE_EXTINT)
+				continue;
+			ioapic_write(base, IOAPIC_REDTBL + 2u * j,
+				     lo | IOAPIC_MASK);
+			masked++;
+		}
+
+		serial_puts(SERIAL_COM1, "ioapic: masked ");
+		serial_putdec(SERIAL_COM1, masked);
+		serial_puts(SERIAL_COM1, " of ");
+		serial_putdec(SERIAL_COM1, entries);
+		serial_puts(SERIAL_COM1, " entries at ");
+		serial_puthex(SERIAL_COM1, addr);
+		serial_puts(SERIAL_COM1, "\n");
+	}
+}

+ 11 - 0
ioapic.h

@@ -0,0 +1,11 @@
+/* I/O APIC masking (see ioapic.c). */
+#ifndef IOAPIC_H
+#define IOAPIC_H
+
+/* Mask every normal IOAPIC redirection entry so the kernel's 8259/PIC path
+ * (delivered through LAPIC LINT0 as ExtINT) is the only interrupt source.
+ * ExtINT entries are left alone in case the firmware routes the 8259
+ * through an IOAPIC pin instead.  A machine without an IOAPIC is a no-op. */
+void ioapic_mask_all(void);
+
+#endif

+ 7 - 2
kernel.c

@@ -8,6 +8,7 @@
 #include "cros_ec.h"
 #include "cros_ec.h"
 #include "idle.h"
 #include "idle.h"
 #include "io.h"
 #include "io.h"
+#include "ioapic.h"
 #include "lapic.h"
 #include "lapic.h"
 #include "panic.h"
 #include "panic.h"
 #include "kmalloc.h"
 #include "kmalloc.h"
@@ -242,11 +243,12 @@ extern unsigned char __bss_start[], __bss_end[];
 static int kworker_pid = -1;
 static int kworker_pid = -1;
 
 
 /* Parts of the system that must keep running independently of the WM:
 /* Parts of the system that must keep running independently of the WM:
- * input routing, cursor blink, kexec recovery, netlog flushing, gfx-session
- * cleanup and the shadow-buffer flush. */
+ * input routing, thermal polling, cursor blink, kexec recovery, netlog
+ * flushing, gfx-session cleanup and the shadow-buffer flush. */
 static void system_housekeeping(void)
 static void system_housekeeping(void)
 {
 {
 	process_reap_dead();
 	process_reap_dead();
+	thermal_housekeeping();
 	mouse_poll_update();
 	mouse_poll_update();
 #ifndef NOWM
 #ifndef NOWM
 	wm_pump_keyboard();
 	wm_pump_keyboard();
@@ -462,6 +464,9 @@ void kernel_main(void)
 	 * leaves the machine at one CPU. */
 	 * leaves the machine at one CPU. */
 	acpi_init();
 	acpi_init();
 	acpi_dump();
 	acpi_dump();
+	/* The kernel keeps the 8259 on LAPIC LINT0; firmware-left IOAPIC
+	 * entries would otherwise deliver into the PIC/LAPIC vector space. */
+	ioapic_mask_all();
 	boot_trace("acpi");
 	boot_trace("acpi");
 	boot_val("acpi cpus", acpi_cpu_count());
 	boot_val("acpi cpus", acpi_cpu_count());
 	io_init();
 	io_init();

+ 108 - 0
mtrr.c

@@ -56,6 +56,17 @@ static int cpu_has_mtrr(void)
 	return (edx & (1u << 12)) != 0;
 	return (edx & (1u << 12)) != 0;
 }
 }
 
 
+static int cpu_is_amd(void)
+{
+	unsigned int eax = 0, ebx, ecx, edx;
+
+	__asm__ volatile ("cpuid"
+		: "+a"(eax), "=b"(ebx), "=c"(ecx), "=d"(edx));
+	/* "AuthenticAMD" */
+	return ebx == 0x68747541u && edx == 0x69746E65u &&
+	       ecx == 0x444D4163u;
+}
+
 /* Mask bits for physical address bits 32..35+.  Those are reserved (writing
 /* Mask bits for physical address bits 32..35+.  Those are reserved (writing
  * 1 to an unimplemented bit faults) so ask CPUID for the real width.  All
  * 1 to an unimplemented bit faults) so ask CPUID for the real width.  All
  * ones for the implemented high bits means "must match PHYSBASE", which is
  * ones for the implemented high bits means "must match PHYSBASE", which is
@@ -150,6 +161,97 @@ static void dump_mtrrs(unsigned int vcnt)
 	}
 	}
 }
 }
 
 
+/* AMD family 15h WC path.  The Intel path's read-modify-write of
+ * MSR_MTRRdefType is what reset the 970A-DS3P during the first paging init.
+ * AMD only has eight variable MTRRs, and the LFB is below 4 GB, so this path
+ * never touches MTRRdefType and writes a zero high mask (all 32..63 address
+ * bits are don't-care); that avoids every reserved-bit write while still
+ * covering the framebuffer range.  Only a free entry is used. */
+static int mtrr_set_wc_amd(unsigned int base, unsigned int size,
+			   unsigned int *wc_base, unsigned int *wc_size)
+{
+	unsigned int lo, hi, mlo, mhi;
+	unsigned int vcnt, i, use = ~0u;
+	unsigned int region_size, align, physmask;
+
+	rdmsr(MSR_MTRRCAP, &lo, &hi);
+	vcnt = lo & 0xFF;
+	if (vcnt > 8)
+		vcnt = 8;
+	if (vcnt == 0)
+		return 0;
+
+	rdmsr(MSR_MTRR_DEF_TYPE, &lo, &hi);
+	if (!(lo & MTRR_VALID)) {
+		serial_puts(SERIAL_COM1, "mtrr: AMD MTRR disabled by BIOS\n");
+		return 0;
+	}
+
+	region_size = 0x1000;
+	while (region_size < size) {
+		region_size <<= 1;
+		if (region_size == 0)
+			return 0;
+	}
+	align = base & (~base + 1u);
+	if (align == 0 || align > 0x80000000u)
+		align = 0x80000000u;
+	if (region_size > align)
+		region_size = align;
+	if (region_size < 0x1000)
+		return 0;
+	base &= ~(region_size - 1);
+
+	for (i = 0; i < vcnt; i++) {
+		unsigned int esize;
+
+		rdmsr(MSR_MTRR_PHYSBASE0 + 2 * i, &lo, &hi);
+		rdmsr(MSR_MTRR_PHYSMASK0 + 2 * i, &mlo, &mhi);
+		if (!(mlo & MTRR_VALID) || (lo & 0xFF) != MTRR_TYPE_WC ||
+		    (lo & 0xFFFFF000u) != base)
+			continue;
+		esize = ((~mlo) & 0xFFFFF000u) + 0x1000;
+		if (esize < region_size)
+			continue;
+		serial_puts(SERIAL_COM1,
+			    "mtrr: AMD LFB already write-combining\n");
+		if (wc_base)
+			*wc_base = base;
+		if (wc_size)
+			*wc_size = esize;
+		return 1;
+	}
+
+	for (i = 0; i < vcnt; i++) {
+		rdmsr(MSR_MTRR_PHYSMASK0 + 2 * i, &mlo, &mhi);
+		if (!(mlo & MTRR_VALID)) {
+			use = i;
+			break;
+		}
+	}
+	if (use == ~0u) {
+		serial_puts(SERIAL_COM1,
+			    "mtrr: AMD no free variable entry; skipping WC\n");
+		return 0;
+	}
+
+	physmask = (~(region_size - 1) & 0xFFFFF000u) | MTRR_VALID;
+	wrmsr(MSR_MTRR_PHYSBASE0 + 2 * use, base | MTRR_TYPE_WC, 0);
+	wrmsr(MSR_MTRR_PHYSMASK0 + 2 * use, physmask, 0);
+
+	serial_puts(SERIAL_COM1, "mtrr: AMD LFB WC [");
+	serial_puthex(SERIAL_COM1, base);
+	serial_puts(SERIAL_COM1, " +");
+	serial_puthex(SERIAL_COM1, region_size);
+	serial_puts(SERIAL_COM1, "]\n");
+
+	if (wc_base)
+		*wc_base = base;
+	if (wc_size)
+		*wc_size = region_size;
+	return 1;
+}
+
 int mtrr_set_wc(unsigned int base, unsigned int size,
 int mtrr_set_wc(unsigned int base, unsigned int size,
 		unsigned int *wc_base, unsigned int *wc_size)
 		unsigned int *wc_base, unsigned int *wc_size)
 {
 {
@@ -162,6 +264,12 @@ int mtrr_set_wc(unsigned int base, unsigned int size,
 	if (!cpu_has_mtrr() || size == 0)
 	if (!cpu_has_mtrr() || size == 0)
 		return 0;
 		return 0;
 
 
+	/* AMD's MTRR register layout and BIOS setup differ enough from the
+	 * Intel path that the latter reset the 970A-DS3P.  Use the separate
+	 * free-entry/zero-high-mask path. */
+	if (cpu_is_amd())
+		return mtrr_set_wc_amd(base, size, wc_base, wc_size);
+
 	rdmsr(MSR_MTRRCAP, &lo, &hi);
 	rdmsr(MSR_MTRRCAP, &lo, &hi);
 	vcnt = lo & 0xFF;
 	vcnt = lo & 0xFF;
 	if (vcnt > 16)
 	if (vcnt > 16)

+ 7 - 4
nvidia.c

@@ -197,9 +197,12 @@ void nvidia_init(unsigned int bus, unsigned int dev, unsigned int device_id)
 		serial_puts(SERIAL_COM1, "\n");
 		serial_puts(SERIAL_COM1, "\n");
 	}
 	}
 
 
-	/* Read-only look at the display engine (EVO channels, object table,
-	 * cursor state) for boards with no serial console (netmon mirror). */
-	nv50_probe();
+	/* Read-only look at the nv50-family display engine (EVO channels,
+	 * object table, cursor state).  The register layout is nv50-specific;
+	 * Maxwell and later parts must not be poked through it. */
+	if (nv_present && (nv_chipset == 0xaa || nv_chipset == 0xac ||
+			    nv_chipset == 0xaf))
+		nv50_probe();
 }
 }
 
 
 int nvidia_available(void)
 int nvidia_available(void)
@@ -275,7 +278,7 @@ unsigned int nvidia_lfb_in_vram(void)
 
 
 	paging_map_ram(vram, vsize);
 	paging_map_ram(vram, vsize);
 
 
-	/* Marker at LFB + 8 MB: past any 1280x1024x32 frame. */
+	/* Marker at LFB + 8 MB: past any 1920x1080x32 frame. */
 	{
 	{
 		volatile unsigned int *p =
 		volatile unsigned int *p =
 			(volatile unsigned int *)(lfb + 0x00800000u);
 			(volatile unsigned int *)(lfb + 0x00800000u);

+ 241 - 46
ohci.c

@@ -50,13 +50,19 @@
 #define CTL_HCFS     0x000000C0u
 #define CTL_HCFS     0x000000C0u
 #define HCFS_RESUME  0x00000040u
 #define HCFS_RESUME  0x00000040u
 #define HCFS_OPER    0x00000080u
 #define HCFS_OPER    0x00000080u
+#define CTL_IR       0x00000100u   /* SMM owns the controller */
 
 
 /* R_COMMAND bits. */
 /* R_COMMAND bits. */
 #define CMD_HCR 0x00000001u
 #define CMD_HCR 0x00000001u
 #define CMD_CLF 0x00000002u
 #define CMD_CLF 0x00000002u
+#define CMD_OCR 0x00000008u   /* request ownership from the SMM */
 
 
 /* R_INT_STATUS bits. */
 /* R_INT_STATUS bits. */
 #define INTR_WDH 0x00000002u
 #define INTR_WDH 0x00000002u
+#define INTR_RHSC 0x00000040u
+
+/* HCCA: DoneHead is the 33rd dword. */
+#define HCCA_DONE_HEAD 0x84u
 
 
 /* R_RH_DESC_A bits. */
 /* R_RH_DESC_A bits. */
 #define RHA_PSM    0x00000100u
 #define RHA_PSM    0x00000100u
@@ -143,18 +149,25 @@ struct ohci_ctrl {
 	int int_armed[USB_HCD_INT_SLOTS];
 	int int_armed[USB_HCD_INT_SLOTS];
 };
 };
 
 
-static struct ohci_ctrl ctrls[USB_HCD_MAX_CTRL];
 static unsigned int n_ctrls;
 static unsigned int n_ctrls;
-
-/* Control-transfer scratch: transfers are serialized, so one ED/TD set for
-   all instances is enough.  A dummy TD anchors the tail of each queue (the
-   controller stops when HeadP == TailP; the dummy is never processed). */
-static struct ohci_ed ctrl_ed;
-static struct ohci_td ctrl_tds[OHCI_MAX_TD];
-static struct ohci_td ctrl_dummy;
-static unsigned char setup_buf[8] __attribute__((aligned(16)));
 static int ctl_busy;
 static int ctl_busy;
 
 
+/* DMA structures are filled by the CPU and read/written by the controller.
+ * The SB950's OHCI does not snoop dirty CPU cache lines, so paging_init()
+ * maps this page uncacheable (see paging.c).  One ED/TD set is shared by
+ * all control transfers (they are serialized by ctl_busy). */
+struct ohci_dma {
+	struct ohci_ed ctrl_ed;
+	struct ohci_td ctrl_tds[OHCI_MAX_TD];
+	struct ohci_td ctrl_dummy;
+	unsigned char setup_buf[8] __attribute__((aligned(16)));
+	struct ohci_ctrl ctrls[USB_HCD_MAX_CTRL];
+};
+
+unsigned char ohci_dma_page[4096] __attribute__((aligned(4096)));
+static struct ohci_dma *const dma = (struct ohci_dma *)ohci_dma_page;
+typedef char ohci_dma_fits_page[(sizeof(struct ohci_dma) <= 4096) ? 1 : -1];
+
 static void ohci_int_in_stop(unsigned int slot);
 static void ohci_int_in_stop(unsigned int slot);
 
 
 static unsigned int rd(struct ohci_ctrl *c, unsigned int ofs)
 static unsigned int rd(struct ohci_ctrl *c, unsigned int ofs)
@@ -167,6 +180,27 @@ static void wr(struct ohci_ctrl *c, unsigned int ofs, unsigned int val)
 	c->regs[ofs >> 2] = val;
 	c->regs[ofs >> 2] = val;
 }
 }
 
 
+/* The EDs/TDs live in cacheable RAM while the controller DMAs them.  Store
+ * ordering against the MMIO doorbell is not free: without a full barrier the
+ * HC can read an ED before the (WB) head-pointer store is visible, see
+ * HeadP == TailP, skip the transfer and never retire the TD.  That was the
+ * SB950 mouse's intermittent "cursor stops, no error" failure.  MFENCE needs
+ * SSE2, so use the i486-compatible locked no-op. */
+static void ohci_barrier(void)
+{
+	__asm__ volatile ("lock; addl $0, 0(%%esp)" ::: "memory");
+}
+
+/* The descriptors are uncacheable, but the caller's control data buffer is
+ * ordinary write-back memory.  Flush dirty OUT data before the HC reads it
+ * and drop stale lines before reading the DMA-written IN data.  Control
+ * transfers are rare (enumeration, SCSI commands), so WBINVD is cheap here;
+ * the polled HID path never calls it. */
+static void ohci_flush(void)
+{
+	__asm__ volatile ("wbinvd" ::: "memory");
+}
+
 static void delay_ms(unsigned int ms)
 static void delay_ms(unsigned int ms)
 {
 {
 	usb_delay_ms(ms);    /* sleeps inside a sleepable scan */
 	usb_delay_ms(ms);    /* sleeps inside a sleepable scan */
@@ -177,6 +211,66 @@ static unsigned int port_reg(unsigned int port)
 	return R_RH_PORT_FIRST + 4u * port;
 	return R_RH_PORT_FIRST + 4u * port;
 }
 }
 
 
+/* Polled driver: retired TDs are harvested from their CC fields, so the
+ * done list itself is discarded.  WDH must still be acknowledged, or the
+ * HC stops refreshing HCCA.DoneHead and (on this SB950) occasionally
+ * stops fetching a freshly filled control list. */
+static void ohci_ack_done(struct ohci_ctrl *c)
+{
+	if (rd(c, R_INT_STATUS) & (INTR_WDH | INTR_RHSC)) {
+		if (rd(c, R_INT_STATUS) & INTR_WDH)
+			((volatile unsigned int *)c->hcca)[HCCA_DONE_HEAD / 4] = 0;
+		wr(c, R_INT_STATUS, INTR_WDH | INTR_RHSC);
+	}
+}
+
+/* AMD SB600/SB700/SB800/SB950 SMBus device.  Its config 0x64 bit 15 gates
+ * the southbridge USB SMI: the firmware keeps legacy USB emulation alive
+ * with it, and with it enabled the SMM can intercept/take back the OHCI
+ * controllers after the OS has programmed them.  Linux/FreeBSD disable it
+ * once the USB host drivers own the ports. */
+static void amd_sb_usb_smi_disable(void)
+{
+	static int done;
+	unsigned int bus, dev, func;
+
+	if (done)
+		return;
+	done = 1;
+
+	/* The southbridge SMBus function is always on PCI bus 0.  Scanning
+	 * only that bus keeps the probe cheap on Intel/QEMU machines, where
+	 * it finds nothing. */
+	bus = 0;
+	for (dev = 0; dev < 32; dev++) {
+		unsigned int id = pci_cfg_read32(bus, dev, 0, 0x00);
+		unsigned int htype, nfunc;
+
+		if (id == 0xFFFFFFFFu || id == 0)
+			continue;
+		htype = (pci_cfg_read32(bus, dev, 0, 0x0C) >> 16) & 0xFFu;
+		nfunc = (htype & 0x80u) ? 8u : 1u;
+		for (func = 0; func < nfunc; func++) {
+			unsigned int idf = pci_cfg_read32(bus, dev, func, 0x00);
+			unsigned int val;
+
+			if (idf == 0xFFFFFFFFu || idf == 0)
+				continue;
+			if ((idf & 0xFFFFu) != 0x1002u ||
+			    ((idf >> 16) & 0xFFFFu) != 0x4385u)
+				continue;
+			val = pci_cfg_read32(bus, dev, func, 0x64);
+			if (val & 0x8000u) {
+				pci_cfg_write32(bus, dev, func, 0x64,
+						val & ~0x8000u);
+				serial_puts(SERIAL_COM1,
+					"ohci: disabled AMD SB USB SMI\n");
+			}
+			return;
+		}
+	}
+}
+
 static int ohci_setup_one(unsigned int bus, unsigned int dev, unsigned int func)
 static int ohci_setup_one(unsigned int bus, unsigned int dev, unsigned int func)
 {
 {
 	struct ohci_ctrl *c;
 	struct ohci_ctrl *c;
@@ -202,7 +296,7 @@ static int ohci_setup_one(unsigned int bus, unsigned int dev, unsigned int func)
 	/* Disable legacy SMI emulation (same idea as the UHCI driver). */
 	/* Disable legacy SMI emulation (same idea as the UHCI driver). */
 	pci_cfg_write16(bus, dev, func, 0xC0, 0);
 	pci_cfg_write16(bus, dev, func, 0xC0, 0);
 
 
-	c = &ctrls[n_ctrls];
+	c = &dma->ctrls[n_ctrls];
 	c->regs = (volatile unsigned int *)bar;
 	c->regs = (volatile unsigned int *)bar;
 	c->bus = bus;
 	c->bus = bus;
 	c->dev = dev;
 	c->dev = dev;
@@ -218,6 +312,32 @@ static int ohci_setup_one(unsigned int bus, unsigned int dev, unsigned int func)
 		return -1;
 		return -1;
 	}
 	}
 
 
+	/* On AMD southbridges the firmware SMM can still own the controller.
+	 * Request ownership (HcCommandStatus.OCR) and clear HcControl.IR
+	 * before resetting; otherwise the controller ignores our commands
+	 * until the SMM decides to release it.  On Intel/QEMU IR is already
+	 * clear, so this is a no-op. */
+	{
+		unsigned int ctl = rd(c, R_CONTROL);
+
+		if (ctl & CTL_IR) {
+			serial_puts(SERIAL_COM1,
+				    "ohci: SMM owns controller, requesting change\n");
+			wr(c, R_COMMAND, CMD_OCR);
+			wr(c, R_CONTROL, ctl & ~CTL_IR);
+			t0 = get_ticks_ms();
+			while (rd(c, R_CONTROL) & CTL_IR) {
+				if (get_ticks_ms() - t0 > 200)
+					break;
+				delay_ms(1);
+			}
+			serial_puts(SERIAL_COM1,
+				    (rd(c, R_CONTROL) & CTL_IR) ?
+				    "ohci: SMM did not release\n" :
+				    "ohci: ownership acquired\n");
+		}
+	}
+
 	c->hcca = mm_alloc_page();
 	c->hcca = mm_alloc_page();
 	if (!c->hcca) {
 	if (!c->hcca) {
 		serial_puts(SERIAL_COM1, "ohci: no memory for HCCA\n");
 		serial_puts(SERIAL_COM1, "ohci: no memory for HCCA\n");
@@ -243,6 +363,7 @@ static int ohci_setup_one(unsigned int bus, unsigned int dev, unsigned int func)
 	}
 	}
 	for (i = 0; i < 32; i++)
 	for (i = 0; i < 32; i++)
 		((unsigned int *)c->hcca)[i] = (unsigned int)&c->int_ed[0];
 		((unsigned int *)c->hcca)[i] = (unsigned int)&c->int_ed[0];
+	ohci_barrier();
 
 
 	/* Host controller reset. */
 	/* Host controller reset. */
 	wr(c, R_COMMAND, CMD_HCR);
 	wr(c, R_COMMAND, CMD_HCR);
@@ -260,7 +381,7 @@ static int ohci_setup_one(unsigned int bus, unsigned int dev, unsigned int func)
 	wr(c, R_HCCA, c->hcca);
 	wr(c, R_HCCA, c->hcca);
 	wr(c, R_INT_DISABLE, 0xFFFFFFFFu);
 	wr(c, R_INT_DISABLE, 0xFFFFFFFFu);
 	wr(c, R_INT_STATUS, 0xFFFFFFFFu);   /* clear pending */
 	wr(c, R_INT_STATUS, 0xFFFFFFFFu);   /* clear pending */
-	wr(c, R_DONE_HEAD, 0);
+	((unsigned int *)c->hcca)[HCCA_DONE_HEAD / 4] = 0;
 
 
 	/* Root hub: port count and power. */
 	/* Root hub: port count and power. */
 	rha = rd(c, R_RH_DESC_A);
 	rha = rd(c, R_RH_DESC_A);
@@ -292,7 +413,9 @@ static int ohci_setup_one(unsigned int bus, unsigned int dev, unsigned int func)
 	   periodic + control lists enabled. */
 	   periodic + control lists enabled. */
 	wr(c, R_CONTROL, HCFS_RESUME);
 	wr(c, R_CONTROL, HCFS_RESUME);
 	delay_ms(20);
 	delay_ms(20);
+	ohci_barrier();
 	wr(c, R_CONTROL, HCFS_OPER | CTL_PLE | CTL_CLE);
 	wr(c, R_CONTROL, HCFS_OPER | CTL_PLE | CTL_CLE);
+	ohci_barrier();
 
 
 	n_ctrls++;
 	n_ctrls++;
 
 
@@ -337,6 +460,8 @@ static int ohci_init(void)
 	if (n_ctrls)
 	if (n_ctrls)
 		return (int)n_ctrls;
 		return (int)n_ctrls;
 
 
+	amd_sb_usb_smi_disable();
+
 	for (bus = 0; bus < 256 && n_ctrls < USB_HCD_MAX_CTRL; bus++) {
 	for (bus = 0; bus < 256 && n_ctrls < USB_HCD_MAX_CTRL; bus++) {
 		for (dev = 0; dev < 32; dev++) {
 		for (dev = 0; dev < 32; dev++) {
 			for (func = 0; func < 8; func++) {
 			for (func = 0; func < 8; func++) {
@@ -366,7 +491,7 @@ static unsigned int ohci_count(void)
 static void ohci_info(unsigned int ctrl, unsigned int *bus, unsigned int *dev,
 static void ohci_info(unsigned int ctrl, unsigned int *bus, unsigned int *dev,
 		      unsigned int *func, unsigned int *base, int *mmio)
 		      unsigned int *func, unsigned int *base, int *mmio)
 {
 {
-	struct ohci_ctrl *c = &ctrls[ctrl];
+	struct ohci_ctrl *c = &dma->ctrls[ctrl];
 	*bus = c->bus;
 	*bus = c->bus;
 	*dev = c->dev;
 	*dev = c->dev;
 	*func = c->func;
 	*func = c->func;
@@ -376,22 +501,22 @@ static void ohci_info(unsigned int ctrl, unsigned int *bus, unsigned int *dev,
 
 
 static unsigned int ohci_port_count(unsigned int ctrl)
 static unsigned int ohci_port_count(unsigned int ctrl)
 {
 {
-	return ctrls[ctrl].ports;
+	return dma->ctrls[ctrl].ports;
 }
 }
 
 
 static int ohci_port_connected(unsigned int ctrl, unsigned int port)
 static int ohci_port_connected(unsigned int ctrl, unsigned int port)
 {
 {
-	return (rd(&ctrls[ctrl], port_reg(port)) & PS_CCS) ? 1 : 0;
+	return (rd(&dma->ctrls[ctrl], port_reg(port)) & PS_CCS) ? 1 : 0;
 }
 }
 
 
 static int ohci_port_low_speed(unsigned int ctrl, unsigned int port)
 static int ohci_port_low_speed(unsigned int ctrl, unsigned int port)
 {
 {
-	return (rd(&ctrls[ctrl], port_reg(port)) & PS_LSDA) ? 1 : 0;
+	return (rd(&dma->ctrls[ctrl], port_reg(port)) & PS_LSDA) ? 1 : 0;
 }
 }
 
 
 static int ohci_port_take_change(unsigned int ctrl, unsigned int port)
 static int ohci_port_take_change(unsigned int ctrl, unsigned int port)
 {
 {
-	struct ohci_ctrl *c = &ctrls[ctrl];
+	struct ohci_ctrl *c = &dma->ctrls[ctrl];
 	unsigned int ofs = port_reg(port);
 	unsigned int ofs = port_reg(port);
 
 
 	if (!(rd(c, ofs) & PS_CSC))
 	if (!(rd(c, ofs) & PS_CSC))
@@ -402,7 +527,7 @@ static int ohci_port_take_change(unsigned int ctrl, unsigned int port)
 
 
 static int ohci_port_reset(unsigned int ctrl, unsigned int port)
 static int ohci_port_reset(unsigned int ctrl, unsigned int port)
 {
 {
-	struct ohci_ctrl *c = &ctrls[ctrl];
+	struct ohci_ctrl *c = &dma->ctrls[ctrl];
 	unsigned int ofs = port_reg(port);
 	unsigned int ofs = port_reg(port);
 	unsigned int t0, st;
 	unsigned int t0, st;
 
 
@@ -455,16 +580,16 @@ static int ohci_transfer(struct ohci_ctrl *c, unsigned int addr,
 		mps = 64;
 		mps = 64;
 
 
 	for (i = 0; i < 8; i++)
 	for (i = 0; i < 8; i++)
-		setup_buf[i] = setup[i];
+		dma->setup_buf[i] = setup[i];
 
 
 	/* SETUP stage (DATA0). */
 	/* SETUP stage (DATA0). */
-	td_set(&ctrl_tds[n++], TD_DP(TD_DP_SETUP) | TD_T_DATA0,
-	       (unsigned int)setup_buf, (unsigned int)setup_buf + 7);
+	td_set(&dma->ctrl_tds[n++], TD_DP(TD_DP_SETUP) | TD_T_DATA0,
+	       (unsigned int)dma->setup_buf, (unsigned int)dma->setup_buf + 7);
 
 
 	/* DATA stage: one TD for the whole buffer, DATA1 (like Linux; the
 	/* DATA stage: one TD for the whole buffer, DATA1 (like Linux; the
 	   controller splits it into MPS-sized packets itself). */
 	   controller splits it into MPS-sized packets itself). */
 	if (len > 0) {
 	if (len > 0) {
-		td_set(&ctrl_tds[n++],
+		td_set(&dma->ctrl_tds[n++],
 		       TD_R | TD_DP(dir_in ? TD_DP_IN : TD_DP_OUT) |
 		       TD_R | TD_DP(dir_in ? TD_DP_IN : TD_DP_OUT) |
 		       TD_T_DATA1,
 		       TD_T_DATA1,
 		       (unsigned int)data, (unsigned int)(data + len - 1));
 		       (unsigned int)data, (unsigned int)(data + len - 1));
@@ -472,24 +597,27 @@ static int ohci_transfer(struct ohci_ctrl *c, unsigned int addr,
 	}
 	}
 
 
 	/* STATUS stage (DATA1, opposite direction, no data). */
 	/* STATUS stage (DATA1, opposite direction, no data). */
-	td_set(&ctrl_tds[n++],
+	td_set(&dma->ctrl_tds[n++],
 	       TD_DP(dir_in ? TD_DP_OUT : TD_DP_IN) | TD_T_DATA1, 0, 0);
 	       TD_DP(dir_in ? TD_DP_OUT : TD_DP_IN) | TD_T_DATA1, 0, 0);
 
 
 	/* Chain the TDs and anchor the tail on the dummy TD. */
 	/* Chain the TDs and anchor the tail on the dummy TD. */
 	for (i = 0; i + 1 < n; i++)
 	for (i = 0; i + 1 < n; i++)
-		ctrl_tds[i].next = (unsigned int)&ctrl_tds[i + 1];
-	ctrl_tds[n - 1].next = (unsigned int)&ctrl_dummy;
-	ctrl_dummy.flags = TD_NOTACCESSED << TD_CC_SHIFT;
-	ctrl_dummy.cbp = 0;
-	ctrl_dummy.next = 0;
-	ctrl_dummy.be = 0;
-
-	ctrl_ed.flags = ED_FA(addr) | ED_EN(0) | ED_MPS(mps) | (low ? ED_S : 0);
-	ctrl_ed.tail = (unsigned int)&ctrl_dummy;
-	ctrl_ed.head = (unsigned int)&ctrl_tds[0];
-	ctrl_ed.next = 0;
-
-	wr(c, R_CTRL_HEAD_ED, (unsigned int)&ctrl_ed);
+		dma->ctrl_tds[i].next = (unsigned int)&dma->ctrl_tds[i + 1];
+	dma->ctrl_tds[n - 1].next = (unsigned int)&dma->ctrl_dummy;
+	dma->ctrl_dummy.flags = TD_NOTACCESSED << TD_CC_SHIFT;
+	dma->ctrl_dummy.cbp = 0;
+	dma->ctrl_dummy.next = 0;
+	dma->ctrl_dummy.be = 0;
+
+	ohci_barrier();
+	dma->ctrl_ed.flags = ED_FA(addr) | ED_EN(0) | ED_MPS(mps) | (low ? ED_S : 0);
+	dma->ctrl_ed.tail = (unsigned int)&dma->ctrl_dummy;
+	dma->ctrl_ed.head = (unsigned int)&dma->ctrl_tds[0];
+	dma->ctrl_ed.next = 0;
+	ohci_barrier();
+	ohci_flush();
+
+	wr(c, R_CTRL_HEAD_ED, (unsigned int)&dma->ctrl_ed);
 	wr(c, R_COMMAND, CMD_CLF);
 	wr(c, R_COMMAND, CMD_CLF);
 
 
 	/* Poll until every TD has left "not accessed".  A NAKed TD stays
 	/* Poll until every TD has left "not accessed".  A NAKed TD stays
@@ -498,8 +626,10 @@ static int ohci_transfer(struct ohci_ctrl *c, unsigned int addr,
 	for (;;) {
 	for (;;) {
 		int done = 1, err = 0;
 		int done = 1, err = 0;
 
 
+		ohci_flush();
+		ohci_ack_done(c);
 		for (i = 0; i < n; i++) {
 		for (i = 0; i < n; i++) {
-			unsigned int cc = (ctrl_tds[i].flags & TD_CC_MASK)
+			unsigned int cc = (dma->ctrl_tds[i].flags & TD_CC_MASK)
 					  >> TD_CC_SHIFT;
 					  >> TD_CC_SHIFT;
 			if (cc == TD_NOTACCESSED) {
 			if (cc == TD_NOTACCESSED) {
 				done = 0;
 				done = 0;
@@ -515,27 +645,77 @@ static int ohci_transfer(struct ohci_ctrl *c, unsigned int addr,
 			}
 			}
 		}
 		}
 		if (err) {
 		if (err) {
-			ctrl_ed.head = (unsigned int)&ctrl_dummy;
+			serial_puts(SERIAL_COM1, "ohci: xfer err addr ");
+			serial_putdec(SERIAL_COM1, addr);
+			serial_puts(SERIAL_COM1, " mps ");
+			serial_putdec(SERIAL_COM1, mps);
+			serial_puts(SERIAL_COM1, " low ");
+			serial_putdec(SERIAL_COM1, (unsigned int)low);
+			serial_puts(SERIAL_COM1, "\n");
+			dma->ctrl_ed.head = (unsigned int)&dma->ctrl_dummy;
 			wr(c, R_CTRL_HEAD_ED, 0);
 			wr(c, R_CTRL_HEAD_ED, 0);
 			return -1;
 			return -1;
 		}
 		}
 		if (done)
 		if (done)
 			break;
 			break;
 		if (get_ticks_ms() - t0 > 2000) {
 		if (get_ticks_ms() - t0 > 2000) {
-			serial_puts(SERIAL_COM1, "ohci: xfer timeout\n");
-			ctrl_ed.head = (unsigned int)&ctrl_dummy;
+			serial_puts(SERIAL_COM1, "ohci: xfer timeout addr ");
+			serial_putdec(SERIAL_COM1, addr);
+			serial_puts(SERIAL_COM1, " mps ");
+			serial_putdec(SERIAL_COM1, mps);
+			serial_puts(SERIAL_COM1, " low ");
+			serial_putdec(SERIAL_COM1, (unsigned int)low);
+			for (i = 0; i < n; i++) {
+				serial_puts(SERIAL_COM1, " td");
+				serial_putdec(SERIAL_COM1, i);
+				serial_puts(SERIAL_COM1, " cc ");
+				serial_putdec(SERIAL_COM1,
+					      (dma->ctrl_tds[i].flags & TD_CC_MASK) >>
+					      TD_CC_SHIFT);
+			}
+			/* Controller state: a frozen frame number or a
+			 * cleared CLE/IR says whether the HC is running and
+			 * owns the controller at all. */
+			serial_puts(SERIAL_COM1, " ctl ");
+			serial_puthex(SERIAL_COM1, rd(c, R_CONTROL));
+			serial_puts(SERIAL_COM1, " cmd ");
+			serial_puthex(SERIAL_COM1, rd(c, R_COMMAND));
+			serial_puts(SERIAL_COM1, " int ");
+			serial_puthex(SERIAL_COM1, rd(c, R_INT_STATUS));
+			serial_puts(SERIAL_COM1, " fm ");
+			serial_puthex(SERIAL_COM1, rd(c, R_FM_NUMBER));
+			serial_puts(SERIAL_COM1, " head ");
+			serial_puthex(SERIAL_COM1, rd(c, R_CTRL_HEAD_ED));
+			serial_puts(SERIAL_COM1, " ed ");
+			serial_puthex(SERIAL_COM1, dma->ctrl_ed.flags);
+			serial_putc(SERIAL_COM1, ' ');
+			serial_puthex(SERIAL_COM1, dma->ctrl_ed.tail);
+			serial_putc(SERIAL_COM1, ' ');
+			serial_puthex(SERIAL_COM1, dma->ctrl_ed.head);
+			serial_putc(SERIAL_COM1, ' ');
+			serial_puthex(SERIAL_COM1, dma->ctrl_ed.next);
+			serial_puts(SERIAL_COM1, " t0 ");
+			serial_puthex(SERIAL_COM1, dma->ctrl_tds[0].flags);
+			serial_putc(SERIAL_COM1, ' ');
+			serial_puthex(SERIAL_COM1, dma->ctrl_tds[0].cbp);
+			serial_putc(SERIAL_COM1, ' ');
+			serial_puthex(SERIAL_COM1, dma->ctrl_tds[0].next);
+			serial_putc(SERIAL_COM1, ' ');
+			serial_puthex(SERIAL_COM1, dma->ctrl_tds[0].be);
+			serial_puts(SERIAL_COM1, "\n");
+			dma->ctrl_ed.head = (unsigned int)&dma->ctrl_dummy;
 			wr(c, R_CTRL_HEAD_ED, 0);
 			wr(c, R_CTRL_HEAD_ED, 0);
 			return -1;
 			return -1;
 		}
 		}
 		usb_poll_relax(t0);
 		usb_poll_relax(t0);
 	}
 	}
-	ctrl_ed.head = (unsigned int)&ctrl_dummy;
+	dma->ctrl_ed.head = (unsigned int)&dma->ctrl_dummy;
 	wr(c, R_CTRL_HEAD_ED, 0);
 	wr(c, R_CTRL_HEAD_ED, 0);
 
 
 	/* Bytes actually received: the TD's CBP advances with the data
 	/* Bytes actually received: the TD's CBP advances with the data
 	   (the controller clears it to 0 when the whole buffer arrived). */
 	   (the controller clears it to 0 when the whole buffer arrived). */
 	if (len > 0 && dir_in && n_data == 1) {
 	if (len > 0 && dir_in && n_data == 1) {
-		unsigned int cbp = ctrl_tds[1].cbp;
+		unsigned int cbp = dma->ctrl_tds[1].cbp;
 
 
 		if (cbp == 0)
 		if (cbp == 0)
 			return (int)len;
 			return (int)len;
@@ -555,7 +735,7 @@ static int ohci_control_transfer(unsigned int ctrl, unsigned int addr,
 	if (ctrl >= n_ctrls || ctl_busy)
 	if (ctrl >= n_ctrls || ctl_busy)
 		return -1;
 		return -1;
 	ctl_busy = 1;
 	ctl_busy = 1;
-	r = ohci_transfer(&ctrls[ctrl], addr, mps, low_speed, setup, data, len,
+	r = ohci_transfer(&dma->ctrls[ctrl], addr, mps, low_speed, setup, data, len,
 			  dir_in);
 			  dir_in);
 	ctl_busy = 0;
 	ctl_busy = 0;
 	return r;
 	return r;
@@ -574,10 +754,14 @@ static void ohci_int_arm(struct ohci_ctrl *c, unsigned int slot)
 	c->int_td[slot].be = (unsigned int)c->int_buf[slot] +
 	c->int_td[slot].be = (unsigned int)c->int_buf[slot] +
 			     c->int_mps[slot] - 1;
 			     c->int_mps[slot] - 1;
 
 
+	/* Publish the TD before the ED points at it, and the new head before
+	 * the controller's next pass. */
+	ohci_barrier();
 	c->int_ed[slot].head = (unsigned int)&c->int_td[slot] |
 	c->int_ed[slot].head = (unsigned int)&c->int_td[slot] |
 			       (c->int_toggle[slot] ? ED_C : 0);
 			       (c->int_toggle[slot] ? ED_C : 0);
 	c->int_ed[slot].tail = (unsigned int)&c->int_dummy[slot];
 	c->int_ed[slot].tail = (unsigned int)&c->int_dummy[slot];
 	/* int_ed[slot].next keeps the chain to the other slots. */
 	/* int_ed[slot].next keeps the chain to the other slots. */
+	ohci_barrier();
 
 
 	c->int_armed[slot] = 1;
 	c->int_armed[slot] = 1;
 }
 }
@@ -590,7 +774,7 @@ static int ohci_int_in_start(unsigned int ctrl, unsigned int slot,
 
 
 	if (ctrl >= n_ctrls || slot >= USB_HCD_INT_SLOTS)
 	if (ctrl >= n_ctrls || slot >= USB_HCD_INT_SLOTS)
 		return -1;
 		return -1;
-	c = &ctrls[ctrl];
+	c = &dma->ctrls[ctrl];
 
 
 	ohci_int_in_stop(slot);
 	ohci_int_in_stop(slot);
 
 
@@ -614,19 +798,24 @@ static int ohci_int_in_poll(unsigned int slot, unsigned char *buf,
 	if (slot >= USB_HCD_INT_SLOTS)
 	if (slot >= USB_HCD_INT_SLOTS)
 		return 0;
 		return 0;
 	for (i = 0; i < n_ctrls; i++) {
 	for (i = 0; i < n_ctrls; i++) {
-		if (ctrls[i].int_armed[slot]) {
-			c = &ctrls[i];
+		if (dma->ctrls[i].int_armed[slot]) {
+			c = &dma->ctrls[i];
 			break;
 			break;
 		}
 		}
 	}
 	}
 	if (!c)
 	if (!c)
 		return 0;
 		return 0;
 
 
+	ohci_ack_done(c);
+	ohci_barrier();
 	cc = (c->int_td[slot].flags & TD_CC_MASK) >> TD_CC_SHIFT;
 	cc = (c->int_td[slot].flags & TD_CC_MASK) >> TD_CC_SHIFT;
 	if (cc == TD_NOTACCESSED) {
 	if (cc == TD_NOTACCESSED) {
 		if (c->int_ed[slot].head & ED_H) {
 		if (c->int_ed[slot].head & ED_H) {
 			/* Halted by the controller without a CC update:
 			/* Halted by the controller without a CC update:
 			   clear it and stay armed. */
 			   clear it and stay armed. */
+			serial_puts(SERIAL_COM1, "ohci: int halt slot ");
+			serial_putdec(SERIAL_COM1, slot);
+			serial_puts(SERIAL_COM1, "\n");
 			ohci_int_arm(c, slot);
 			ohci_int_arm(c, slot);
 			return -1;
 			return -1;
 		}
 		}
@@ -634,6 +823,11 @@ static int ohci_int_in_poll(unsigned int slot, unsigned char *buf,
 	}
 	}
 	if (cc != 0) {
 	if (cc != 0) {
 		/* Report the error but stay armed (toggle preserved). */
 		/* Report the error but stay armed (toggle preserved). */
+		serial_puts(SERIAL_COM1, "ohci: int err slot ");
+		serial_putdec(SERIAL_COM1, slot);
+		serial_puts(SERIAL_COM1, " cc ");
+		serial_putdec(SERIAL_COM1, cc);
+		serial_puts(SERIAL_COM1, "\n");
 		ohci_int_arm(c, slot);
 		ohci_int_arm(c, slot);
 		return -1;
 		return -1;
 	}
 	}
@@ -658,13 +852,14 @@ static void ohci_int_in_stop(unsigned int slot)
 	if (slot >= USB_HCD_INT_SLOTS)
 	if (slot >= USB_HCD_INT_SLOTS)
 		return;
 		return;
 	for (i = 0; i < n_ctrls; i++) {
 	for (i = 0; i < n_ctrls; i++) {
-		struct ohci_ctrl *c = &ctrls[i];
+		struct ohci_ctrl *c = &dma->ctrls[i];
 
 
 		if (!c->int_armed[slot])
 		if (!c->int_armed[slot])
 			continue;
 			continue;
 		c->int_armed[slot] = 0;
 		c->int_armed[slot] = 0;
 		c->int_ed[slot].head = (unsigned int)&c->int_dummy[slot];
 		c->int_ed[slot].head = (unsigned int)&c->int_dummy[slot];
 		c->int_ed[slot].tail = (unsigned int)&c->int_dummy[slot];
 		c->int_ed[slot].tail = (unsigned int)&c->int_dummy[slot];
+		ohci_barrier();
 	}
 	}
 }
 }
 
 

+ 55 - 2
paging.c

@@ -9,6 +9,7 @@
  */
  */
 
 
 #include "paging.h"
 #include "paging.h"
+#include "bootcon.h"
 #include "cpu.h"
 #include "cpu.h"
 #include "mm.h"
 #include "mm.h"
 #include "mtrr.h"
 #include "mtrr.h"
@@ -40,12 +41,14 @@
 #define PDE_PCD      0x010
 #define PDE_PCD      0x010
 #define PDE_PS       0x080   /* 4 MB page */
 #define PDE_PS       0x080   /* 4 MB page */
 
 
-/* How much of the LFB to map.  16 MB covers any mode up to 1280x1024x32
- * (~5 MB) with margin, and is independent of the BIOS's VRAM report. */
+/* How much of the LFB to map.  16 MB covers any mode up to 1920x1080x32
+ * (~8.3 MB) with margin, and is independent of the BIOS's VRAM report. */
 #define LFB_MAP_SIZE 0x1000000
 #define LFB_MAP_SIZE 0x1000000
 
 
 static unsigned int *page_dir;
 static unsigned int *page_dir;
 
 
+static void uc_page_cr3(unsigned int cr3, unsigned int va);
+
 static void rdmsr(unsigned int msr, unsigned int *lo, unsigned int *hi)
 static void rdmsr(unsigned int msr, unsigned int *lo, unsigned int *hi)
 {
 {
 	__asm__ volatile ("rdmsr" : "=a"(*lo), "=d"(*hi) : "c"(msr));
 	__asm__ volatile ("rdmsr" : "=a"(*lo), "=d"(*hi) : "c"(msr));
@@ -166,10 +169,12 @@ void paging_init(void)
 	unsigned int i;
 	unsigned int i;
 	const volatile struct vga_boot_fb_info *fb = VGA_BOOT_FB;
 	const volatile struct vga_boot_fb_info *fb = VGA_BOOT_FB;
 
 
+	bootcon_puts("paging: prepare\n");
 	paging_prepare_cpu();
 	paging_prepare_cpu();
 	/* Opaque asm hides the fixed 0x600 pointer from -Warray-bounds. */
 	/* Opaque asm hides the fixed 0x600 pointer from -Warray-bounds. */
 	__asm__ volatile ("" : "+r"(fb));
 	__asm__ volatile ("" : "+r"(fb));
 
 
+	bootcon_puts("paging: alloc\n");
 	page_dir = (unsigned int *)mm_alloc_page();
 	page_dir = (unsigned int *)mm_alloc_page();
 	if (!page_dir) {
 	if (!page_dir) {
 		serial_puts(SERIAL_COM1, "paging: out of memory\n");
 		serial_puts(SERIAL_COM1, "paging: out of memory\n");
@@ -188,6 +193,18 @@ void paging_init(void)
 	for (i = 0; i < MM_MAX_PHYS / 0x400000; i++)
 	for (i = 0; i < MM_MAX_PHYS / 0x400000; i++)
 		page_dir[i] = (i << 22) | PDE_PS | PDE_WRITABLE | PDE_PRESENT;
 		page_dir[i] = (i << 22) | PDE_PS | PDE_WRITABLE | PDE_PRESENT;
 
 
+	/* The OHCI ED/TD/interrupt-buffer page is DMA'd by the SB950's legacy
+	 * USB controller, which does not snoop dirty CPU cache lines.  Split
+	 * the containing 4 MB page now, before paging is enabled, so every
+	 * process directory clones the uncacheable mapping. */
+	{
+		extern unsigned char ohci_dma_page[];
+		unsigned int va = (unsigned int)ohci_dma_page;
+
+		if ((va >> 22) == 0)
+			uc_page_cr3((unsigned int)page_dir, va);
+	}
+
 	/* Identity-map the framebuffer and make VRAM writes batch.  Use the
 	/* Identity-map the framebuffer and make VRAM writes batch.  Use the
 	 * actual framebuffer size (not the whole mapping) so the WC range
 	 * actual framebuffer size (not the whole mapping) so the WC range
 	 * cannot swallow unrelated MMIO, and install the MTRR *before* choosing
 	 * cannot swallow unrelated MMIO, and install the MTRR *before* choosing
@@ -200,8 +217,10 @@ void paging_init(void)
 
 
 		if (want == 0 || want > LFB_MAP_SIZE)
 		if (want == 0 || want > LFB_MAP_SIZE)
 			want = LFB_MAP_SIZE;
 			want = LFB_MAP_SIZE;
+		bootcon_puts("paging: mtrr\n");
 		lfb_wc_ok = mtrr_set_wc(fb->lfb_base, want,
 		lfb_wc_ok = mtrr_set_wc(fb->lfb_base, want,
 					&lfb_wc_base, &lfb_wc_size);
 					&lfb_wc_base, &lfb_wc_size);
+		bootcon_puts("paging: map\n");
 		lfb_apply_pages(page_dir);
 		lfb_apply_pages(page_dir);
 		/* Tell the truth about VRAM writes: with cacheable pages the WC
 		/* Tell the truth about VRAM writes: with cacheable pages the WC
 		 * MTRR applies (fast bursts); otherwise every dword is a separate
 		 * MTRR applies (fast bursts); otherwise every dword is a separate
@@ -213,6 +232,7 @@ void paging_init(void)
 
 
 	/* Load CR3, enable PSE, then PG + WP.  The jump flushes the prefetch
 	/* Load CR3, enable PSE, then PG + WP.  The jump flushes the prefetch
 	 * queue after the paging flip. */
 	 * queue after the paging flip. */
+	bootcon_puts("paging: enable\n");
 	__asm__ volatile (
 	__asm__ volatile (
 		"movl %0, %%cr3\n\t"
 		"movl %0, %%cr3\n\t"
 		"movl %%cr4, %%eax\n\t"
 		"movl %%cr4, %%eax\n\t"
@@ -227,6 +247,7 @@ void paging_init(void)
 		: "r"((unsigned int)page_dir)
 		: "r"((unsigned int)page_dir)
 		: "eax", "memory");
 		: "eax", "memory");
 
 
+	bootcon_puts("paging: on\n");
 	serial_puts(SERIAL_COM1, "paging: enabled (identity map)\n");
 	serial_puts(SERIAL_COM1, "paging: enabled (identity map)\n");
 }
 }
 
 
@@ -400,3 +421,35 @@ void paging_map_mmio(unsigned int phys_base, unsigned int size)
 {
 {
 	paging_map_mmio_cr3((unsigned int)page_dir, phys_base, size);
 	paging_map_mmio_cr3((unsigned int)page_dir, phys_base, size);
 }
 }
+
+/* Split the 4 MB page containing `va` in one directory and set PCD on that
+ * 4 KB page.  The kernel identity map is WB; legacy OHCI DMA on the SB950
+ * does not reliably snoop dirty descriptor lines, so the ED/TD page must
+ * bypass the cache. */
+static void uc_page_cr3(unsigned int cr3, unsigned int va)
+{
+	unsigned int *pd = (unsigned int *)cr3;
+	unsigned int pde = va >> 22;
+	unsigned int pte = (va >> 12) & 0x3FFu;
+	unsigned int entry = pd[pde];
+	unsigned int *pt;
+	unsigned int i;
+
+	if (!(entry & PDE_PRESENT))
+		return;
+	if (entry & PDE_PS) {
+		unsigned int base = entry & 0xFFC00000u;
+		unsigned int flags = (entry & 0xFFFu) & ~PDE_PS;
+		unsigned int table = mm_alloc_page();
+
+		if (!table)
+			return;
+		pt = (unsigned int *)table;
+		for (i = 0; i < 1024; i++)
+			pt[i] = (base + i * 0x1000u) | flags;
+		pd[pde] = table | flags;
+	} else {
+		pt = (unsigned int *)(entry & 0xFFFFF000u);
+	}
+	pt[pte] |= PDE_PCD;
+}

+ 2 - 0
paging.h

@@ -18,6 +18,8 @@ int paging_lfb_wc(void);
  * is whatever the MTRRs say (write-combining when we added an entry). */
  * is whatever the MTRRs say (write-combining when we added an entry). */
 void paging_map_ram(unsigned int base, unsigned int size);
 void paging_map_ram(unsigned int base, unsigned int size);
 
 
+
+
 /* Physical address of the page directory currently loaded in CR3.  On SMP this
 /* Physical address of the page directory currently loaded in CR3.  On SMP this
  * is per-CPU; on one CPU it is the running process's directory. */
  * is per-CPU; on one CPU it is the running process's directory. */
 unsigned int paging_current_cr3(void);
 unsigned int paging_current_cr3(void);

+ 98 - 6
thermal.c

@@ -14,6 +14,7 @@
  */
  */
 #include "thermal.h"
 #include "thermal.h"
 #include "cpu.h"
 #include "cpu.h"
+#include "pci.h"
 #include "sched.h"
 #include "sched.h"
 #include "serial.h"
 #include "serial.h"
 #include "timer.h"
 #include "timer.h"
@@ -22,10 +23,19 @@
 #define MSR_IA32_TEMPERATURE_TARGET  0x1A2
 #define MSR_IA32_TEMPERATURE_TARGET  0x1A2
 
 
 static int thermal_state = -1;  /* -1 unprobed, 0 unsupported, 1 DTS */
 static int thermal_state = -1;  /* -1 unprobed, 0 unsupported, 1 DTS */
+static int thermal_amd;         /* 1 = AMD D18F3xA4 instead of Intel DTS */
 static int thermal_tjmax_c = 100;
 static int thermal_tjmax_c = 100;
 static unsigned int thermal_tjmax_raw;   /* last MSR 0x1A2 sample */
 static unsigned int thermal_tjmax_raw;   /* last MSR 0x1A2 sample */
 static int thermal_tjmax_msr;            /* TjMax came from the MSR */
 static int thermal_tjmax_msr;            /* TjMax came from the MSR */
 
 
+/* AMD family 15h models below 60h (Bulldozer/Piledriver/Steamroller) report
+ * Tctl in D18F3xA4: bits 31:21 are the raw temperature in 0.125 C units and
+ * bits 17:16 select the -49 C range offset (k10temp's pre-Zen path). */
+#define AMD_NB_DEV        0x18
+#define AMD_NB_FUNC       3
+#define AMD_REPORTED_TEMP 0xA4
+#define AMD_TJMAX_C       70
+
 static void cpuid_leaf(unsigned int leaf, unsigned int sub,
 static void cpuid_leaf(unsigned int leaf, unsigned int sub,
 		       unsigned int *a, unsigned int *b, unsigned int *c,
 		       unsigned int *a, unsigned int *b, unsigned int *c,
 		       unsigned int *d)
 		       unsigned int *d)
@@ -134,6 +144,30 @@ static void read_brand(char out[49])
 	}
 	}
 }
 }
 
 
+static int amd_temp_c(void)
+{
+	unsigned int id, val, raw, mc;
+
+	id = pci_cfg_read32(0, AMD_NB_DEV, AMD_NB_FUNC, 0x00);
+	if (id == 0xFFFFFFFFu || id == 0)
+		return -1;
+	val = pci_cfg_read32(0, AMD_NB_DEV, AMD_NB_FUNC, AMD_REPORTED_TEMP);
+	if (val == 0xFFFFFFFFu || val == 0)
+		return -1;
+	raw = (val >> 21) & 0x7FFu;
+	if (raw == 0 || raw == 0x7FFu)
+		return -1;
+	mc = raw * 125u;
+	if ((val & 0x30000u) == 0x30000u) {
+		if (mc < 49000u)
+			return -1;
+		mc -= 49000u;
+	}
+	if (mc > 125000u)
+		return -1;
+	return (int)((mc + 500u) / 1000u);
+}
+
 static int pick_tjmax(unsigned int model, unsigned int stepping,
 static int pick_tjmax(unsigned int model, unsigned int stepping,
 		      const char *brand)
 		      const char *brand)
 {
 {
@@ -162,6 +196,7 @@ void thermal_init(void)
 	int msr_probed = 0;
 	int msr_probed = 0;
 
 
 	thermal_state = 0;
 	thermal_state = 0;
+	thermal_amd = 0;
 	thermal_tjmax_c = 100;
 	thermal_tjmax_c = 100;
 	if (!cpu_has_cpuid())
 	if (!cpu_has_cpuid())
 		goto out;
 		goto out;
@@ -171,12 +206,10 @@ void thermal_init(void)
 	((unsigned int *)vendor)[1] = d;
 	((unsigned int *)vendor)[1] = d;
 	((unsigned int *)vendor)[2] = c;
 	((unsigned int *)vendor)[2] = c;
 	vendor[12] = '\0';
 	vendor[12] = '\0';
-	if (!str_eq(vendor, "GenuineIntel") || max_leaf < 1)
+	if (max_leaf < 1)
 		goto out;
 		goto out;
 
 
 	cpuid_leaf(1, 0, &a, &b, &c, &d);
 	cpuid_leaf(1, 0, &a, &b, &c, &d);
-	if (!(d & (1u << 5)))          /* MSR support */
-		goto out;
 	family = (a >> 8) & 0xF;
 	family = (a >> 8) & 0xF;
 	model = (a >> 4) & 0xF;
 	model = (a >> 4) & 0xF;
 	stepping = a & 0xF;
 	stepping = a & 0xF;
@@ -184,6 +217,25 @@ void thermal_init(void)
 		family += (a >> 20) & 0xFF;
 		family += (a >> 20) & 0xFF;
 	if (family == 0x6 || family == 0xF)
 	if (family == 0x6 || family == 0xF)
 		model += ((a >> 16) & 0xF) << 4;
 		model += ((a >> 16) & 0xF) << 4;
+
+	if (str_eq(vendor, "AuthenticAMD")) {
+		int t;
+
+		if (family != 0x15 || model >= 0x60)
+			goto out;
+		t = amd_temp_c();
+		if (t < -20 || t > 125)
+			goto out;
+		thermal_tjmax_c = AMD_TJMAX_C;
+		thermal_amd = 1;
+		thermal_state = 1;
+		goto out;
+	}
+
+	if (!str_eq(vendor, "GenuineIntel"))
+		goto out;
+	if (!(d & (1u << 5)))          /* MSR support */
+		goto out;
 	if (family != 0x6 || !model_has_dts(model))
 	if (family != 0x6 || !model_has_dts(model))
 		goto out;
 		goto out;
 	if (max_leaf < 6)
 	if (max_leaf < 6)
@@ -209,7 +261,12 @@ void thermal_init(void)
 	thermal_state = 1;
 	thermal_state = 1;
 
 
 out:
 out:
-	if (thermal_state) {
+	if (thermal_state && thermal_amd) {
+		serial_puts(SERIAL_COM1,
+			    "thermal: AMD family 15h, D18F3xA4, TjMax ");
+		serial_putdec(SERIAL_COM1, (unsigned int)thermal_tjmax_c);
+		serial_puts(SERIAL_COM1, " C\n");
+	} else if (thermal_state) {
 		serial_puts(SERIAL_COM1, "thermal: Intel DTS, model ");
 		serial_puts(SERIAL_COM1, "thermal: Intel DTS, model ");
 		serial_putdec(SERIAL_COM1, model);
 		serial_putdec(SERIAL_COM1, model);
 		serial_puts(SERIAL_COM1, " stepping ");
 		serial_puts(SERIAL_COM1, " stepping ");
@@ -227,7 +284,8 @@ out:
 		}
 		}
 		serial_puts(SERIAL_COM1, "\n");
 		serial_puts(SERIAL_COM1, "\n");
 	} else {
 	} else {
-		serial_puts(SERIAL_COM1, "thermal: no Intel DTS, disabled\n");
+		serial_puts(SERIAL_COM1,
+			    "thermal: no supported temperature sensor, disabled\n");
 	}
 	}
 }
 }
 
 
@@ -236,6 +294,12 @@ int thermal_read_this_cpu(void)
 	unsigned int raw;
 	unsigned int raw;
 	int t;
 	int t;
 
 
+	if (thermal_state < 0)
+		thermal_init();
+	if (!thermal_state)
+		return -1;
+	if (thermal_amd)
+		return amd_temp_c();
 	if (thermal_status_this_cpu(&raw) != 0)
 	if (thermal_status_this_cpu(&raw) != 0)
 		return -1;
 		return -1;
 	t = thermal_tjmax_c - (int)((raw >> 16) & 0x7F);
 	t = thermal_tjmax_c - (int)((raw >> 16) & 0x7F);
@@ -250,7 +314,7 @@ int thermal_status_this_cpu(unsigned int *status)
 
 
 	if (thermal_state < 0)
 	if (thermal_state < 0)
 		thermal_init();
 		thermal_init();
-	if (!thermal_state)
+	if (!thermal_state || thermal_amd)
 		return -1;
 		return -1;
 	__asm__ volatile ("rdmsr" : "=a"(lo), "=d"(hi)
 	__asm__ volatile ("rdmsr" : "=a"(lo), "=d"(hi)
 			  : "c"(MSR_IA32_THERM_STATUS));
 			  : "c"(MSR_IA32_THERM_STATUS));
@@ -265,6 +329,11 @@ void thermal_tick(void)
 	struct cpu *c = this_cpu();
 	struct cpu *c = this_cpu();
 	unsigned int ms = (c->id == 0) ? timer_tick_ms() : c->tick_ms;
 	unsigned int ms = (c->id == 0) ? timer_tick_ms() : c->tick_ms;
 
 
+	if (thermal_state < 0)
+		thermal_init();
+	if (!thermal_state || thermal_amd)
+		return;
+
 	/* The timer period drops to 10 ms while a CPU is idle, so count
 	/* The timer period drops to 10 ms while a CPU is idle, so count
 	 * milliseconds rather than ticks to keep the 1 Hz sample rate. */
 	 * milliseconds rather than ticks to keep the 1 Hz sample rate. */
 	if ((c->temp_div += ms) < 1000)
 	if ((c->temp_div += ms) < 1000)
@@ -273,6 +342,29 @@ void thermal_tick(void)
 	c->temp_c = thermal_read_this_cpu();
 	c->temp_c = thermal_read_this_cpu();
 }
 }
 
 
+void thermal_housekeeping(void)
+{
+	static unsigned int last_ms;
+	unsigned int now, i;
+	int t;
+
+	if (thermal_state < 0)
+		thermal_init();
+	if (!thermal_state || !thermal_amd)
+		return;
+
+	now = get_ticks_ms();
+	if (last_ms && now - last_ms < 1000)
+		return;
+	last_ms = now;
+
+	/* D18F3xA4 is a package/northbridge value, not per core.  Publish it
+	 * to every CPU so thermal_max_c() and the top bar see it. */
+	t = amd_temp_c();
+	for (i = 0; i < cpu_count && i < MAX_CPUS; i++)
+		cpus[i].temp_c = t;
+}
+
 int thermal_max_c(void)
 int thermal_max_c(void)
 {
 {
 	int max = -1;
 	int max = -1;

+ 12 - 4
thermal.h

@@ -1,4 +1,4 @@
-/* Intel digital thermal sensor (DTS) access. */
+/* CPU temperature sources: Intel DTS and AMD family 15h D18F3xA4. */
 #ifndef THERMAL_H
 #ifndef THERMAL_H
 #define THERMAL_H
 #define THERMAL_H
 
 
@@ -6,13 +6,21 @@
 void thermal_init(void);
 void thermal_init(void);
 
 
 /* Sample this CPU's DTS.  Called from the per-CPU scheduler tick, at most
 /* Sample this CPU's DTS.  Called from the per-CPU scheduler tick, at most
- * once per second. */
+ * once per second.  The AMD package sensor is sampled from the kworker
+ * instead (under the BKL; PCI config space is not safe to touch from a
+ * timer interrupt on multiple CPUs). */
 void thermal_tick(void);
 void thermal_tick(void);
 
 
-/* Read this CPU's DTS now: degrees C, or -1 when unavailable. */
+/* Once-a-second AMD package sensor poll; called from system_housekeeping()
+ * under the BKL.  A no-op on Intel and when no sensor was found. */
+void thermal_housekeeping(void);
+
+/* Read this CPU's temperature now: degrees C, or -1 when unavailable.
+ * On AMD this reads the package sensor, so all CPUs report the same value. */
 int thermal_read_this_cpu(void);
 int thermal_read_this_cpu(void);
 
 
-/* Read this CPU's raw IA32_THERM_STATUS: 0 on success, -1 when unavailable. */
+/* Read this CPU's raw IA32_THERM_STATUS (Intel only): 0 on success, -1 when
+ * unavailable. */
 int thermal_status_this_cpu(unsigned int *status);
 int thermal_status_this_cpu(unsigned int *status);
 
 
 /* Hottest per-CPU reading cached by the ticks, or -1 when unavailable. */
 /* Hottest per-CPU reading cached by the ticks, or -1 when unavailable. */

+ 1 - 1
ucmd_cpuinfo.c

@@ -300,7 +300,7 @@ void _start(void)
 			put_uint((unsigned int)ct.tjmax_c);
 			put_uint((unsigned int)ct.tjmax_c);
 			u_puts(" C)\n");
 			u_puts(" C)\n");
 		} else {
 		} else {
-			u_puts("temp unavailable (no Intel DTS)\n");
+			u_puts("temp unavailable (no supported sensor)\n");
 		}
 		}
 	}
 	}
 	u_puts("eist ");
 	u_puts("eist ");

+ 3 - 3
ucmd_sensors.c

@@ -1,4 +1,4 @@
-/* sensors: CPU DTS plus the board's hardware monitor.
+/* sensors: CPU temperature plus the board's hardware monitor.
  *
  *
  * Board sources: the IT87xx Super I/O (AT3IONT-I, three temperatures and fan
  * Board sources: the IT87xx Super I/O (AT3IONT-I, three temperatures and fan
  * tachometers), the ThinkPad embedded controller (X201, temperatures at EC
  * tachometers), the ThinkPad embedded controller (X201, temperatures at EC
@@ -53,9 +53,9 @@ static void show_dts(void)
 	struct sys_cputemp ct;
 	struct sys_cputemp ct;
 	unsigned int i;
 	unsigned int i;
 
 
-	u_puts("dts ");
+	u_puts("cpu ");
 	if (u_cpu_temp(&ct) != 0 || ct.temp_c < 0) {
 	if (u_cpu_temp(&ct) != 0 || ct.temp_c < 0) {
-		u_puts("unavailable (no Intel DTS)\n");
+		u_puts("unavailable (no supported sensor)\n");
 		return;
 		return;
 	}
 	}
 	u_puts("max ");
 	u_puts("max ");

+ 123 - 40
usb.c

@@ -5,6 +5,7 @@
 #include "io.h"
 #include "io.h"
 #include "process.h"
 #include "process.h"
 #include "sched.h"
 #include "sched.h"
+#include "serial.h"
 #include "timer.h"
 #include "timer.h"
 #include "usb.h"
 #include "usb.h"
 #include "usb_hcd.h"
 #include "usb_hcd.h"
@@ -337,11 +338,28 @@ int usb_control_out_data(unsigned int ctrl, unsigned int addr,
 				     len, 0);
 				     len, 0);
 }
 }
 
 
+/* Always-on failure trail (COM1/netmon): a device that never enumerates
+   must not be silent, since boot-time input may depend on it. */
+static void usb_fail(const char *what, unsigned int ctrl, unsigned int port,
+		     unsigned int addr)
+{
+	serial_puts(SERIAL_COM1, "usb: ");
+	serial_puts(SERIAL_COM1, what);
+	serial_puts(SERIAL_COM1, " ctrl ");
+	serial_putdec(SERIAL_COM1, ctrl);
+	serial_puts(SERIAL_COM1, " port ");
+	serial_putdec(SERIAL_COM1, port);
+	serial_puts(SERIAL_COM1, " addr ");
+	serial_putdec(SERIAL_COM1, addr);
+	serial_putc(SERIAL_COM1, '\n');
+}
+
 /* Read the configuration descriptor and hand every interface with an
 /* Read the configuration descriptor and hand every interface with an
-   interrupt-IN endpoint to the active probe. */
-static void probe_config(unsigned int ctrl, unsigned int addr, unsigned int mps,
-			 int low, unsigned int port, unsigned int vendor,
-			 unsigned int product)
+   interrupt-IN endpoint to the active probe.  Returns 1 when the device
+   answered and its configuration was parsed. */
+static int probe_config(unsigned int ctrl, unsigned int addr, unsigned int mps,
+			int low, unsigned int port, unsigned int vendor,
+			unsigned int product)
 {
 {
 	struct usb_iface_info info;
 	struct usb_iface_info info;
 	unsigned int total, i;
 	unsigned int total, i;
@@ -351,20 +369,20 @@ static void probe_config(unsigned int ctrl, unsigned int addr, unsigned int mps,
 			   REQ_GET_DESCRIPTOR,
 			   REQ_GET_DESCRIPTOR,
 			   (unsigned short)(DESC_CONFIG << 8), 0,
 			   (unsigned short)(DESC_CONFIG << 8), 0,
 			   conf_hdr, 9) < 0) {
 			   conf_hdr, 9) < 0) {
-		dbg("usb:   config descriptor header failed\n");
-		return;
+		usb_fail("config header failed", ctrl, port, addr);
+		return 0;
 	}
 	}
 	total = (unsigned int)conf_hdr[2] | ((unsigned int)conf_hdr[3] << 8);
 	total = (unsigned int)conf_hdr[2] | ((unsigned int)conf_hdr[3] << 8);
 	if (total < 9)
 	if (total < 9)
-		return;
+		return 0;
 	if (total > USB_CONFIG_MAX)
 	if (total > USB_CONFIG_MAX)
 		total = USB_CONFIG_MAX;
 		total = USB_CONFIG_MAX;
 	if (usb_control_in(ctrl, addr, mps, low, RT_DEV2HOST_STD,
 	if (usb_control_in(ctrl, addr, mps, low, RT_DEV2HOST_STD,
 			   REQ_GET_DESCRIPTOR,
 			   REQ_GET_DESCRIPTOR,
 			   (unsigned short)(DESC_CONFIG << 8), 0,
 			   (unsigned short)(DESC_CONFIG << 8), 0,
 			   conf_buf, total) < 0) {
 			   conf_buf, total) < 0) {
-		dbg("usb:   config descriptor read failed\n");
-		return;
+		usb_fail("config read failed", ctrl, port, addr);
+		return 0;
 	}
 	}
 	dbg_dec("usb:   config descriptor len ", total);
 	dbg_dec("usb:   config descriptor len ", total);
 
 
@@ -445,19 +463,20 @@ static void probe_config(unsigned int ctrl, unsigned int addr, unsigned int mps,
 	}
 	}
 	if (have_iface && info.ep_addr && current_probe)
 	if (have_iface && info.ep_addr && current_probe)
 		current_probe(&info);
 		current_probe(&info);
+	return 1;
 }
 }
 
 
 static void enumerate_hub(unsigned int ctrl, unsigned int addr, unsigned int mps,
 static void enumerate_hub(unsigned int ctrl, unsigned int addr, unsigned int mps,
 			  int low, unsigned int port, unsigned int depth);
 			  int low, unsigned int port, unsigned int depth);
-static void enumerate_device(unsigned int ctrl, unsigned int addr,
-			     unsigned int mps, int low, unsigned int port,
-			     unsigned int depth);
-static void enumerate_new_device(unsigned int ctrl, unsigned int port, int low,
-				 unsigned int depth);
-
-static void enumerate_device(unsigned int ctrl, unsigned int addr,
-			     unsigned int mps, int low, unsigned int port,
-			     unsigned int depth)
+static int enumerate_device(unsigned int ctrl, unsigned int addr,
+			    unsigned int mps, int low, unsigned int port,
+			    unsigned int depth);
+static int enumerate_new_device(unsigned int ctrl, unsigned int port, int low,
+				unsigned int depth);
+
+static int enumerate_device(unsigned int ctrl, unsigned int addr,
+			    unsigned int mps, int low, unsigned int port,
+			    unsigned int depth)
 {
 {
 	unsigned int vendor, product, cls, subcls, proto;
 	unsigned int vendor, product, cls, subcls, proto;
 
 
@@ -465,12 +484,12 @@ static void enumerate_device(unsigned int ctrl, unsigned int addr,
 			   REQ_GET_DESCRIPTOR,
 			   REQ_GET_DESCRIPTOR,
 			   (unsigned short)(DESC_DEVICE << 8), 0,
 			   (unsigned short)(DESC_DEVICE << 8), 0,
 			   dev_desc, 18) < 0) {
 			   dev_desc, 18) < 0) {
-		dbg("usb:   device descriptor read failed\n");
+		usb_fail("device descriptor failed", ctrl, port, addr);
 		if (print_devices) {
 		if (print_devices) {
 			indent(depth);
 			indent(depth);
 			io_putstr("(device descriptor read failed)\n");
 			io_putstr("(device descriptor read failed)\n");
 		}
 		}
-		return;
+		return 0;
 	}
 	}
 
 
 	vendor  = dev_desc[8]  | ((unsigned int)dev_desc[9]  << 8);
 	vendor  = dev_desc[8]  | ((unsigned int)dev_desc[9]  << 8);
@@ -509,11 +528,15 @@ static void enumerate_device(unsigned int ctrl, unsigned int addr,
 		io_putstr("]\n");
 		io_putstr("]\n");
 	}
 	}
 
 
-	if ((current_probe || print_devices) && cls != 0x09)
-		probe_config(ctrl, addr, mps, low, port, vendor, product);
-
-	if (cls == 0x09)
+	if (cls == 0x09) {
 		enumerate_hub(ctrl, addr, mps, low, port, depth + 1);
 		enumerate_hub(ctrl, addr, mps, low, port, depth + 1);
+		return 1;
+	}
+
+	if (current_probe || print_devices)
+		return probe_config(ctrl, addr, mps, low, port, vendor, product);
+
+	return 1;
 }
 }
 
 
 static void enumerate_hub(unsigned int ctrl, unsigned int addr, unsigned int mps,
 static void enumerate_hub(unsigned int ctrl, unsigned int addr, unsigned int mps,
@@ -637,8 +660,8 @@ static void enumerate_hub(unsigned int ctrl, unsigned int addr, unsigned int mps
 	}
 	}
 }
 }
 
 
-static void enumerate_new_device(unsigned int ctrl, unsigned int port, int low,
-				 unsigned int depth)
+static int enumerate_new_device(unsigned int ctrl, unsigned int port, int low,
+				unsigned int depth)
 {
 {
 	unsigned int mps;
 	unsigned int mps;
 	unsigned int addr = next_addr[ctrl];
 	unsigned int addr = next_addr[ctrl];
@@ -648,38 +671,48 @@ static void enumerate_new_device(unsigned int ctrl, unsigned int port, int low,
 			indent(depth);
 			indent(depth);
 			io_putstr("(too many devices)\n");
 			io_putstr("(too many devices)\n");
 		}
 		}
-		return;
+		return 0;
 	}
 	}
 
 
+	/* Some low/full-speed devices need a little more settle time after
+	 * the port reset than the OHCI spec's 10 ms.  Without this the 970A's
+	 * OHCI mouse was intermittently dropped before its first control
+	 * transfer. */
+	msleep(20);
+
 	/* Traditional ("old") enumeration scheme: assign the address before
 	/* Traditional ("old") enumeration scheme: assign the address before
 	 * reading the descriptor.  The xHCI Default-state EP0 transfer is
 	 * reading the descriptor.  The xHCI Default-state EP0 transfer is
 	 * unreliable on this hardware, while a slot in the Addressed state
 	 * unreliable on this hardware, while a slot in the Addressed state
-	 * works.  The device's real max packet size is not known yet, so the
-	 * high/full-speed guess is 64 (low speed is always 8). */
-	mps = low ? 8 : 64;
+	 * works.  The device's real max packet size is not known yet, so use
+	 * the default 8-byte pipe for the first SET_ADDRESS/GET_DESCRIPTOR.
+	 * A full-speed device may have an 8-byte EP0 (the 64-byte guess made
+	 * the 970A's OHCI drop a mouse during descriptor read), and a
+	 * high-speed device accepts the short transfer and reports its real
+	 * bMaxPacketSize0 in the descriptor. */
+	mps = 8;
 	if (usb_control_out(ctrl, 0, mps, low, RT_HOST2DEV_STD,
 	if (usb_control_out(ctrl, 0, mps, low, RT_HOST2DEV_STD,
 			    REQ_SET_ADDRESS, (unsigned short)addr, 0) < 0) {
 			    REQ_SET_ADDRESS, (unsigned short)addr, 0) < 0) {
-		dbg("usb:   SET_ADDRESS failed\n");
+		usb_fail("SET_ADDRESS failed", ctrl, port, 0);
 		if (print_devices) {
 		if (print_devices) {
 			indent(depth);
 			indent(depth);
 			io_putstr("(SET_ADDRESS failed)\n");
 			io_putstr("(SET_ADDRESS failed)\n");
 		}
 		}
-		return;
+		return 0;
 	}
 	}
 	next_addr[ctrl] = addr + 1;
 	next_addr[ctrl] = addr + 1;
-	msleep(5);
+	msleep(20);
 
 
 	/* First 8 bytes at the assigned address (learn max packet size). */
 	/* First 8 bytes at the assigned address (learn max packet size). */
 	if (usb_control_in(ctrl, addr, mps, low, RT_DEV2HOST_STD,
 	if (usb_control_in(ctrl, addr, mps, low, RT_DEV2HOST_STD,
 			   REQ_GET_DESCRIPTOR,
 			   REQ_GET_DESCRIPTOR,
 			   (unsigned short)(DESC_DEVICE << 8), 0,
 			   (unsigned short)(DESC_DEVICE << 8), 0,
 			   desc8, 8) < 0) {
 			   desc8, 8) < 0) {
-		dbg("usb:   no response at the assigned address\n");
+		usb_fail("descriptor8 failed", ctrl, port, addr);
 		if (print_devices) {
 		if (print_devices) {
 			indent(depth);
 			indent(depth);
 			io_putstr("(device descriptor read failed)\n");
 			io_putstr("(device descriptor read failed)\n");
 		}
 		}
-		return;
+		return 0;
 	}
 	}
 
 
 	mps = desc8[7];
 	mps = desc8[7];
@@ -687,7 +720,30 @@ static void enumerate_new_device(unsigned int ctrl, unsigned int port, int low,
 		mps = 8;
 		mps = 8;
 
 
 	dbg_dec("usb:   enumerated device, addr ", addr);
 	dbg_dec("usb:   enumerated device, addr ", addr);
-	enumerate_device(ctrl, addr, mps, low, port, depth);
+	return enumerate_device(ctrl, addr, mps, low, port, depth);
+}
+
+/* A port reset hands the device to its companion controller, and the first
+ * control transfer after it is occasionally ignored by the SB950 OHCI
+ * (every TD stays NotAccessed for the full 2 s timeout).  A fresh port
+ * reset and a short settle makes the retry work, so keep trying a couple
+ * of times instead of leaving the port without a device until the next
+ * connect-change. */
+static int enum_port_retry(unsigned int ctrl, unsigned int port,
+			   const struct usb_hcd_ops *ops, unsigned int local)
+{
+	unsigned int try;
+
+	for (try = 0;; try++) {
+		if (enumerate_new_device(ctrl, port,
+					 ops->port_low_speed(local, port), 1))
+			return 1;
+		if (try >= 2)
+			return 0;
+		msleep(30);
+		if (ops->port_reset(local, port) != 0)
+			return 0;
+	}
 }
 }
 
 
 static void add_ctrl(const struct usb_hcd_ops *ops, unsigned int count)
 static void add_ctrl(const struct usb_hcd_ops *ops, unsigned int count)
@@ -836,6 +892,7 @@ int usb_bulk_supported(unsigned int ctrl)
 int usb_scan(usb_probe_fn probe)
 int usb_scan(usb_probe_fn probe)
 {
 {
 	unsigned int c, p;
 	unsigned int c, p;
+	unsigned int seen[USB_MAX_CTRL];
 
 
 	if (scan_busy || usb_bus_claim() != 0)
 	if (scan_busy || usb_bus_claim() != 0)
 		return -2;
 		return -2;
@@ -852,6 +909,8 @@ int usb_scan(usb_probe_fn probe)
 	generation++;
 	generation++;
 	current_probe = probe;
 	current_probe = probe;
 	print_devices = (probe == 0);
 	print_devices = (probe == 0);
+	for (c = 0; c < USB_MAX_CTRL; c++)
+		seen[c] = 0;
 
 
 	for (c = 0; c < n_usb_ctrls; c++) {
 	for (c = 0; c < n_usb_ctrls; c++) {
 		const struct usb_hcd_ops *ops = usb_ctrls[c].ops;
 		const struct usb_hcd_ops *ops = usb_ctrls[c].ops;
@@ -892,8 +951,8 @@ int usb_scan(usb_probe_fn probe)
 				continue;
 				continue;
 			}
 			}
 			dbg("usb:   port reset ok\n");
 			dbg("usb:   port reset ok\n");
-			enumerate_new_device(c, p,
-					     ops->port_low_speed(local, p), 1);
+			if (enum_port_retry(c, p, ops, local) && p < 32)
+				seen[c] |= 1u << p;
 		}
 		}
 
 
 		if (print_devices && ops->print_ports) {
 		if (print_devices && ops->print_ports) {
@@ -902,6 +961,31 @@ int usb_scan(usb_probe_fn probe)
 		}
 		}
 	}
 	}
 
 
+	/* EHCI is scanned first so it can hand low/full-speed devices back to
+	 * their OHCI companion.  That handback can leave the companion port
+	 * briefly reporting "disconnected" exactly while the OHCI pass runs
+	 * (the 970A's mouse was missed that way).  A delayed second OHCI-only
+	 * pass catches ports that stayed connected but produced no device. */
+	msleep(60);
+	for (c = 0; c < n_usb_ctrls; c++) {
+		const struct usb_hcd_ops *ops = usb_ctrls[c].ops;
+		unsigned int local = usb_ctrls[c].local;
+
+		if (ops != &usb_ohci_ops)
+			continue;
+		for (p = 0; p < ops->port_count(local) && p < 32; p++) {
+			if (seen[c] & (1u << p))
+				continue;
+			if (!ops->port_connected(local, p))
+				continue;
+			ops->port_take_change(local, p);
+			if (ops->port_reset(local, p) != 0)
+				continue;
+			dbg("usb:   companion retry\n");
+			enum_port_retry(c, p, ops, local);
+		}
+	}
+
 	current_probe = 0;
 	current_probe = 0;
 	print_devices = 0;
 	print_devices = 0;
 	scan_busy = 0;
 	scan_busy = 0;
@@ -937,8 +1021,7 @@ int usb_hotplug_poll(usb_probe_fn probe)
 				continue;
 				continue;
 			if (ops->port_reset(local, p) != 0)
 			if (ops->port_reset(local, p) != 0)
 				continue;
 				continue;
-			enumerate_new_device(c, p,
-					     ops->port_low_speed(local, p), 1);
+			enum_port_retry(c, p, ops, local);
 			n++;
 			n++;
 		}
 		}
 	}
 	}

+ 14 - 2
usbhid.c

@@ -44,6 +44,7 @@ struct hid_dev {
 	unsigned int ctrl, addr, ep, mps, port;
 	unsigned int ctrl, addr, ep, mps, port;
 	int low;
 	int low;
 	unsigned int err;         /* consecutive transfer errors */
 	unsigned int err;         /* consecutive transfer errors */
+	unsigned int disc;        /* consecutive "port disconnected" reads */
 	/* keyboard report-diff state */
 	/* keyboard report-diff state */
 	unsigned char prev[6];
 	unsigned char prev[6];
 	unsigned char prev_mod;
 	unsigned char prev_mod;
@@ -267,6 +268,7 @@ static void dev_attach(struct hid_dev *d, unsigned int slot)
 	if (usb_int_in_start(d->ctrl, slot, d->addr, d->ep, d->mps, d->low) != 0)
 	if (usb_int_in_start(d->ctrl, slot, d->addr, d->ep, d->mps, d->low) != 0)
 		return;
 		return;
 	d->err = 0;
 	d->err = 0;
+	d->disc = 0;
 	d->present = 1;
 	d->present = 1;
 	d->prev_mod = 0;
 	d->prev_mod = 0;
 	for (i = 0; i < 6; i++)
 	for (i = 0; i < 6; i++)
@@ -288,6 +290,10 @@ static void dev_detach(struct hid_dev *d, unsigned int slot)
 	usb_int_in_stop(slot);
 	usb_int_in_stop(slot);
 	d->present = 0;
 	d->present = 0;
 	d->claimed = 0;
 	d->claimed = 0;
+	/* A false port-loss leaves the device attached but unreachable (no
+	 * CSC to wake the hotplug watcher).  A clean full rescan re-arms
+	 * everything, and is the only reliable recovery on this SB950. */
+	need_rescan = 1;
 	last_watch = get_ticks_ms() - WATCH_MS;   /* watch again soon */
 	last_watch = get_ticks_ms() - WATCH_MS;   /* watch again soon */
 	serial_puts(SERIAL_COM1, d->kind == KIND_MOUSE
 	serial_puts(SERIAL_COM1, d->kind == KIND_MOUSE
 				   ? "usbhid: mouse detached (addr "
 				   ? "usbhid: mouse detached (addr "
@@ -365,13 +371,19 @@ static int dev_poll(struct hid_dev *d, unsigned int slot, unsigned char *buf,
 
 
 	if (!d->present)
 	if (!d->present)
 		return 0;
 		return 0;
+	/* CCS can glitch for a frame on the SB950; a single read must not
+	 * detach a working device.  Require three consecutive misses. */
 	if (d->port != 0xFFu && !usb_port_connected(d->ctrl, d->port)) {
 	if (d->port != 0xFFu && !usb_port_connected(d->ctrl, d->port)) {
-		dev_detach(d, slot);
+		if (++d->disc >= 3)
+			dev_detach(d, slot);
 		return 0;
 		return 0;
 	}
 	}
+	d->disc = 0;
 	n = usb_int_in_poll(slot, buf, len);
 	n = usb_int_in_poll(slot, buf, len);
 	if (n < 0) {
 	if (n < 0) {
-		if (++d->err >= 5)
+		/* The HCD re-arms on every error; a short burst is normal on
+		 * a marginal low-speed link and must not kill the device. */
+		if (++d->err >= 50)
 			dev_detach(d, slot);
 			dev_detach(d, slot);
 		return 0;
 		return 0;
 	}
 	}

+ 21 - 2
vesa_stage.S

@@ -279,8 +279,9 @@ walk_modes:
 	cmpb  $16, 0x2219
 	cmpb  $16, 0x2219
 	jb    walk_modes
 	jb    walk_modes
 
 
-	/* TODO: Remove this width cap when display scaling is improved. */
-	cmpw  $1280, 0x2212
+	/* 1920x1080x32 fits the 8 MB shadow reserve and the 4 MB window
+	 * canvas slot; wider modes would need a larger shadow. */
+	cmpw  $1920, 0x2212
 	ja    walk_modes
 	ja    walk_modes
 
 
 	/* Check: fits in VRAM. */
 	/* Check: fits in VRAM. */
@@ -292,6 +293,24 @@ walk_modes:
 2:	cmpw  vram_64k, %dx
 2:	cmpw  vram_64k, %dx
 	ja    walk_modes
 	ja    walk_modes
 
 
+	/* Keep the 32bpp shadow inside the 8 MB reserve at 0x100000:
+	 * pitch * height must not exceed 8 MB.  This rejects 1920x1200
+	 * (9.2 MB) while allowing 1920x1080 (8.29 MB). */
+	movzwl 0x2210, %eax	/* bytes per scanline */
+	movzwl 0x2214, %edx	/* height */
+	imull %edx, %eax
+	cmpl  $0x800000, %eax
+	ja    walk_modes
+
+	/* The WM maps every window's RGB565 canvas in a 4 MB slot.  A
+	 * 1920x1200 canvas needs 4.6 MB, so cap the mode at 2 M pixels
+	 * (1920x1080 = 2.07 M fits). */
+	movzwl 0x2212, %eax	/* width */
+	movzwl 0x2214, %edx	/* height */
+	imull %edx, %eax
+	cmpl  $0x200000, %eax
+	ja    walk_modes
+
 	/* Score = width * height + bpp. */
 	/* Score = width * height + bpp. */
 	movzwl 0x2212, %eax
 	movzwl 0x2212, %eax
 	movzwl 0x2214, %edx
 	movzwl 0x2214, %edx

+ 3 - 1
vga.c

@@ -815,7 +815,9 @@ void vga_fb_flush(void)
 
 
 int vga_fb_lfb_wc(void)
 int vga_fb_lfb_wc(void)
 {
 {
-	return lfb_is_wc;
+	/* `lfb_is_wc` only tracks the ION stolen-VRAM alias; the normal
+	 * MTRR-backed path is recorded in paging.c.  Report either. */
+	return lfb_is_wc || paging_lfb_wc();
 }
 }
 
 
 int vga_shadow_is_active(void)
 int vga_shadow_is_active(void)

Некоторые файлы не были показаны из-за большого количества измененных файлов