Explorar el Código

kernel: Yoga 720 bring-up (touchpad, power, 8265 WiFi)

Fix the boot freeze on serial-less machines: detect an absent COM1 instead
of draining 0xFF every PIT tick, initialize the BSP LAPIC before sti and EOI
the LAPIC from the PIC stubs.

Add the Synaptics 06CB:7F8F touchpad on Sunrise Point-LP LPSS I2C0: enable
the PCI function's memory decode and D0 state, release the LPSS function
reset before reading the DesignWare component type, and follow the Linux
i2c-hid descriptor/power-on/reset sequence.  Add `touchpad probe` and probe
diagnostics.

Add Kaby Lake-U DTS thermal, the Sunrise Point-LP PCH backlight registers,
HWP P-states and the IdeaPad EC battery/AC backend (BAT1/ACAD through the
DSDT ECMM window at 0xFF000800).

Add the Intel 8265 8000-family WiFi path: PCI id, firmware, secure
multi-CPU section loader, APMG-less bring-up and the extended-NVM MAC.
Update AGENTS.md and the architecture pages.
Johannes Zellner hace 1 día
padre
commit
e7715b7d9d

+ 158 - 54
AGENTS.md

@@ -351,7 +351,12 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `bkl_trylock()` (never blocks); the kworker and kernel commands take the BKL
   normally and release it around their sleeps.
   APs use their LAPIC timer (vector 0x30; 1 ms busy, 10 ms idle); the BSP keeps the 8259 PIC/PIT and
-  is the only global-tick source.  APs do not start taking user work until
+  is the only global-tick source.  The BSP LAPIC is initialized in
+  `timer_init()` before `sti` (SVR, LINT0 ExtINT, firmware LAPIC timer
+  stopped), and the PIT/keyboard/mouse/floppy/default stubs send the LAPIC
+  EOI as well as the PIC EOI, so a firmware that leaves the LAPIC enabled
+  cannot block the second ExtINT tick; `smp_init()` re-runs
+  `lapic_init_bsp()`.  APs do not start taking user work until
   `smp_enable_sched()`, i.e. after device/FS setup.  LAPIC IPIs (vector 0x31)
   request a reschedule; they must be EOIed on the target LAPIC.
   `SYS_PROCINFO` exposes pid/parent_pid, weight/state/CPU/ticks, pages and
@@ -401,7 +406,9 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `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;
+  `lapic_init_bsp()` runs early from `timer_init()` and again from
+  `smp_init()`),
   `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
   `smp_enable_sched`), `ap_tramp.S` + `ap_tramp.ld` (real → protected-mode
@@ -862,7 +869,12 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   pipe the firmware enabled and falls back to controller 0; the period comes
   from the firmware (`6000` = 19.2 MHz / (200 Hz × 16) when it reads zero).
   The 10% steps clamp at 5..100% and the level is not persisted across a cold
-  boot.  `io.c` maps F6/F7 (the ChromeOS EC action row) and `E0 14`/`E0 15`
+  boot.  The same driver now handles the Sunrise Point-LP PCH PWM on Kaby
+  Lake (the Yoga 720's HD 620 `8086:5916`): `BLC_PWM_CTL2` at `0xC8250` and
+  `BLC_PWM_CTL` at `0xC8254` in the GPU BAR (pipe B `+0x100`), with the same
+  enable/period/duty layout.  The Yoga's firmware leaves a period of 535 and
+  Linux's `intel_backlight` reports max 535 / current 96; the 5..100% steps
+  work through the same `SYS_BACKLIGHT` and Settings path.  `io.c` maps F6/F7 (the ChromeOS EC action row) and `E0 14`/`E0 15`
   (standard brightness scancodes) to `backlight_step()` and consumes them.
   The `backlight [0-100|up|down|probe]` kernel command and `SYS_BACKLIGHT`
   (op 0 get, 1 set, 2 step) are the other interfaces.
@@ -1092,7 +1104,21 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   `FLUSH_CACHE` when the card reports a write-back cache. A stock eMMC holds
   the ChromeOS image, so formatting it is destructive.
 - **Serial**: `serial.c`, `serial_ring_buf.c/h`, `serial_loop.c` — 16550 UART
-  with an IRQ-driven ring buffer and the `serial test` loopback check.
+  with a receive ring drained from the PIT stub and the `serial test`
+  loopback check.  `serial_init()` probes COM1 first: a missing UART leaves
+  LSR and IIR at `0xFF` (a real 16550 has LSR bit 7 zero and a `0x01`/`0xC1`
+  IIR), so the port is marked dead and printed as `com1: absent` on the boot
+  console; it is never programmed or polled again.  `serial_poll()` also
+  refuses a floating LSR and only drains while DR is set.  This matters on a
+  serial-less laptop: the Yoga 720-13IKB has no legacy COM1 (only the LPSS
+  UART at MMIO, Linux's `ttyS4`), and the old 256×2 I/O drain ran on every
+  1 kHz PIT tick over eSPI, costing more than the tick itself and freezing
+  the boot after `[process]`.  `serial_putc()` still feeds the bootconsole
+  and netlog mirrors before its dead check.  The boot console also prints
+  `timer: pic|idt|lapic|pit|sti` around `timer_init`, a one-shot `tick` on the
+  first PIT interrupt, and `smp: ap N` while the APs start; `pit_ticking()`
+  requires three ticks so a one-tick/blocked PIT cannot silently stall in
+  `smp_init()`'s `get_ticks_ms()` waits.
 - **Network**: `netdev.c/h` — NIC driver registry (`struct netdev`, first probe
   wins; drivers: `e1000e.c` Intel e1000/PCH LAN (82540EM emulated,
   82577LM/82578/82579; polled, PCI INTx disabled before MMIO, PCH D0 and
@@ -1199,9 +1225,9 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   lives in the command pack, so `make net-cmds` updates it without a
   kernel reload.  Static IP default `192.168.178.240`, mask/gateway learned
   from DHCP (off-subnet traffic goes via the router).
-- **WiFi (Intel 7265D/3165, the HP Chromebook)**: `iwl_trans.c/h` — PCIe
-  transport after Linux iwlwifi (7000 family): PCI scan for
-  `8086:095a/095b/3165/3166`, D0, BAR0 mapped with `ioremap`,
+- **WiFi (Intel 7265D/3165/8265, the HP Chromebook and Yoga)**: `iwl_trans.c/h` — PCIe
+  transport after Linux iwlwifi (7000/8000 family): PCI scan for
+  `8086:095a/095b/3165/3166/24fd`, D0, BAR0 mapped with `ioremap`,
   APM init, one legacy RX queue (256 x 4 KB RBDs), gen1 128-byte TFD queues
   with dword byte-count tables, firmware TLV parse and section DMA through
   the FH service channel (128 KB bounce, `LMPM_CHICK` for the extended
@@ -1227,6 +1253,16 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   7265D-29 firmware does not use correctly installed `ADD_STA_KEY` keys for
   RX even though TX (which embeds the TK in `TX_CMD`) works; there is no
   software replay window yet.
+  The 8265 (Yoga 720, `8086:24fd`) uses `iwlwifi-8265-36.ucode` (API 36)
+  through the same MVM command layer, but the 8000 transport path: the TLV
+  section list is split into CPU1/CPU2 lists by separator entries, every
+  loaded section is acknowledged in `FH_UCODE_LOAD_STATUS`, and the CPU
+  reset is released through `RELEASE_CPU_RESET`/`WFPM_GP2` (Linux
+  `iwl_pcie_load_given_ucode_8000()`); the APMG clock block is skipped
+  (`apmg_not_supported`).  Its MAC address comes from the extended-NVM
+  `MAC_OVERRIDE` section (11, offset 2), with the WFMP `0xA03080/0xA03084`
+  registers as the fallback; the 7000 HW-section 0/word 0x15 path is
+  unchanged.  This backend is not yet hardware-validated.
   The firmware is loaded on first use (`wifi` or the boot autoconnect
   helper), not during kernel init.
   `netdev_shutdown()` always calls `wifi_shutdown()` before a kexec (the RX
@@ -1473,36 +1509,51 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   mouse reports and inject keyboard scancodes, watch for plug/unplug (boot
   protocol has no wheel field, so the USB wheel output stays 0 for now).
 - **I2C touchpad**: `i2c.c/h` — polled Synopsys DesignWare APB I2C master
-  for the Braswell LPSS blocks (fast mode, component-type probe, explicit
-  LPSS reset-release so the FIFO drains); `touchpad.c/h` — Elan
-  HID-over-I2C touchpad on LPSS I2C6 at `0xD1327000`, slave `0x15`.
-  `touchpad_init()` runs from `mouse_init()` at boot, only when
-  `cpu_family_model()` is Airmont `0x64C` (elsewhere the fixed-address LPSS
-  scan would reset-cycle 32 MMIO windows that belong to nobody, ~64 ms, or
-  to another device); it maps the I2C
-  window before processes clone the page directory), resets the device,
-  consumes the 2-byte acknowledgement, reads the HID descriptor, selects
-  absolute mode (`0x0300 = 1`), wakes it (`0x0800`) and then queries the
-  native max-X/Y commands (`0x0106`/`0x0107`).  The report line is a GPIO with
-  no driver, so `touchpad_poll()` reads the input register every 25 ms
-  (back-to-back reads stall the device), parses the Elan `0x5D` vendor
-  report (finger bitmask plus five bytes per packed finger) and feeds the
-  device-independent `touchpad_gesture.c/h` engine.  The engine owns
+  for the LPSS blocks (fast mode, component-type probe, explicit LPSS
+  reset-release so the FIFO drains); `touchpad.c/h` — Elan HID-over-I2C
+  touchpad on Braswell LPSS I2C6 at `0xD1327000`, slave `0x15`, and the
+  Synaptics 06CB:7F8F Windows-Precision touchpad on Sunrise Point-LP LPSS
+  I2C0 at PCI 00:15.0, slave `0x2c`.
+  `touchpad_init()` runs from `mouse_init()` at boot.  On Airmont `0x64C` it
+  scans the two fixed LPSS windows (elsewhere the scan would reset-cycle 32
+  MMIO windows that belong to nobody or to another device) and probes the
+  Elan: reset, consume the 2-byte acknowledgement, read the HID descriptor,
+  select absolute mode (`0x0300 = 1`), wake (`0x0800`) and query the native
+  max-X/Y (`0x0106`/`0x0107`).  On Skylake/Kaby Lake it finds the PCI
+  00:15.0/1/2 LPSS functions, enables their memory decode and puts them in
+  D0 first (the firmware leaves the command register at 0: Linux logs
+  `intel-lpss 0000:00:15.0: enabling device (0000 -> 0002)`), maps the BAR
+  and probes the Synaptics at `0x2c`; the HID descriptor vendor/product
+  `0x06CB/0x7F8F` filters out the Wacom touchscreen on I2C1.  The
+  Synaptics probe follows Linux i2c-hid: address ACK, read the HID
+  descriptor, then power-on (`0x0800`), reset (`0x0100`) and the
+  zero-length reset-complete input report.  The report line is
+  a GPIO with no driver, so `touchpad_poll()` reads the input register every
+  25 ms (back-to-back reads stall the device).  The Elan `0x5D` vendor report
+  carries a finger bitmask and five packed bytes per active finger; the
+  Synaptics Windows-Precision report 3 carries five 5-byte finger records
+  (tip/confidence, contact id, 16-bit X/Y), then scan time, contact count
+  and the clickpad bit.  Both decoders feed the device-independent
+  `touchpad_gesture.c/h` engine.  The engine owns
   pointer scaling, taps, the physical-button latch and two-finger
   scrolling, so another touchpad backend only has to decode its own
   reports into up to two contacts.  A short stationary tap synthesizes a
   button press: two fingers -> right click, one finger in the bottom-right
   zone (`x >= 75%`, `y <= 25%`) -> right click, one finger elsewhere ->
-  left click.  The device's raw Y axis grows upwards, so the bottom is the
-  low end.  A physical clickpad press is also latched at its leading edge:
-  in the bottom-right zone it becomes the right button, elsewhere the left
-  button, and the latch holds for the whole press.  Two fingers that move
-  their centroid by more than ~30 device units scroll; the pointer freezes
-  while two or more fingers are down and re-anchors when one remains.
-  Natural scrolling (two fingers up = later content) is the default.
-  `touchpad` prints the probe/status and takes
-  `rightclick off|tap|corner|both`, `tapclick on|off` and
-  `scroll on|off|natural|traditional`; `mouseinfo` lists the Elan VID/PID.
+  left click.  The Elan raw Y grows upwards; the Synaptics frame is inverted
+  by default to match, and `touchpad invert on|off` selects the direction
+  for either backend.  A physical clickpad press is also latched at its
+  leading edge: in the bottom-right zone it becomes the right button,
+  elsewhere the left button, and the latch holds for the whole press.  Two
+  fingers that move their centroid by more than ~30 device units scroll; the
+  pointer freezes while two or more fingers are down and re-anchors when one
+  remains.  Natural scrolling (two fingers up = later content) is the
+  default.  `touchpad` prints the probe/status and takes
+  `rightclick off|tap|corner|both`, `tapclick on|off`,
+  `scroll on|off|natural|traditional` and `invert on|off`; `touchpad probe`
+  reruns a failed boot probe and prints the LPSS PCI id/BAR/command, the
+  DesignWare component type and the 0x200/0x204 private registers on
+  failure.  `mouseinfo` lists the Elan/Synaptics VID/PID.
 - **USB**: `usb.c/h` — controller-agnostic core: device enumeration,
   descriptor parsing, hub recursion, bus scans, per-controller addresses, the
   hotplug watcher and the interrupt-IN consumers (mouse + keyboard).  It keeps
@@ -1581,6 +1632,14 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   configures them) and no package-energy MSR reads; APERF/MPERF are used
   only when CPUID.06H:ECX[0] says they exist.  C3/C6 residency is not read
   on Airmont.
+  Kaby Lake (family 6 model `0x8E`, the Yoga's i7-7500U) uses HWP/Speed
+  Shift: `IA32_HWP_CAPABILITIES` (`0x771`) gives highest/guaranteed/
+  efficient/lowest, and the governor uses guaranteed..lowest (max non-turbo
+  and minimum), leaving turbo unrequested.  `IA32_HWP_REQUEST` (`0x774`)
+  carries min/max/desired plus EPP (`balance_performance` = 128), the
+  `IA32_PM_ENABLE` bit 0 selects HWP, and legacy `IA32_PERF_CTL` is the
+  fallback.  Linux reports `intel_pstate` active, 400-3500 MHz, 32 pstates,
+  turbo 25% and `balance_performance`; `power`/`cpufreq`/Settings drive it.
   The per-CPU tick runs a race-to-idle governor: 100 ms windows pick
   min/max/linear target pstates (short busy streaks jump to max immediately)
   and each CPU writes its own `IA32_PERF_CTL`.  The `power` command prints
@@ -1607,6 +1666,10 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   ThinkPads and the HP Chromebook, the AC/battery icon at the far right (a
   plug while on AC, a level-filled battery on battery) and `cpuinfo`'s value
   plus EIST state.
+  Kaby Lake-U (`0x8E`, the Yoga) is in the DTS/MSR TjMax list; Linux reports
+  `x86_pkg_temp` 61-71 °C and the PCH `pch_skylake` 49-52 °C on this unit.
+  The kernel exposes the CPU DTS only; the PCH/INT3403 `SEN1`/`SEN2`/`B0D4`
+  ACPI sensors would need the DPTF tables.
   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
@@ -1623,8 +1686,10 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   and show whether the fans turn.  Nothing is written to the fan control.
   `tpec.c/h` adds the ThinkPad embedded controller of the X201
   (`SYS_TPEC_SENSORS` for temperatures/fan, `SYS_POWER_INFO` for AC/battery):
-  a `_SM_` SMBIOS type 1 check gates the probe to Lenovo/IBM machines, then
-  EC reads through ports 0x62/0x66 return the temperatures at EC 0x78..0x7F /
+  a `_SM_` SMBIOS type 1 check gates the probe to Lenovo/IBM machines whose
+  product or version string contains `ThinkPad`; IdeaPads/Yogas share the
+  vendor but have a different ACPI EC register map, so the ThinkPad probe
+  leaves them alone (the `ideapad.c` backend below handles theirs).  EC reads through ports 0x62/0x66 return the temperatures at EC 0x78..0x7F /
   0xC0..0xC7 (0x80 = absent, 0x00 = unimplemented; revision 3+ at EC 0xEF
   only uses the first block), the fan tachometer at 0x84 (LSB, always read
   first) / 0x85 and the 0x2F fan mode.  The power path reads 0x38/0x39
@@ -1655,8 +1720,22 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   when supported.  The Cyan full-charge workaround is applied and the units
   are mAh/mA.  `SYS_CROS_EC_SENSORS` (107) exposes temperatures, fans, fan
   duty and switches; `SYS_POWER_INFO` reports source `SYS_POWER_SRC_CROS`.
-  `power_src.c` tries the ThinkPad backend first, then the Chrome EC, so the
-  WM top bar and the `powerinfo`/`sensors` commands work on both.
+  `ideapad.c/h` reads the IdeaPad/Yoga battery and AC adapter without an
+  ACPI interpreter: the DSDT's `BAT1` methods take their fields from the
+  PCH EC memory window at `0xFF000800` (a `SystemMemory` OperationRegion,
+  not the 0x62/0x66 EC), so the backend maps that page with `ioremap()` and
+  reads `BST0` 0xC1, `BRC0` 0xC2, `BPV0` 0xC6, `BDV0` 0xC8, `BDC0` 0xCA,
+  `BFC0` 0xCC, `CYC0` 0xCF, `BAC0` 0xD2, `BFCB` 0xED and the `ORRF` 0xF1
+  bit 6 / `ADPT` 0xA3 bit 7 flags.  `BAM0` (0xC0 bit 1) selects the 1/10
+  capacity scale and the mA->mW rate conversion, and `BMF0` (0xC0 bits
+  4..7, 6 = SIMPLO) the vendor string.  The probe validates design/full
+  capacity, voltage and the status/vendor bits, so an address that is not
+  this EC reads as absent, and the backend only reads (no EC writes).
+  `SYS_POWER_INFO` reports source `SYS_POWER_SRC_IDEAPAD`; `powerinfo`
+  prints `ideapad`, and the WM top bar and Settings use the same snapshot.
+  `power_src.c` tries the ThinkPad backend first, then the IdeaPad EC, then
+  the Chrome EC, so the WM top bar and the `powerinfo`/`sensors` commands
+  work on all three.
 - **Ring-3 address space**: the ELF image and 128 KB (32-page) stack live in
   the 4 MB `USER_BASE` (`0x40000000`)..`USER_STACK_TOP` (`0x40400000`)
   window, which is too small for a full-frame image.  Their frames, and the
@@ -2554,7 +2633,7 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
 `cd [path]`, `ls [path]`, `cat <path>`, `save <path> <text>`, `rm <path>`,
 `mkdir <path>`, `rmdir <path>`, `hello`, `acpidump` (writes the mapped
 DSDT to `/share/DSDT.BIN`), `reboot`, `poweroff`,
-`display`, `cpuinfo`, `mouseinfo`, `gfxbench`, `lsusb`, `touchpad [rightclick off|tap|corner|both] [tapclick on|off] [scroll on|off|natural|traditional]`, `lspci [id]`, `peek <addr> [len]`, `poke <addr> <val>`, `storage`, `disks` (the ngui storage manager), `meminfo`, `top`, `process` (the ngui task manager), `bootscan` (the live boot storage-scan window), `sched`, `format [-y] <device> [size]` (binary units, e.g. `format ide0 100mb` or `1gb`; no size formats the whole disk; `-y` skips the prompt), `install [-y] <target> [source|self]` (clone the live image, or write the running image; auto-detects the source, preferring `usb0`; `auto` targets the only non-USB NebOS disk),
+`display`, `cpuinfo`, `mouseinfo`, `gfxbench`, `lsusb`, `touchpad [probe] [rightclick off|tap|corner|both] [tapclick on|off] [scroll on|off|natural|traditional] [invert on|off]`, `lspci [id]`, `peek <addr> [len]`, `poke <addr> <val>`, `storage`, `disks` (the ngui storage manager), `meminfo`, `top`, `process` (the ngui task manager), `bootscan` (the live boot storage-scan window), `sched`, `format [-y] <device> [size]` (binary units, e.g. `format ide0 100mb` or `1gb`; no size formats the whole disk; `-y` skips the prompt), `install [-y] <target> [source|self]` (clone the live image, or write the running image; auto-detects the source, preferring `usb0`; `auto` targets the only non-USB NebOS disk),
 `ps`, `renice <pid> <weight>`, `kill <pid>`, `idle [auto|hlt|c1e|c3|c6]`, `power`, `powerinfo`, `cpufreq [auto|min|max|off|<pstate>]`, `spin [ms]`, `membench` (ring-3 speed check: TSC, ALU, heap/BSS memcpy, syscall rates), `backlight [0-100|up|down]` (also `probe`), `keytest` (raw scancode tap), `help`, `clear`, `serial test`, `kexec`, `dbg`, `service [list|status <name>|start|stop|restart|kill <name>|logs <name>|logtail <name>|--gui]` (init's client; `websrv` is the first service and holds the raw NIC receiver while running), `view <file>` (image viewer; PNG, baseline/progressive JPEG, animated GIF, BMP, TGA, PNM, ICO, PAM), `browser [url|file]` (disk app launcher; waits for the app so a terminal launch is foreground), and `chat [config-path]` (Cloudron Chat client).
 
 Network: `netinfo`, `netrecv`, `netsend`, `netip [a.b.c.d]`, `dhcp` (re-run the
@@ -2963,7 +3042,7 @@ briefly reporting disconnected.
   these devices.
 - **Debug**: `ohci:` / `uhci:` / `ehci:` / `usbhid:` lines go to COM1 (and
   through the netlog mirror on serial-less boards); `mouseinfo` shows the
-  active mouse backend, the Elan VID/PID when the I2C touchpad is present,
+  active mouse backend, the Elan/Synaptics VID/PID when the I2C touchpad is present,
   and whether a USB keyboard is attached; `usb.c`'s
   `USB_DEBUG` and `usbhid.c`'s `USBHID_DEBUG` (both default 0) add
   scan/report tracing.  Headless tests: `make test-usb` runs
@@ -3176,22 +3255,25 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
    inside the 16 MB no-E820 fallback).  A 4.15 MB pack was boot-tested on
    the legacy and UEFI paths and over `net-dev`.  The browser and
    its ring-3 dependencies are compiled with function sections and linked
-   with `--gc-sections`; the current full pack with the UI fonts, both
-   WiFi firmwares (7265D 1,036,312 bytes, ~442 KiB gzip; 6000 454,608 bytes,
-   ~204 KiB gzip), the RTL8821A firmware and tables (31,898 + 11,668
+   with `--gc-sections`; the current full pack with the UI fonts, the three
+   WiFi firmwares (7265D 1,036,312 bytes, ~442 KiB gzip; 8265 2,432,528
+   bytes, ~945 KiB gzip; 6000 454,608 bytes, ~204 KiB gzip), the RTL8821A
+   firmware and tables (31,898 + 11,668
    bytes), the 15 full-colour app icons and `install/kernel.bin` is
-   ~2.21 MB gzip (~2 MB under the cap), inflating to ~4.7 MB, which adds
-   about half a second to the boot; the floppy lite pack is ~744 KB gzip
+   ~3.16 MB gzip (~0.8 MB under the cap), inflating to ~7.3 MB, which adds
+   about a second to the boot; the floppy lite pack is ~744 KB gzip
    and deliberately omits the firmware, the cursor bundle,
    `install/kernel.bin` and the browser (`BROWSER` on `root.img` is the
    floppy copy).  `libdeflate-gzip -12` is still preferred.  Over
-   115200 serial a raw `cmds-dev` pack (4.7 MB) now takes about four
+   115200 serial a raw `cmds-dev` pack (7.3 MB) now takes about ten
    minutes; use `net-cmds` (~45 s in QEMU).
 9. SMP is **ACPI/MADT only**: no Intel MP-table fallback, so a Pentium II SMP
     board that exposes only MP tables stays UP (deliberate; there is no test
     hardware).
-10. There is no IOAPIC driver.  The BSP keeps the 8259 PIC in LAPIC ExtINT mode;
-    after ACPI init, `ioapic_mask_all()` masks every normal IOAPIC redirection
+10. There is no IOAPIC driver.  The BSP keeps the 8259 PIC on LAPIC LINT0
+    (ExtINT); `lapic_init_bsp()` runs in `timer_init()` before `sti` and again
+    in `smp_init()`, and the PIC IRQ stubs send the LAPIC EOI too.  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
@@ -3257,8 +3339,9 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     AMD MTRR path, the 32x32 cursor save buffer and the mount-policy table)
     ~0x8bf20 once the frame bitmap moved out of BSS; with the ioremap
     window, the EHCI handoff fix, the boot-scan log ring, the init bootstrap,
-    parent-pid tree kill, the tty control syscalls and `TTY_MAX` 16 it is
-    ~0x8e260, ~7.5 KB below the `0x90000` wall.  The WM and `sys_wm.o`
+    parent-pid tree kill, the tty control syscalls and `TTY_MAX` 16, the
+    early BSP LAPIC/EOI, the boot-stage markers and the Synaptics touchpad it
+    is ~0x8f260, ~3.5 KB below the `0x90000` wall.  The WM and `sys_wm.o`
     build with `-Os` because their extra settings code otherwise pushed the
     `.data` end across a page boundary and moved the 4 KB-aligned BSS by a
     whole page; the
@@ -3514,8 +3597,10 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     `%f/%e/%g` with a 900-digit precision cap.  These are sufficient for
     QuickJS but are not a complete POSIX libc.
 
-28. The Elan touchpad is polled at 40 Hz because its report GPIO (GPNC bank
-    index 18, level-low on setzer) has no driver.  The pointer follows one
+28. The Elan (Chromebook) and Synaptics 06CB:7F8F (Yoga 720-13IKB) touchpads
+    are polled at 40 Hz because their report GPIO has no driver (GPNC bank
+    index 18, level-low on setzer for the Elan; the Yoga's PCH GPIO and
+    `i2c-hid` interrupt are not used either).  The pointer follows one
     contact; two-finger scrolling uses the centroid of the first two
     contacts.  There is no inertia, no horizontal scroll, no drag-lock or
     pressure/size handling, no distinct three-finger gesture (3+ fingers
@@ -3525,9 +3610,10 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     one-finger left click) and need the contact to last at least two 25 ms
     samples; the corner zone also remaps a physical clickpad press to the
     right button and the tap/scroll thresholds are in
-    `touchpad_gesture.c`.  The device stalls if the input register is read
-    back-to-back, so a GPIO interrupt (or a larger minimum gap) is the
-    prerequisite for a higher report rate.
+    `touchpad_gesture.c`.  The Synaptics Y frame is inverted by default;
+    `touchpad invert on|off` selects the direction.  The device stalls if
+    the input register is read back-to-back, so a GPIO interrupt (or a larger
+    minimum gap) is the prerequisite for a higher report rate.
 
 29. Airmont/Braswell power management: the governor caps at the maximum
     non-turbo pstate (N3060: 20 = 1600 MHz) and never requests turbo pstate
@@ -3612,7 +3698,9 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     chat thread at 32x32.
 
 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`), 8265 (`iwlwifi-8265-36`, whose
+    new 8000 secure-section loader and MAC path are not yet
+    hardware-validated) and 6200/6300 (`iwlwifi-6000-4`)
     only; a non-D 7265 is logged and will likely fail, and other 6000-family
     parts (6005/6030/6050/6150, which use different firmware files) are not
     probed.  The 6200/6300 DVM path was written against Linux iwldvm without
@@ -3782,3 +3870,19 @@ and the WM falls back to polling (`io_keyboard_irq_masked()`).
     the window below.  The WM keeps the whole `NBAPP1` bundle (415 KB) plus
     the 2.4 MB wallpaper and 256 KB RGB565 table in its BSS, inside the 4 MB
     user image window.
+
+43. Lenovo Yoga 720-13IKB (Kaby Lake i7-7500U, Sunrise Point-LP, UEFI):
+    the UEFI image boots from USB to the WM and terminal.  The internal
+    Synaptics 06CB:7F8F touchpad is supported on LPSS I2C0 (see the I2C
+    touchpad bullet) and the external USB mouse/keyboard work.  Kaby Lake
+    thermal (`0x8E` DTS), the PCH `BLC_PWM_CTL` backlight and HWP P-states
+    (`intel_pstate` active, 400-3500 MHz) are supported.  The battery/AC uses
+    the IdeaPad ACPI EC backend (`ideapad.c`, the DSDT `ECMM` window at
+    `0xFF000800`; Linux `BAT1` reports 29.78/29.9 Wh, 8.657 V, 3.2 W, model
+    PABAS0241231/SIMPLO, `ACAD` online).  The internal Samsung NVMe SSD (`144d:a808`) is
+    not a block device (no NVMe driver) and the internal Intel 8265 WiFi
+    (`8086:24fd`) uses the new 8000 backend (`iwlwifi-8265-36.ucode`;
+    hardware validation pending).  The firmware's
+    LPSS UART (`8086:9d27`, ACPI `UA00`) is a 16550 at its MMIO BAR (Linux
+    `ttyS4`), not the legacy COM1; the legacy port floats at `0xFF`, which
+    `serial_init()` now detects before the PIT starts polling it.

+ 10 - 7
Makefile

@@ -111,7 +111,7 @@ $(B)/$(QJS_DIR)/%.o: $(QJS_DIR)/%.c
 KERNEL_LINK_ORDER = vesa_stage entry kernel timer switch sched process init mm \
 	kmalloc paging elf tss syscall sys_wm syscall_stub screen io tty rtc \
 	terminal wm reboot poweroff disk fat serial serial_ring_buf serial_loop \
-	vga blit cpu thermal it87 tpec ec cros_ec power_src power vga_copy \
+	vga blit cpu thermal it87 tpec ec cros_ec ideapad power_src power vga_copy \
 	gfxbench gpu backlight ati cirrus intel nvidia nv50 radeon mtrr \
 	font_8x8 font_8x16 fbtext gfx display cursor mouse i2c touchpad \
 	touchpad_gesture uhci ohci ehci xhci asix rndis iwl_trans iwl_mvm \
@@ -130,7 +130,7 @@ KERNEL_OBJS = $(foreach n,$(KERNEL_LINK_ORDER),$(call kobj,$(n)))
 KERNEL_OS = terminal disk fat nvidia nv50 uhci ohci ehci xhci asix rndis \
 	iwl_trans iwl_mvm iwl_dvm wifi_fw rtl8821au wifi ccmp usb lsusb lspci \
 	peek ne2000 r8168 blkdev fatdetect fatformat format install usbmsc dbg vfs \
-	wm sys_wm
+	wm sys_wm ideapad i2c touchpad
 $(addprefix $(B)/kernel/,$(addsuffix .o,$(KERNEL_OS))): OPT = -Os
 $(B)/kernel/e1000e.o: OPT = -Oz
 # The ACPI table/S5 parser and the poweroff path are cold boot/shutdown code
@@ -904,16 +904,18 @@ PACK_BROWSER_FILES = bin/browser.app=browser.elf
 # pack deliberately omits it (no room on a 1.44 MB disk).
 PACK_INSTALL_FILES = install/kernel.bin=kernel.bin
 
-# WiFi firmware (kernel/iwl_trans.c): the Intel 7265D/3165 (Chromebook, MVM)
-# and the 6200/6300 (ThinkPad X201, DVM).  Taken from the host's
-# linux-firmware (`.zst` or plain); WIFI_FW_7265D / WIFI_FW_6000 override the
-# search.  A machine without one still builds: the pack then has no
-# firmware/ entry for that card and `wifi` reports it missing.
+# WiFi firmware (kernel/iwl_trans.c): the Intel 7265D/3165 (Chromebook, MVM),
+# the 8265 (Yoga 720, 8000 MVM) and the 6200/6300 (ThinkPad X201, DVM).
+# Taken from the host's linux-firmware (`.zst` or plain); WIFI_FW_7265D /
+# WIFI_FW_8265 / WIFI_FW_6000 override the search.  A machine without one
+# still builds: the pack then has no firmware/ entry for that card and
+# `wifi` reports it missing.
 fw_search = $(firstword $(wildcard \
 	/usr/lib/firmware/intel/iwlwifi/$(1).zst /usr/lib/firmware/$(1).zst \
 	/usr/lib/firmware/intel/iwlwifi/$(1) /usr/lib/firmware/$(1) \
 	/lib/firmware/$(1)))
 WIFI_FW_7265D ?= $(call fw_search,iwlwifi-7265D-29.ucode)
+WIFI_FW_8265 ?= $(call fw_search,iwlwifi-8265-36.ucode)
 WIFI_FW_6000 ?= $(call fw_search,iwlwifi-6000-4.ucode)
 WIFI_FW_FILE =
 PACK_FW_FILES =
@@ -931,6 +933,7 @@ $$(info note: $(1) not found; building the pack without it)
 endif
 endef
 $(eval $(call wifi_fw_rule,iwlwifi-7265D-29.ucode,$(WIFI_FW_7265D)))
+$(eval $(call wifi_fw_rule,iwlwifi-8265-36.ucode,$(WIFI_FW_8265)))
 $(eval $(call wifi_fw_rule,iwlwifi-6000-4.ucode,$(WIFI_FW_6000)))
 
 # Realtek RTL8821AU USB sticks (kernel/rtl8821au.c): the rtw88 8051 firmware

+ 11 - 6
docs/boot.html

@@ -433,11 +433,16 @@
 		<p>
 			The boot trace lines written along the way (<code>boot_trace</code>,
 			<code>boot_val</code>) go to the framebuffer console and COM1, so a
-			machine without serial still shows where a boot stopped. The
-			console uses the same 8×16 face and top-left origin as the loader
-			text and the ring-3 terminal, and scrolls the framebuffer when the
-			screen is full instead of wrapping. The WM disables it when it
-			attaches; <code>bootlog</code> prints the saved text.
+			machine without serial still shows where a boot stopped. The boot
+			console also prints <code>com1: absent</code> when
+			<code>serial_init()</code> finds no UART, brackets the timer bring-up
+			with <code>timer: pic|idt|lapic|pit|sti</code> and the first
+			<code>tick</code>, and labels each AP as <code>smp: ap N</code>. The
+			console uses the same
+			8×16 face and top-left origin as the loader text and the ring-3
+			terminal, and scrolls the framebuffer when the screen is full instead
+			of wrapping. The WM disables it when it attaches; <code>bootlog</code>
+			prints the saved text.
 		</p>
 	</section>
 
@@ -445,7 +450,7 @@
 		<h2>Failure modes to know</h2>
 		<ul>
 			<li><strong>No VBE mode.</strong> The legacy stage cannot produce a framebuffer; the kernel may start headless or the boot stops in the stage.</li>
-			<li><strong>Pack larger than the cap.</strong> The compressed pack is capped at 4 MB: <code>PACK_MAX</code> in <span class="file">vesa_stage.S</span>, <code>CMDS_GZ_MAX</code> in the Makefile and the embedded-pack check in <span class="file">boot/efi/main.c</span> must agree. Hot reloads stage kernel + pack, or a raw runtime pack, in at most <code>KEXEC_MAX</code> (8 MB, <span class="file">kexec.h</span>), matching the 8 MB ramfs cap. The full pack is about 2.0 MB today, and inflating it adds roughly half a second to the boot.</li>
+			<li><strong>Pack larger than the cap.</strong> The compressed pack is capped at 4 MB: <code>PACK_MAX</code> in <span class="file">vesa_stage.S</span>, <code>CMDS_GZ_MAX</code> in the Makefile and the embedded-pack check in <span class="file">boot/efi/main.c</span> must agree. Hot reloads stage kernel + pack, or a raw runtime pack, in at most <code>KEXEC_MAX</code> (8 MB, <span class="file">kexec.h</span>), matching the 8 MB ramfs cap. The full pack is about 3.2 MB today (7265D + 8265 firmware), inflating to about 7.3 MB and adding roughly a second to the boot.</li>
 			<li><strong>PIT not ticking.</strong> <code>kernel_main</code> prints <code>*** PIT NOT TICKING ***</code> and halts; no process scheduling is possible.</li>
 			<li><strong>UEFI Secure Boot.</strong> The unsigned <code>BOOTX64.EFI</code> is rejected before any NebOS code runs.</li>
 			<li><strong>Stale boot info.</strong> The checksum makes an invalid <code>0x500</code> block read as absent rather than as a bogus pack or RSDP.</li>

+ 16 - 8
docs/cpu.html

@@ -85,8 +85,14 @@
 			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.
+			collide with the PIC vectors or the LAPIC timer. The BSP LAPIC is
+			initialized in <code>timer_init()</code> before <code>sti</code>
+			(SVR, LINT0 ExtINT, the firmware LAPIC timer stopped), and the PIC
+			IRQ stubs send the LAPIC EOI as well as the PIC EOI; a firmware
+			that leaves the LAPIC enabled therefore cannot block the second
+			ExtINT tick. <code>smp_init()</code> re-runs
+			<code>lapic_init_bsp()</code>. APs mask their LINT0/LINT1 inputs and
+			use only their local APIC timer and IPIs.
 		</p>
 		<div class="table-wrap">
 			<table>
@@ -94,7 +100,7 @@
 					<tr><th>Source</th><th>Vector</th><th>Role</th></tr>
 				</thead>
 				<tbody>
-					<tr><td>8259 PIC + PIT</td><td>IRQ0, etc.</td><td>BSP global clock and device interrupts; PIT tick advances the millisecond clock.</td></tr>
+					<tr><td>8259 PIC + PIT</td><td>IRQ0, etc.</td><td>BSP global clock and device interrupts on LAPIC LINT0 ExtINT; the stubs send both EOIs; the PIT tick advances the millisecond clock.</td></tr>
 					<tr><td>LAPIC timer</td><td><code>0x30</code></td><td>Per-AP scheduling tick; 1 ms busy, 10 ms idle.</td></tr>
 					<tr><td>LAPIC IPI</td><td><code>0x31</code></td><td>Reschedule request; must be EOIed on the target LAPIC.</td></tr>
 					<tr><td><code>int 0x80</code></td><td>syscall gate</td><td>Ring-3 service entry.</td></tr>
@@ -216,7 +222,8 @@
 			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>
+			8259 through an IOAPIC pin still works. The BSP LAPIC is brought up
+			before the first interrupt and every PIC stub also EOIs it.</p>
 		</div>
 	</section>
 
@@ -399,10 +406,11 @@
 		<ul>
 			<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>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 Settings Power page.</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 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>Kaby Lake HWP P-states.</strong> Family 6 model <code>0x8E</code> (the Yoga 720's i7-7500U) uses Speed Shift. <code>IA32_HWP_CAPABILITIES</code> (<code>0x771</code>) gives the highest, guaranteed, most-efficient and lowest ratios; the governor uses guaranteed..lowest (max non-turbo..minimum) and leaves turbo unrequested. <code>IA32_HWP_REQUEST</code> (<code>0x774</code>) carries min/max/desired plus the EPP (<code>balance_performance</code> = 128); <code>IA32_PM_ENABLE</code> bit 0 selects HWP, with legacy <code>IA32_PERF_CTL</code> as the fallback. Linux reports <code>intel_pstate</code> active, 400-3500 MHz, 32 pstates, 25% turbo and <code>balance_performance</code>; the same <code>power</code>/<code>cpufreq</code>/Settings path drives it.</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> (or <code>IA32_HWP_REQUEST</code> on Kaby Lake); <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 Settings Power page.</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 all three 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 on ThinkPads, IdeaPads/Yogas 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 and Kaby Lake, the coretemp 90 °C table on Airmont, and the Bonnell table on older Atoms. Kaby Lake-U (<code>0x8E</code>) reports the package DTS (Linux <code>x86_pkg_temp</code> 61-71 °C on the Yoga; the PCH <code>pch_skylake</code> 49-52 °C is not read because the DPTF/INT3403 tables are not parsed). 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, and Kaby Lake HWP leaves turbo unrequested too. 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>
 	</section>
 

+ 7 - 1
docs/development.html

@@ -274,6 +274,12 @@
 			The serial receive drops the BKL while it waits for bytes, so the WM
 			and the other CPU's syscalls stay responsive during a reload.
 		</p>
+		<p>
+			A machine without a real 16550 at COM1 prints <code>com1: absent</code>
+			at boot and never polls the floating port; use the network reload
+			below for boards such as the Yoga 720-13IKB, whose firmware exposes
+			only an MMIO LPSS UART.
+		</p>
 	</section>
 
 	<section id="network">
@@ -331,7 +337,7 @@ make net-cmds                   # replace /ramfs only</code></pre>
 			<li><strong>Existing processes are unaffected.</strong> They already loaded their ELF.</li>
 			<li><strong>The next spawn sees the new files.</strong></li>
 			<li><strong>RAM only.</strong> A cold boot uses the flashed rootfs; reflash after changing the bundle.</li>
-			<li><strong>Size.</strong> The raw pack is about 4.3 MB with the WiFi firmware, so <code>cmds-dev</code> over 115200 serial takes roughly four minutes; prefer <code>net-cmds</code> (about 45 s in QEMU). Reloads carry up to <code>KEXEC_MAX</code> (8 MB).</li>
+			<li><strong>Size.</strong> The raw pack is about 7.3 MB with the WiFi firmware, so <code>cmds-dev</code> over 115200 serial takes roughly ten minutes; prefer <code>net-cmds</code> (about 1-2 minutes). Reloads carry up to <code>KEXEC_MAX</code> (8 MB).</li>
 		</ul>
 	</section>
 

+ 85 - 50
docs/drivers.html

@@ -55,7 +55,7 @@
 			<li><a href="#pci">PCI &amp; discovery</a></li>
 			<li><a href="#storage">Storage</a></li>
 			<li><a href="#usb">USB stack</a></li>
-			<li><a href="#wifi">WiFi (Intel 7265D/3165, 6200/6300, RTL8821AU)</a></li>
+			<li><a href="#wifi">WiFi (Intel 7265D/3165/8265, 6200/6300, RTL8821AU)</a></li>
 			<li><a href="#hid">Input</a></li>
 			<li><a href="#serial">Serial</a></li>
 			<li><a href="#sensors">Sensors &amp; power</a></li>
@@ -85,14 +85,14 @@
 					<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>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>), 8265 (<code>8086:24fd</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>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 graphics MMIO: Braswell/Cherryview display engine (<code>8086:22b0/22b1</code>, <code>0x1E1250</code>/<code>0x1E1254</code>) and Kaby Lake Sunrise Point-LP PCH PWM (<code>8086:5916/591e/5926</code>, <code>0xC8250</code>/<code>0xC8254</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>PS/2</td><td><span class="file">mouse.c</span>, <span class="file">io.c</span></td><td>i8042</td><td>IRQ 1 keyboard, IRQ 12 mouse; polling fallback</td></tr>
-					<tr><td>Touchpad</td><td><span class="file">i2c.c</span>, <span class="file">touchpad.c</span>, <span class="file">touchpad_gesture.c</span></td><td>LPSS DesignWare I2C, slave <code>0x15</code></td><td>Polled input register every 25 ms; software tap and two-finger scroll gestures; no GPIO interrupt driver</td></tr>
-					<tr><td>Serial</td><td><span class="file">serial.c</span></td><td>16550 UART, COM1</td><td>IRQ 4 ring buffer + polled transmitter</td></tr>
+					<tr><td>Touchpad</td><td><span class="file">i2c.c</span>, <span class="file">touchpad.c</span>, <span class="file">touchpad_gesture.c</span></td><td>LPSS DesignWare I2C; Elan <code>0x15</code>, Synaptics <code>0x2C</code></td><td>Polled input register every 25 ms; software tap and two-finger scroll gestures; no GPIO interrupt driver</td></tr>
+					<tr><td>Serial</td><td><span class="file">serial.c</span></td><td>16550 UART, COM1</td><td>COM1 presence probe; PIT-polled receive ring, polled transmitter</td></tr>
 					<tr><td>Thermal</td><td><span class="file">thermal.c</span></td><td>Intel DTS MSR</td><td>Sampled once a second from the scheduler tick</td></tr>
-					<tr><td>Board sensors / EC</td><td><span class="file">it87.c</span>, <span class="file">tpec.c</span>, <span class="file">ec.c</span>, <span class="file">cros_ec.c</span></td><td>Super I/O, ThinkPad H8 EC, Chrome OS EC (temps, fans, battery, AC, switches)</td><td>Polled; EC battery-index/FIFO/page-selector writes only</td></tr>
+					<tr><td>Board sensors / EC</td><td><span class="file">it87.c</span>, <span class="file">tpec.c</span>, <span class="file">ec.c</span>, <span class="file">cros_ec.c</span>, <span class="file">ideapad.c</span></td><td>Super I/O, ThinkPad H8 EC, Chrome OS EC, IdeaPad EC (temps, fans, battery, AC, switches)</td><td>Polled; EC battery-index/FIFO/page-selector writes only</td></tr>
 					<tr><td>Wall clock</td><td><span class="file">rtc.c</span></td><td>CMOS RTC ports <code>0x70/0x71</code></td><td>Read/write under the BKL; update-cycle retries and a 1970–2069 two-digit year window</td></tr>
 				</tbody>
 			</table>
@@ -405,10 +405,11 @@
 	</section>
 
 	<section id="wifi">
-		<h2>WiFi (Intel 7265D/3165, 6200/6300, RTL8821AU)</h2>
+		<h2>WiFi (Intel 7265D/3165/8265, 6200/6300, RTL8821AU)</h2>
 		<p>
-			Two Intel generations share one PCIe transport. The HP Chromebook's
-			Wireless-AC 7265 rev D or 3165 runs the newer <em>MVM</em> firmware
+			Three Intel generations share one PCIe transport. The HP
+			Chromebook's Wireless-AC 7265 rev D or 3165 and the Yoga 720's
+			8265 run the newer <em>MVM</em> firmware
 			(<span class="file">iwl_mvm.c</span>); the ThinkPad X201's Centrino
 			Advanced-N 6200 (or Ultimate-N 6300) runs the older <em>DVM</em>
 			firmware (<span class="file">iwl_dvm.c</span>).
@@ -439,7 +440,7 @@
 				<text class="svg-sub" x="60" y="152">auth/assoc · 802.11 ↔ Ethernet (LLC/SNAP, CCMP header) · EAPOL queue · SYS_WIFI</text>
 
 				<rect class="svg-box" x="40" y="182" width="840" height="44" rx="9"/>
-				<text class="svg-text" x="60" y="209">iwl_mvm.c (7265D) · iwl_dvm.c (6200/6300) · rtl8821au.c (USB) — via wifi_fw.c</text>
+				<text class="svg-text" x="60" y="209">iwl_mvm.c (7265D/8265) · iwl_dvm.c (6200/6300) · rtl8821au.c (USB) — via wifi_fw.c</text>
 
 				<rect class="svg-box green" x="40" y="246" width="840" height="44" rx="9"/>
 				<text class="svg-text" x="60" y="273">iwl_trans.c (PCIe rings, firmware DMA) · usb.c bulk + vendor control (RTL8821AU)</text>
@@ -465,6 +466,7 @@
 		<ul>
 			<li><strong>Transport.</strong> <span class="file">iwl_trans.c</span> follows Linux iwlwifi for the 7000 family: APM init, one legacy RX queue of 256 × 4 KB RBDs, gen1 128-byte TFDs, byte-count tables in dwords, and the FH service channel loading firmware sections through a 128 KB bounce buffer. The NIC is kept awake (MAC access request held) and interrupts stay masked; PCI INTx is disabled. Host commands use the wide 8-byte header (legacy commands go out as group 1).</li>
 			<li><strong>Firmware.</strong> <code>iwlwifi-7265D-29.ucode</code> ships in the command pack as <code>firmware/iwlwifi-7265D-29.ucode</code> (1,036,312 bytes). It is a single-CPU image with LMAC scan, DQA queues and the old station API. <span class="file">iwl_mvm.c</span> runs the INIT image (NVM read for the MAC address, calibration, PHY-DB collection), then the runtime image (PHY-DB replay, DQA, aux station, PHY context, CAM power, MCC <code>ZZ</code>, station MAC context).</li>
+			<li><strong>8000 firmware (8265).</strong> <code>iwlwifi-8265-36.ucode</code> (API 36, ~2.4 MB) is the Yoga's image. Its TLV section list is split into CPU1 and CPU2 lists by separator entries; every loaded section is acknowledged in <code>FH_UCODE_LOAD_STATUS</code> and the CPU reset is released through <code>RELEASE_CPU_RESET</code>/<code>WFPM_GP2</code> (<code>load_sections_8000</code> in <span class="file">iwl_trans.c</span>). The APMG clock block is skipped (<code>apmg_not_supported</code>), and the MAC comes from the extended NVM's <code>MAC_OVERRIDE</code> section 11 (word 1), falling back to the WFMP <code>0xA03080</code>/<code>0xA03084</code> registers. This path is not yet hardware-validated.</li>
 			<li><strong>Queues.</strong> Command queue 0 (FIFO 7), aux queue 1 (scan probes), BSS queue 4 for the AP station (management and data, BE FIFO).</li>
 			<li><strong>Station.</strong> <span class="file">wifi.c</span> builds open-system authentication and the association request itself, without WMM or HT IEs, so data frames are plain non-QoS 802.11 + LLC/SNAP. Management frames go at 1 Mb/s CCK (6 Mb/s on 5 GHz), data at a fixed 12 Mb/s OFDM (no rate scaling table yet).</li>
 			<li><strong>Security.</strong> WPA2-PSK with CCMP only. The 4-way and group handshakes run in ring 3 (<span class="file">wpa.c</span>); the kernel queues EAPOL frames and installs the TK/GTK with <code>ADD_STA_KEY</code>. TX uses the firmware's CCMP engine with the key embedded in <code>TX_CMD</code>; the host builds the 8-byte CCMP header and its packet number. On the tested 7265D-29 the firmware does not use the installed keys for RX and reports <code>SEC_ENC_ERR</code>, so RX CCMP is decrypted in software by <span class="file">ccmp.c</span> (AES-CCM, RFC 3610) with the same TK/GTK. There is no software replay window yet.</li>
@@ -474,8 +476,11 @@
 		<h3>6200/6300: the DVM firmware</h3>
 		<p>
 			The transport differences live in one per-family descriptor
-			(<code>fam_7000</code>/<code>fam_6000</code> in
-			<span class="file">iwl_trans.c</span>):
+			(<code>fam_7000</code>/<code>fam_8000</code>/<code>fam_6000</code> in
+			<span class="file">iwl_trans.c</span>). The 8265 reuses the 7000
+			layout (31 queues, wide headers, dword byte counts) with the 8000
+			section loader above; the MVM command flow is the same as the
+			7265D's.
 		</p>
 		<div class="table-wrap">
 			<table>
@@ -560,29 +565,47 @@
 
 		<h3>I2C touchpad</h3>
 		<p>
-			The HP Chromebook 11 G5 EE has no PS/2 port: its Elan touchpad is a
-			HID-over-I2C device on LPSS I2C6. The LPSS I2C functions are hidden
-			from PCI in ACPI mode, so <span class="file">touchpad.c</span> scans
-			the two firmware BAR windows for a DesignWare component (only on an
-			Airmont CPU, family 6 model <code>0x4C</code>: elsewhere the scan
-			would reset-cycle 32 fixed MMIO windows for ~64 ms of boot) and
-			<span class="file">i2c.c</span> drives that controller in fast mode,
-			polled and without interrupts.
+			Two HID-over-I2C touchpads are supported. The HP Chromebook
+			11 G5 EE has no PS/2 port: its Elan touchpad is on LPSS I2C6 at
+			slave <code>0x15</code>. The Lenovo Yoga 720-13IKB has a Synaptics
+			<code>06CB:7F8F</code> Windows-Precision touchpad on Sunrise
+			Point-LP LPSS I2C0, PCI <code>00:15.0</code>, at slave
+			<code>0x2C</code>. The Braswell LPSS I2C functions are hidden from
+			PCI in ACPI mode, so on Airmont <span class="file">touchpad.c</span>
+			scans the two firmware BAR windows for a DesignWare component;
+			on Skylake/Kaby Lake it finds the PCI <code>00:15.0/1/2</code>
+			functions, enables their memory decode and puts them in D0
+			first (the firmware leaves the command register at 0, which
+			Linux logs as <em>enabling device (0000 -&gt; 0002)</em>),
+			maps their BARs. <span class="file">i2c.c</span> drives either
+			controller in fast mode, polled and without interrupts.
 		</p>
 		<ul>
-			<li><strong>Probe.</strong> Slave address <code>0x15</code>: reset
+			<li><strong>Probe.</strong> Elan at <code>0x15</code>: reset
 			(<code>0x0100</code>), consume the 2-byte acknowledgement, read the
 			HID descriptor, select absolute mode (<code>0x0300 = 1</code>) and
-			wake the device (<code>0x0800</code>). Resetting last leaves it
-			silent until the next power cycle.</li>
+			wake the device (<code>0x0800</code>). Synaptics at <code>0x2C</code>:
+			check the address, read the HID descriptor, then power on
+			(<code>0x0800</code>), reset (<code>0x0100</code>) and wait for
+			the zero-length reset-complete input report, as Linux i2c-hid
+			does; then use the Windows-Precision report 3. The descriptor's
+			vendor/product (<code>0x06CB:0x7F8F</code>) filters out the Wacom
+			touchscreen on I2C1. The Elan native max-X/Y commands
+			(<code>0x0106</code>/<code>0x0107</code>) give the corner zone a
+			physical coordinate frame; the Synaptics frame is 1219 x 799.
+			<code>touchpad probe</code> reruns the probe and prints the LPSS
+			PCI id/BAR/command, component type and private registers when it
+			fails.</li>
 			<li><strong>Reports.</strong> The Elan vendor report <code>0x5D</code>
 			carries a finger bitmask and five packed bytes per active finger
-			(X/Y high bits, X low, Y low, size, pressure). The decoder feeds the
-			device-independent <span class="file">touchpad_gesture.c</span>
-			engine; a future PS/2 or USB touchpad backend only has to produce
-			the same two-contact frame. The native max-X/Y commands
-			(<code>0x0106</code>/<code>0x0107</code>) give the corner zone a
-			physical coordinate frame.</li>
+			(X/Y high bits, X low, Y low, size, pressure). Synaptics report 3
+			carries five 5-byte finger records (tip/confidence, contact id,
+			16-bit X/Y), then scan time, contact count and the clickpad bit.
+			Both decoders feed the device-independent
+			<span class="file">touchpad_gesture.c</span> engine; another
+			touchpad backend only has to produce the same two-contact frame.
+			The Synaptics Y axis is inverted by default to match the Elan's
+			upward frame; <code>touchpad invert on|off</code> selects it.</li>
 			<li><strong>Tap gestures.</strong> A short stationary contact is
 			turned into a synthetic button press: two fingers is a right click,
 			one finger starting in the bottom-right zone (right 25% x bottom
@@ -611,9 +634,11 @@
 			<li><strong>Discovery and tuning.</strong> <code>touchpad</code>
 			prints the probe result, max coordinates, last report and synthesized
 			click counters, and takes <code>rightclick off|tap|corner|both</code>,
-			<code>tapclick on|off</code> or
-			<code>scroll on|off|natural|traditional</code>; <code>mouseinfo</code>
-			lists the Elan vendor/product ID next to the PS/2 and USB backends.</li>
+			<code>tapclick on|off</code>,
+			<code>scroll on|off|natural|traditional</code> or
+			<code>invert on|off</code>; <code>mouseinfo</code>
+			lists the Elan/Synaptics vendor/product ID next to the PS/2 and USB
+			backends.</li>
 		</ul>
 	</section>
 
@@ -621,37 +646,47 @@
 		<h2>Serial</h2>
 		<p>
 			<span class="file">serial.c</span> drives the 16550 at COM1, 115200
-			8N1, with an IRQ-driven receive ring buffer. It is used for the boot
-			trace, the netlog mirror source, the <code>dbg</code> monitor and the
-			<code>KXE2</code> kexec receiver.
+			8N1, with a receive ring drained from the PIT stub. It is used for the
+			boot trace, the netlog mirror source, the <code>dbg</code> monitor and
+			the <code>KXE2</code> kexec receiver.
 		</p>
 		<p>
 			The transmitter is polled, so a machine without a serial port still
-			boots normally. <code>serial_puthex</code> and
-			<code>serial_putdec</code> are the structured dump helpers used by
-			drivers.
+			boots normally. <code>serial_init()</code> probes COM1 first: a missing
+			UART leaves LSR and IIR at <code>0xFF</code> (a real 16550 has LSR bit
+			7 zero and a <code>0x01</code>/<code>0xC1</code> IIR), so the port is
+			marked dead and printed as <code>com1: absent</code>. A floating LSR is
+			also refused by <code>serial_poll()</code>, which only drains while DR
+			is set. This matters on a serial-less eSPI laptop (the Yoga 720-13IKB
+			has only an MMIO LPSS UART): the old 256×2 I/O drain ran on every PIT
+			tick and froze the boot after <code>[process]</code>. The boot console
+			and netlog mirrors are still fed before the dead check.
+			<code>serial_puthex</code> and <code>serial_putdec</code> are the
+			structured dump helpers used by drivers.
 		</p>
 	</section>
 
 	<section id="sensors">
 		<h2>Sensors, power &amp; thermals</h2>
 		<ul>
-			<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>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, Airmont/Braswell and Kaby Lake-U (<code>0x8E</code>, the Yoga) models. TjMax comes from <code>IA32_TEMPERATURE_TARGET</code> on Nehalem/Westmere and Kaby Lake; Airmont uses coretemp's 90 °C table (the kernel does not read the MSR before the IDT exists), and Bonnell uses the table. The Yoga's Linux <code>x86_pkg_temp</code> reads 61-71 °C; the PCH <code>pch_skylake</code> (49-52 °C) and the INT3403 <code>SEN1</code>/<code>SEN2</code>/<code>B0D4</code> sensors are not read because the DPTF tables are not parsed. 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 vendor and a <code>ThinkPad</code> product or version string; IdeaPads/Yogas share the vendor but have a different ACPI EC register map, so the ThinkPad probe leaves them alone (the IdeaPad backend below handles theirs). It 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>IdeaPad/Yoga EC.</strong> <span class="file">ideapad.c</span> reads <code>BAT1</code> and <code>ACAD</code> without an ACPI interpreter. The DSDT's <code>BAT1</code> methods take their fields from the PCH EC memory window at <code>0xFF000800</code> (a <code>SystemMemory</code> OperationRegion, not the <code>0x62/0x66</code> EC): <code>BST0</code> <code>0xC1</code>, <code>BRC0</code> <code>0xC2</code>, <code>BPV0</code> <code>0xC6</code>, <code>BDV0</code> <code>0xC8</code>, <code>BDC0</code> <code>0xCA</code>, <code>BFC0</code> <code>0xCC</code>, <code>CYC0</code> <code>0xCF</code>, <code>BAC0</code> <code>0xD2</code>, <code>BFCB</code> <code>0xED</code>, <code>ORRF</code> <code>0xF1</code> bit 6 and <code>ADPT</code> <code>0xA3</code> bit 7. <code>BAM0</code> (0xC0 bit 1) selects the 1/10 capacity scale and the mA-to-mW rate conversion, and <code>BMF0</code> (bits 4..7, 6 = SIMPLO) the pack vendor. The probe validates capacity, voltage and the status/vendor bits and only reads the window. Linux's <code>BAT1</code> on the Yoga reports 29.78/29.9 Wh, 8.657 V, 3.2 W, model <code>PABAS0241231</code> (SIMPLO), <code>ACAD</code> online; <span class="file">power_src.c</span> selects the ThinkPad EC first, then the IdeaPad EC, then the Chrome EC.</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>
 		<p>
 			<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
-			source (<code>thinkpad</code> or <code>chrome ec</code>), the AC
+			board sensors and all three EC types; <code>powerinfo</code> prints the
+			source (<code>thinkpad</code>, <code>ideapad</code> or
+			<code>chrome ec</code>), the AC
 			adapter, battery model/manufacturer/serial, capacities, voltage,
 			rate and cycle count through <code>SYS_POWER_INFO</code>;
 			<code>power</code> prints ratios, effective MHz and C-state hints.
-			The WM top bar shows the CPU temperature and, on both ThinkPads
-			and Chromebooks, a status icon at the far right for the first
+			The WM top bar shows the CPU temperature and, on ThinkPads,
+			IdeaPads/Yogas and Chromebooks, a status icon at the far right for the first
 			present battery: a plug while the AC adapter is online and a
 			level-filled battery on battery.  Machines without an EC show
 			neither.
@@ -718,8 +753,8 @@
 			<li><strong>AHCI.</strong> First controller only, no hotplug after boot, disks above 2 TB are clamped to 32-bit LBA.</li>
 			<li><strong>eMMC.</strong> Polled 1-bit/25 MHz PIO; no DMA, IRQ, CMD6 bus-width/high-speed/DDR switch or hotplug. Only the eMMC function is driven; the SDIO/SD functions and SD card reader are not.</li>
 			<li><strong>Storage serialization.</strong> A FAT/floppy operation sets <code>sys_fs_busy</code> and stalls process switching for its duration; the PIT keeps ticking.</li>
-			<li><strong>EC.</strong> The Chrome EC path uses the ACPI v2 memmap only: no MEC host-command interface, EC SCI events, charger current/voltage, charging limit or EC firmware version. The ThinkPad H8 path is limited to its page-selected battery window and has no SCI handler. Battery/AC is polled by the WM once a second.</li>
-			<li><strong>WiFi.</strong> Intel 7265 rev D/3165 (7265D firmware) and 6200/6300 (6000 firmware, written without hardware in the loop); WPA2-PSK/CCMP and open networks, no WPA3/SAE, 802.1X, TKIP or WEP. No roaming, power save, background scan, HT/VHT, aggregation or rate scaling. Group rekeys need the background <code>wifi __keep</code> helper running. RX CCMP falls back to the byte-oriented software AES-CCM path when the firmware rejects the installed keys, so it has no replay window and is CPU-bound at high RX rates.</li>
+			<li><strong>EC.</strong> The Chrome EC path uses the ACPI v2 memmap only: no MEC host-command interface, EC SCI events, charger current/voltage, charging limit or EC firmware version. The ThinkPad H8 path is limited to its page-selected battery window and has no SCI handler. The IdeaPad path maps the DSDT's EC memory window and only reads <code>BAT1</code>/<code>ACAD</code> (there is no ACPI interpreter, no EC SCI/notify handling, and the model/serial strings are the DSDT defaults). Battery/AC is polled by the WM once a second.</li>
+			<li><strong>WiFi.</strong> Intel 7265 rev D/3165 (7265D firmware), 8265 (8265-36 firmware, the 8000 loader is not yet hardware-validated) and 6200/6300 (6000 firmware, written without hardware in the loop); WPA2-PSK/CCMP and open networks, no WPA3/SAE, 802.1X, TKIP or WEP. No roaming, power save, background scan, HT/VHT, aggregation or rate scaling. Group rekeys need the background <code>wifi __keep</code> helper running. RX CCMP falls back to the byte-oriented software AES-CCM path when the firmware rejects the installed keys, so it has no replay window and is CPU-bound at high RX rates.</li>
 			<li><strong>RTL8821AU.</strong> High-speed EHCI/xHCI only (no UHCI/OHCI bulk). No IQ calibration, thermal power tracking, DIG, BT coexistence or by-rate/regulatory TX power tables (the eFuse base index is used for every rate); 20 MHz legacy rates only. Only one bulk device can stream on xHCI at a time (single bulk ring), so it does not mix with an ASIX dongle or a USB stick transfer.</li>
 			<li><strong>Suspend.</strong> There is no S0ix/suspend path; package C-states and the EC sleep handshake remain firmware-managed.</li>
 		</ul>
@@ -737,8 +772,8 @@
 			<li><code>kernel/uhci.c</code>, <code>kernel/ohci.c</code>, <code>kernel/ehci.c</code>, <code>kernel/xhci.c</code></li>
 			<li><code>kernel/usbmsc.c</code>, <code>kernel/usbmsc.h</code> — USB BOT/SCSI mass storage</li>
 			<li><code>kernel/rndis.c</code>, <code>kernel/rndis.h</code> — USB RNDIS tethering</li>
-			<li><code>kernel/iwl_trans.c</code>, <code>kernel/iwl_trans.h</code> — Intel WiFi PCIe transport (7000 and 6000 families)</li>
-			<li><code>kernel/iwl_mvm.c</code>, <code>kernel/iwl_mvm.h</code> — 7265D/3165 firmware commands (MVM)</li>
+			<li><code>kernel/iwl_trans.c</code>, <code>kernel/iwl_trans.h</code> — Intel WiFi PCIe transport (7000, 8000 and 6000 families)</li>
+			<li><code>kernel/iwl_mvm.c</code>, <code>kernel/iwl_mvm.h</code> — 7265D/3165/8265 firmware commands (MVM)</li>
 			<li><code>kernel/iwl_dvm.c</code>, <code>kernel/iwl_dvm.h</code> — 6200/6300 firmware commands (DVM)</li>
 			<li><code>kernel/wifi_fw.c</code>, <code>kernel/wifi_fw.h</code> — WiFi backend dispatch (Intel MVM/DVM, RTL8821AU)</li>
 			<li><code>kernel/rtl8821au.c</code>, <code>kernel/rtl8821au.h</code> — Realtek RTL8821AU USB WiFi</li>
@@ -749,11 +784,11 @@
 			<li><code>kernel/backlight.c</code>, <code>kernel/backlight.h</code> — Cherryview/Braswell panel PWM</li>
 			<li><code>kernel/usbhid.c</code>, <code>kernel/mouse.c</code>, <code>kernel/io.c</code> — input</li>
 			<li><code>kernel/i2c.c</code>, <code>kernel/i2c.h</code> — DesignWare/LPSS I2C master</li>
-			<li><code>kernel/touchpad.c</code>, <code>kernel/touchpad.h</code> — Elan HID-over-I2C touchpad</li>
+			<li><code>kernel/touchpad.c</code>, <code>kernel/touchpad.h</code> — Elan/Synaptics HID-over-I2C touchpads</li>
 			<li><code>kernel/touchpad_gesture.c</code>, <code>kernel/touchpad_gesture.h</code> — device-independent contact gestures (tap, right-click zones, scroll)</li>
 			<li><code>kernel/touchpad_gesture_test.c</code> — host test (<code>make test-touchpad</code>)</li>
 			<li><code>kernel/serial.c</code>, <code>kernel/serial_ring_buf.c</code></li>
-			<li><code>kernel/thermal.c</code>, <code>kernel/it87.c</code>, <code>kernel/tpec.c</code>, <code>kernel/ec.c</code>, <code>kernel/cros_ec.c</code>, <code>kernel/power_src.c</code>, <code>kernel/mtrr.c</code></li>
+			<li><code>kernel/thermal.c</code>, <code>kernel/it87.c</code>, <code>kernel/tpec.c</code>, <code>kernel/ec.c</code>, <code>kernel/cros_ec.c</code>, <code>kernel/ideapad.c</code>, <code>kernel/power_src.c</code>, <code>kernel/mtrr.c</code></li>
 			<li><code>kernel/rtc.c</code> — CMOS wall clock read/write</li>
 			<li><code>kernel/panic.c</code>, <code>kernel/timer.S</code> — fatal exceptions</li>
 		</ul>

+ 4 - 4
docs/graphics.html

@@ -691,11 +691,11 @@
 			<code>intel_backlight</code>.
 		</p>
 		<ul>
-			<li><strong>Registers.</strong> <code>BLC_PWM_CTL2</code> at GPU BAR0 + <code>0x1E1250</code> (pipe A; pipe B is <code>+0x100</code>): bit 31 enables, bit 28 is polarity. <code>BLC_PWM_CTL</code> at <code>0x1E1254</code>: period in bits 31:16, duty in bits 15:0. The Cherryview PWM clock is 19.2 MHz with a fixed /16 increment, so 200 Hz is a period of 6000.</li>
-			<li><strong>Probe.</strong> <span class="file">backlight.c</span> matches Intel <code>8086:22b0</code>/<code>22b1</code>, maps the graphics MMIO BAR, reads both pipes, follows the one the firmware enabled and falls back to controller 0. It logs the chosen pipe, period, duty and raw registers to COM1.</li>
+			<li><strong>Registers.</strong> Cherryview: <code>BLC_PWM_CTL2</code> at GPU BAR0 + <code>0x1E1250</code> (pipe A; pipe B is <code>+0x100</code>): bit 31 enables, bit 28 is polarity. <code>BLC_PWM_CTL</code> at <code>0x1E1254</code>: period in bits 31:16, duty in bits 15:0. The Cherryview PWM clock is 19.2 MHz with a fixed /16 increment, so 200 Hz is a period of 6000. Sunrise Point-LP uses the same layout at <code>BLC_PWM_CTL2 = 0xC8250</code> and <code>BLC_PWM_CTL = 0xC8254</code>; the Yoga 720's firmware leaves period 535 / duty 96, matching Linux's <code>intel_backlight</code> max 535.</li>
+			<li><strong>Probe.</strong> <span class="file">backlight.c</span> matches Intel <code>8086:22b0</code>/<code>22b1</code> (Cherryview) and <code>8086:5916</code>/<code>591e</code>/<code>5926</code> (Kaby Lake), maps the graphics MMIO BAR, reads both pipes, follows the one the firmware enabled and falls back to controller 0. It logs the chosen pipe, period, duty and raw registers to COM1.</li>
 			<li><strong>Use.</strong> The <code>backlight</code> command prints the percentage and PWM state; <code>backlight up|down</code> steps by 10%, <code>backlight 0-100</code> sets a level (clamped to 5..100), and <code>backlight probe</code> dumps both pipes' registers. <code>SYS_BACKLIGHT</code> gives ring 3 the same get/set/step, which drives the quick-settings popover's brightness slider and the Settings Power page. F6/F7 (the ChromeOS EC action-row brightness keys) and the standard <code>E0 14</code>/<code>E0 15</code> brightness scancodes adjust it; the keys are consumed in <span class="file">io.c</span> and never reach a window.</li>
 			<li><strong>Overlay.</strong> <code>SYS_WM_POLL</code> also reports the backlight percentage and a change counter. After each change the ring-3 WM (<span class="file">ucmd_wm.c</span>) draws a centered <em>Brightness</em> bubble with a sun icon, the percentage and a level bar, keeps it up for 3 s, and composits it above the windows on every pass while it is visible.</li>
-			<li><strong>Limits.</strong> Only the Cherryview/Braswell native PWM (<code>8086:22b0</code>/<code>22b1</code>) is driven. The level is not persisted; a cold boot returns to the firmware's duty.</li>
+			<li><strong>Limits.</strong> The Cherryview/Braswell native PWM (<code>8086:22b0</code>/<code>22b1</code>) and the Sunrise Point-LP PCH PWM on Kaby Lake (<code>8086:5916</code>) are driven. The level is not persisted; a cold boot returns to the firmware's duty.</li>
 		</ul>
 	</section>
 
@@ -723,7 +723,7 @@
 			<li><code>user/apps/files/ucmd_files.c</code>, <code>user/apps/process/ucmd_process.c</code>, <code>user/apps/gallery/gallery.c</code>, <code>user/apps/solitaire/ucmd_solitaire.c</code>, <code>user/apps/chat/ucmd_chat.c</code></li>
 			<li><code>user/lib/img/img*.c</code> — image codecs</li>
 			<li><code>kernel/ati.c</code>, <code>kernel/nvidia.c</code>, <code>kernel/intel.c</code>, <code>kernel/nv50.c</code></li>
-			<li><code>kernel/backlight.c</code>, <code>kernel/backlight.h</code> — Cherryview/VLV panel PWM</li>
+			<li><code>kernel/backlight.c</code>, <code>kernel/backlight.h</code> — Cherryview/VLV and Sunrise Point-LP PCH panel PWM</li>
 			<li><code>kernel/cursor.c</code>, <code>kernel/cursor.h</code>, <code>kernel/mouse.c</code>, <code>kernel/cursor_shape.h</code> — cursor bundle loader, drawing and the built-in fallback arrow; <code>kernel/cirrus.c</code>, <code>kernel/radeon.c</code> — hardware cursors</li>
 			<li><code>include/icon_abi.h</code>, <code>tools/mkicons.c</code>, <code>assets/icons/adwaita/</code> — UI icon list, the NBICO1 bundle and the Adwaita symbolic SVGs</li>
 			<li><code>include/app_icon_abi.h</code>, <code>tools/mkappicons.c</code>, <code>assets/icons/apps/</code> — full-colour app icon list, the NBAPP1 bundle, the upstream GNOME app SVGs and their 96 px renders</li>

+ 2 - 2
docs/index.html

@@ -202,7 +202,7 @@
 			</a>
 			<a class="card" href="drivers.html">
 				<h3>Drivers &amp; buses</h3>
-				<p>PCI enumeration, FDC/PATA/SATA/eMMC, the USB core and four host controllers, HID, the I2C touchpad, serial, board sensors and the ThinkPad/Chrome EC power sources.</p>
+				<p>PCI enumeration, FDC/PATA/SATA/eMMC, the USB core and four host controllers, HID, the I2C touchpad, serial, board sensors and the ThinkPad/IdeaPad/Chrome EC power sources.</p>
 				<span class="card-tag">drivers.html</span>
 			</a>
 			<a class="card" href="filesystems.html">
@@ -222,7 +222,7 @@
 			</a>
 			<a class="card" href="drivers.html#wifi">
 				<h3>WiFi</h3>
-				<p>Intel 7265D/3165 (Chromebook, MVM firmware) and 6200/6300 (ThinkPad X201, DVM firmware) on one PCIe transport, plus Realtek RTL8821AU USB sticks; firmware from the command pack, open and WPA2-PSK/CCMP with the handshake in ring 3.</p>
+				<p>Intel 7265D/3165 (Chromebook, MVM firmware), 8265 (Yoga 720, 8000 MVM firmware) and 6200/6300 (ThinkPad X201, DVM firmware) on one PCIe transport, plus Realtek RTL8821AU USB sticks; firmware from the command pack, open and WPA2-PSK/CCMP with the handshake in ring 3.</p>
 				<span class="card-tag">drivers.html#wifi</span>
 			</a>
 			<a class="card" href="network.html#chat">

+ 1 - 1
docs/memory.html

@@ -319,7 +319,7 @@
 	<section id="pack">
 		<h2>Rootfs pack lifetime</h2>
 		<ol>
-			<li>The compressed pack is at most 4 MB (<code>PACK_MAX</code>), so the legacy copy ends below <code>0xD00000</code>, still inside the 16 MB no-E820 fallback; inflated it is about 4.35 MB with the WiFi firmware (the 8 MB <code>RAMFS_MAX_DECOMPRESSED</code> cap applies).</li>
+			<li>The compressed pack is at most 4 MB (<code>PACK_MAX</code>), so the legacy copy ends below <code>0xD00000</code>, still inside the 16 MB no-E820 fallback; inflated it is about 7.3 MB with the WiFi firmware (the 8 MB <code>RAMFS_MAX_DECOMPRESSED</code> cap applies, leaving ~0.7 MB).</li>
 			<li>The boot path places the gzip pack in RAM: the legacy stage copies it directly to <code>0x900000</code> with a protected-mode <code>rep movsb</code>, UEFI into a loader-data buffer below 1 GB, kexec in its staging buffer.</li>
 			<li><code>mm_init</code> reserves <code>[pack_addr, pack_addr + pack_size)</code> so the frame allocator cannot reuse it.</li>
 			<li><code>ramfs_init</code> takes a private page-allocated copy, validates the <code>NBROOT1</code> header and inflates the pack into it.</li>

+ 5 - 5
docs/network.html

@@ -175,9 +175,9 @@
 		</p>
 		<p>
 			<span class="file">wifi.c</span> is the built-in WiFi of the
-			Chromebook (Intel 7265D/3165) and of the ThinkPad X201 (Intel
-			6200/6300), or a Realtek RTL8821AU USB stick when one is plugged
-			in, see the
+			Chromebook (Intel 7265D/3165), the Yoga 720 (Intel 8265) and the
+			ThinkPad X201 (Intel 6200/6300), or a Realtek RTL8821AU USB stick
+			when one is plugged in, see the
 			<a href="drivers.html#wifi">driver page</a>). It is last in the
 			registry, so the boot probe only makes it active when nothing
 			wired is present (a later <code>wifi connect</code> can still select
@@ -234,7 +234,7 @@
 					<tr><td><span class="file">ne2000.c</span></td><td>RTL8029</td><td>ISA / QEMU PCI</td><td>Simple DP8390 path used by <code>make run-net</code>.</td></tr>
 					<tr><td><span class="file">asix.c</span></td><td>AX88772</td><td>USB bulk</td><td>Runs over the USB core; usable on EHCI/xHCI dongles.</td></tr>
 					<tr><td><span class="file">rndis.c</span></td><td>Android USB tethering, QEMU <code>usb-net</code></td><td>USB control + bulk</td><td>RNDIS INIT/QUERY/packet filter; presents the phone's tethering link as an Ethernet netdev.</td></tr>
-					<tr><td><span class="file">wifi.c</span></td><td>Intel 7265D / 3165 (Chromebook), 6200 / 6300 (X201), Realtek RTL8821AU USB stick</td><td>PCIe (firmware) or USB</td><td>Open and WPA2-PSK/CCMP; firmware loaded on first use; link down until <code>wifi connect</code>.</td></tr>
+					<tr><td><span class="file">wifi.c</span></td><td>Intel 7265D / 3165 (Chromebook), 8265 (Yoga 720), 6200 / 6300 (X201), Realtek RTL8821AU USB stick</td><td>PCIe (firmware) or USB</td><td>Open and WPA2-PSK/CCMP; firmware loaded on first use; link down until <code>wifi connect</code>.</td></tr>
 				</tbody>
 			</table>
 		</div>
@@ -525,7 +525,7 @@
 		<ul class="filelist">
 			<li><code>kernel/netdev.c</code>, <code>kernel/netdev.h</code> — registry</li>
 			<li><code>kernel/e1000e.c</code>, <code>kernel/r8168.c</code>, <code>kernel/ne2000.c</code>, <code>kernel/asix.c</code>, <code>kernel/rndis.c</code></li>
-			<li><code>kernel/wifi.c</code>, <code>kernel/wifi_fw.c</code>, <code>kernel/iwl_mvm.c</code>, <code>kernel/iwl_dvm.c</code>, <code>kernel/iwl_trans.c</code>, <code>kernel/rtl8821au.c</code> — Intel 7265D/3165 and 6200/6300 WiFi, Realtek RTL8821AU USB WiFi</li>
+			<li><code>kernel/wifi.c</code>, <code>kernel/wifi_fw.c</code>, <code>kernel/iwl_mvm.c</code>, <code>kernel/iwl_dvm.c</code>, <code>kernel/iwl_trans.c</code>, <code>kernel/rtl8821au.c</code> — Intel 7265D/3165/8265 and 6200/6300 WiFi, Realtek RTL8821AU USB WiFi</li>
 			<li><code>user/lib/wifi/wpa.c</code>, <code>user/lib/tls/wpa_crypto.c</code>, <code>user/apps/wifi/ucmd_wifi.c</code> — WPA2-PSK supplicant and the <code>wifi</code> command (<code>make test-wpa</code>)</li>
 			<li><code>user/apps/netmenu/ucmd_netmenu.c</code>, <code>user/apps/settings/ucmd_settings.c</code>, <code>include/wifi_cfg.h</code>, <code>user/lib/wifi/wifi_store.c/h</code> — top-bar quick popover, Settings window (NIC/WiFi pages), staged WiFi connect request and the saved-network list</li>
 			<li><code>kernel/net.c</code>, <code>kernel/net.h</code> — ARP cache/ICMP/UDP/IP</li>

+ 1 - 0
include/syscall.h

@@ -208,6 +208,7 @@ struct sys_bootlog {
 #define SYS_POWER_SRC_NONE 0
 #define SYS_POWER_SRC_TPEC 1   /* ThinkPad H8 EC */
 #define SYS_POWER_SRC_CROS 2   /* Chrome OS EC */
+#define SYS_POWER_SRC_IDEAPAD 3  /* IdeaPad/Yoga ACPI EC (BAT1/ACAD) */
 
 /* Chrome OS EC temperature/fan/switch snapshot (see cros_ec.c). */
 #define SYS_CROS_EC_SENSORS 107  /* (struct sys_cros_sensors *out) -> 0/-1 */

+ 57 - 18
kernel/backlight.c

@@ -24,12 +24,23 @@
 
 #define INTEL_CHV_GFX_B0	0x22b0
 #define INTEL_CHV_GFX_C0	0x22b1
+#define INTEL_KBL_GFX_GT2	0x5916	/* Yoga 720-13IKB HD 620 */
+#define INTEL_KBL_GFX_GT2_2	0x591e
+#define INTEL_KBL_GFX_GT2_3	0x5926
 
 #define VLV_DISPLAY_BASE	0x180000u
 #define VLV_BLC_PWM_CTL2(pipe)	(VLV_DISPLAY_BASE + 0x61250u + \
 				 ((pipe) ? 0x100u : 0u))
 #define VLV_BLC_PWM_CTL(pipe)	(VLV_DISPLAY_BASE + 0x61254u + \
 				 ((pipe) ? 0x100u : 0u))
+/* Sunrise Point-LP PCH display PWM, same register layout at 0xC825x. */
+#define PCH_BLC_PWM_CTL2(pipe)	(0xc8250u + ((pipe) ? 0x100u : 0u))
+#define PCH_BLC_PWM_CTL(pipe)	(0xc8254u + ((pipe) ? 0x100u : 0u))
+
+enum {
+	BLC_KIND_VLV,
+	BLC_KIND_PCH,
+};
 
 #define BLM_PWM_ENABLE		(1u << 31)
 #define BLC_DUTY_MASK		0xFFFFu
@@ -39,6 +50,7 @@
 
 static unsigned int blc_bar;      /* physical BAR (reported) */
 static unsigned int blc_regs;     /* its kernel mapping */
+static int blc_kind = BLC_KIND_VLV;
 static unsigned int blc_pipe;
 static unsigned int blc_period;
 static unsigned int blc_duty;
@@ -47,6 +59,25 @@ static int blc_present;
 static int blc_enabled;
 static unsigned int blc_seq;	/* bumped on every user-visible change */
 
+static unsigned int blc_ctl2_reg(unsigned int pipe)
+{
+	return blc_kind == BLC_KIND_PCH ? PCH_BLC_PWM_CTL2(pipe) :
+					  VLV_BLC_PWM_CTL2(pipe);
+}
+
+static unsigned int blc_ctl_reg(unsigned int pipe)
+{
+	return blc_kind == BLC_KIND_PCH ? PCH_BLC_PWM_CTL(pipe) :
+					  VLV_BLC_PWM_CTL(pipe);
+}
+
+static unsigned int blc_dsp_reg(unsigned int pipe)
+{
+	unsigned int off = 0x70180u + (pipe ? 0x1000u : 0u);
+
+	return blc_kind == BLC_KIND_PCH ? off : VLV_DISPLAY_BASE + off;
+}
+
 static unsigned int blc_read(unsigned int reg)
 {
 	return *(volatile unsigned int *)(blc_regs + reg);
@@ -70,8 +101,15 @@ void backlight_init(unsigned int bus, unsigned int dev, unsigned int device_id)
 	blc_present = 0;
 	blc_enabled = 0;
 
-	if (device_id != INTEL_CHV_GFX_B0 && device_id != INTEL_CHV_GFX_C0)
+	if (device_id == INTEL_CHV_GFX_B0 || device_id == INTEL_CHV_GFX_C0) {
+		blc_kind = BLC_KIND_VLV;
+	} else if (device_id == INTEL_KBL_GFX_GT2 ||
+		   device_id == INTEL_KBL_GFX_GT2_2 ||
+		   device_id == INTEL_KBL_GFX_GT2_3) {
+		blc_kind = BLC_KIND_PCH;
+	} else {
 		return;
+	}
 
 	bar0 = pci_cfg_read32(bus, dev, 0, 0x10);
 	if (bar0 & 1)
@@ -91,8 +129,8 @@ void backlight_init(unsigned int bus, unsigned int dev, unsigned int device_id)
 	}
 
 	for (i = 0; i < 2; i++) {
-		ctl2[i] = blc_read(VLV_BLC_PWM_CTL2(i));
-		ctl[i] = blc_read(VLV_BLC_PWM_CTL(i));
+		ctl2[i] = blc_read(blc_ctl2_reg(i));
+		ctl[i] = blc_read(blc_ctl_reg(i));
 	}
 
 	a_ok = !(ctl2[0] == 0xFFFFFFFFu && ctl[0] == 0xFFFFFFFFu);
@@ -110,8 +148,8 @@ void backlight_init(unsigned int bus, unsigned int dev, unsigned int device_id)
 		pipe = 1;
 	} else if (b_ok &&
 		   (ctl2[0] & BLM_PWM_ENABLE) == (ctl2[1] & BLM_PWM_ENABLE)) {
-		unsigned int dspa = blc_read(VLV_DISPLAY_BASE + 0x70180);
-		unsigned int dspb = blc_read(VLV_DISPLAY_BASE + 0x71180);
+		unsigned int dspa = blc_read(blc_dsp_reg(0));
+		unsigned int dspb = blc_read(blc_dsp_reg(1));
 
 		if (!(dspa & (1u << 31)) && (dspb & (1u << 31)))
 			pipe = 1;
@@ -137,7 +175,8 @@ void backlight_init(unsigned int bus, unsigned int dev, unsigned int device_id)
 	blc_enabled = (ctl2[pipe] & BLM_PWM_ENABLE) != 0;
 	blc_present = 1;
 
-	serial_puts(SERIAL_COM1, "backlight: CHV PWM pipe ");
+	serial_puts(SERIAL_COM1, blc_kind == BLC_KIND_PCH ?
+		    "backlight: PCH PWM pipe " : "backlight: CHV PWM pipe ");
 	serial_puts(SERIAL_COM1, pipe ? "B" : "A");
 	serial_puts(SERIAL_COM1, ", period ");
 	serial_putdec(SERIAL_COM1, period);
@@ -190,19 +229,19 @@ void backlight_set_percent(int percent)
 		duty = 1;
 
 	if (!blc_enabled) {
-		ctl2 = blc_read(VLV_BLC_PWM_CTL2(blc_pipe));
-		blc_write(VLV_BLC_PWM_CTL2(blc_pipe), ctl2 & ~BLM_PWM_ENABLE);
-		blc_write(VLV_BLC_PWM_CTL(blc_pipe),
+		ctl2 = blc_read(blc_ctl2_reg(blc_pipe));
+		blc_write(blc_ctl2_reg(blc_pipe), ctl2 & ~BLM_PWM_ENABLE);
+		blc_write(blc_ctl_reg(blc_pipe),
 			  (blc_period << 16) | duty);
-		(void)blc_read(VLV_BLC_PWM_CTL(blc_pipe));
-		blc_write(VLV_BLC_PWM_CTL2(blc_pipe),
+		(void)blc_read(blc_ctl_reg(blc_pipe));
+		blc_write(blc_ctl2_reg(blc_pipe),
 			  (ctl2 & ~BLM_PWM_ENABLE) | BLM_PWM_ENABLE);
-		(void)blc_read(VLV_BLC_PWM_CTL2(blc_pipe));
+		(void)blc_read(blc_ctl2_reg(blc_pipe));
 		blc_enabled = 1;
 	} else {
-		blc_write(VLV_BLC_PWM_CTL(blc_pipe),
+		blc_write(blc_ctl_reg(blc_pipe),
 			  (blc_period << 16) | duty);
-		(void)blc_read(VLV_BLC_PWM_CTL(blc_pipe));
+		(void)blc_read(blc_ctl_reg(blc_pipe));
 	}
 
 	blc_duty = duty;
@@ -238,9 +277,9 @@ int backlight_status(struct backlight_status *out)
 	out->duty = blc_duty;
 	out->bar = blc_bar;
 	/* Keep the two pipe snapshots live for the `backlight probe` dump. */
-	out->ctl2[0] = blc_read(VLV_BLC_PWM_CTL2(0));
-	out->ctl2[1] = blc_read(VLV_BLC_PWM_CTL2(1));
-	out->ctl[0] = blc_read(VLV_BLC_PWM_CTL(0));
-	out->ctl[1] = blc_read(VLV_BLC_PWM_CTL(1));
+	out->ctl2[0] = blc_read(blc_ctl2_reg(0));
+	out->ctl2[1] = blc_read(blc_ctl2_reg(1));
+	out->ctl[0] = blc_read(blc_ctl_reg(0));
+	out->ctl[1] = blc_read(blc_ctl_reg(1));
 	return 0;
 }

+ 7 - 8
kernel/i2c.c

@@ -7,7 +7,7 @@
  *
  * Register offsets follow the DesignWare databook; the component type at
  * 0xFC is the usual "DW" signature (0x44570140).  The Intel LPSS private
- * block at 0x800 holds the reset release register; firmware has already
+ * block is at 0x200 with its reset register at 0x204; firmware has already
  * released the controller, but the I2C FSM only drains its FIFOs after an
  * explicit assert/release cycle, so i2c_dw_init() always does one. */
 
@@ -116,17 +116,16 @@ unsigned int i2c_dw_comp_type(unsigned int base)
 
 void i2c_dw_reset_release(unsigned int base)
 {
-	/* Bay Trail/Braswell put the LPSS private block at 0x800 (reset at
-	 * 0x804); newer LPSS layouts put it at 0x200 (reset at 0x204).  The
-	 * Linux intel-lpss driver asserts the reset first and then releases
-	 * it, so do both here: a block left in functional reset keeps the
+	/* The LPSS private block is at 0x200 and its reset register at 0x204
+	 * (Linux intel-lpss LPSS_PRIV_RESETS).  0x800 is the iDMA64 block,
+	 * not a second private block, so it is left alone.  The Linux
+	 * intel-lpss driver asserts the reset first and then releases it
+	 * (FUNC | IDMA bits); a block left in functional reset keeps the
 	 * register file alive but never clocks the I2C master FSM, which
 	 * looks exactly like "commands sit in the TX FIFO forever". */
-	dw_wr(base, 0x804, 0);
 	dw_wr(base, 0x204, 0);
 	dw_delay_ms(1);
-	dw_wr(base, 0x804, 3);
-	dw_wr(base, 0x204, 3);
+	dw_wr(base, 0x204, 7);
 	dw_delay_ms(1);
 }
 

+ 174 - 0
kernel/ideapad.c

@@ -0,0 +1,174 @@
+/* IdeaPad/Yoga ACPI EC battery and AC (Lenovo Yoga 720-13IKB).
+ *
+ * The DSDT BAT1 device reads the battery fields from the PCH EC memory
+ * window at 0xFF000800 (SystemMemory OperationRegion ECMM), not from the
+ * 0x62/0x66 EmbeddedControl region.  The field layout, straight from the
+ * DSDT:
+ *
+ *   0xC0  BTY0:1 BAM0:1 BAL0:1 0:1 BMF0:4   (BMF0 6 = SIMPLO)
+ *   0xC1  BST0   battery state (bit 0 discharging, bit 1 charging)
+ *   0xC2  BRC0   remaining capacity (16-bit)
+ *   0xC6  BPV0   present voltage, mV (16-bit)
+ *   0xC8  BDV0   design voltage, mV (16-bit)
+ *   0xCA  BDC0   design capacity (16-bit)
+ *   0xCC  BFC0   last full capacity (16-bit)
+ *   0xCF  CYC0   cycle count
+ *   0xD2  BAC0   present rate, signed 16-bit (mA when BAM0 == 0)
+ *   0xED  BFCB   alternate last-full capacity (16-bit)
+ *   0xF1  bit 6  ORRF (use BFCB when set)
+ *   0xA3  bit 7  ADPT (AC adapter online)
+ *
+ * The DSDT scales capacities by BASC = 10 when BAM0 == 0 (the pack reports
+ * in 10 mWh units) and converts BAC0 from mA to mW with BPV0.  The _BST rate
+ * is signed; we mirror that.
+ */
+#include "ideapad.h"
+#include "paging.h"
+#include "serial.h"
+#include "syscall.h"
+
+#define ECMM_BASE	0xFF000800u
+#define ECMM_SIZE	0x1000u
+
+static unsigned char *ecmm;
+
+static unsigned char *ecmm_map(void)
+{
+	if (!ecmm)
+		ecmm = (unsigned char *)ioremap(ECMM_BASE, ECMM_SIZE,
+						IOREMAP_MMIO);
+	return ecmm;
+}
+
+static unsigned int rd16(const unsigned char *p)
+{
+	return (unsigned int)p[0] | ((unsigned int)p[1] << 8);
+}
+
+static void copy_str(char *dst, unsigned int size, const char *src)
+{
+	unsigned int i = 0;
+
+	while (i + 1 < size && src[i]) {
+		dst[i] = src[i];
+		i++;
+	}
+	dst[i] = '\0';
+}
+
+/* GUBI() in the DSDT maps BMF0 to the pack vendor. */
+static const char *battery_vendor(unsigned int bmf)
+{
+	switch (bmf) {
+	case 1:  return "SANYO";
+	case 2:  return "SONY";
+	case 3:  return "SDI";
+	case 4:  return "PANASONIC";
+	case 5:  return "SAMSUNG";
+	case 6:  return "SIMPLO";
+	case 7:  return "DYNAPACK";
+	default: return "LENOVO";
+	}
+}
+
+int ideapad_present(void)
+{
+	unsigned char *p = ecmm_map();
+	unsigned int bdc, bfc, bpv;
+
+	if (!p)
+		return 0;
+	bdc = rd16(p + 0xCA);
+	bfc = rd16(p + 0xCC);
+	bpv = rd16(p + 0xC6);
+	if (bdc == 0 || bdc > 0x7FFF || bfc == 0 || bfc > 0x7FFF ||
+	    bpv < 3000 || bpv > 20000)
+		return 0;
+	/* Only the low three status bits are defined, and BMF0 is a small
+	 * pack-vendor id; anything else means 0xFF000800 is not this EC. */
+	if (p[0xC1] > 0x07)
+		return 0;
+	if (((p[0xC0] >> 4) & 0xF) > 7)
+		return 0;
+	return 1;
+}
+
+void ideapad_init(void)
+{
+	if (!ideapad_present())
+		return;
+	serial_puts(SERIAL_COM1,
+		    "ideapad: EC battery/AC at 0xFF000800\n");
+}
+
+void ideapad_power_read(struct power_info *out, int detail)
+{
+	unsigned char *p;
+	unsigned int bst, bam, bmf, basc;
+	unsigned int brc, bfc, bfi, bdc, bpv, bac, cyc, orrf;
+	unsigned int i;
+	int rate;
+	struct power_battery *b;
+
+	for (i = 0; i < sizeof(*out); i++)
+		((unsigned char *)out)[i] = 0;
+	out->ac_online = -1;
+
+	p = ecmm_map();
+	if (!p || !ideapad_present())
+		return;
+
+	out->present = 1;
+	out->source = SYS_POWER_SRC_IDEAPAD;
+	out->ac_online = (p[0xA3] >> 7) & 1;
+	out->battery_count = 1;
+
+	b = &out->battery[0];
+	b->present = 1;
+	bst = p[0xC1];
+	bam = (p[0xC0] >> 1) & 1;
+	bmf = (p[0xC0] >> 4) & 0xF;
+	basc = bam ? 1 : 10;
+
+	bdc = rd16(p + 0xCA);
+	bfc = rd16(p + 0xCC);
+	bfi = rd16(p + 0xED);
+	orrf = (p[0xF1] >> 6) & 1;
+	if (orrf && bfi)
+		bfc = bfi;
+
+	brc = rd16(p + 0xC2);
+	bpv = rd16(p + 0xC6);
+	bac = rd16(p + 0xD2);
+	cyc = p[0xCF];
+
+	rate = (int)(short)bac;
+	if (!bam)
+		rate = rate * (int)bpv / 1000;
+
+	b->status = bst;
+	b->charging = (bst & 2) != 0;
+	b->discharging = (bst & 1) != 0;
+	b->remaining = brc * basc;
+	b->full = bfc * basc;
+	b->design = bdc * basc;
+	b->voltage_mv = bpv;
+	b->rate = rate;
+	b->unit_known = 1;
+	b->unit_mwh = !bam;
+	b->percent = b->full ?
+		(int)(((unsigned long)b->remaining * 100 + b->full / 2) /
+		      b->full) : 0;
+	b->percent_valid = b->full != 0;
+	b->cycle_count = cyc;
+	copy_str(b->manufacturer, sizeof(b->manufacturer),
+		 battery_vendor(bmf));
+	copy_str(b->model, sizeof(b->model), "PABAS0241231");
+	copy_str(b->serial, sizeof(b->serial), "41167");
+
+	if (detail) {
+		copy_str(out->vendor, sizeof(out->vendor), "LENOVO");
+		copy_str(out->product, sizeof(out->product),
+			 "Yoga 720-13IKB");
+	}
+}

+ 21 - 0
kernel/ideapad.h

@@ -0,0 +1,21 @@
+/* IdeaPad/Yoga ACPI EC battery and AC (see ideapad.c).
+ *
+ * The Yoga 720-13IKB exposes BAT1/ACAD through the ACPI EC's PCH memory
+ * window at 0xFF000800.  The DSDT _BST/_BIF methods read the fields from that
+ * window; this backend does the same without an ACPI interpreter.
+ */
+#ifndef IDEAPAD_H
+#define IDEAPAD_H
+
+#include "power_src.h"
+
+/* Probe the EC memory window.  Safe to call more than once. */
+int ideapad_present(void);
+
+/* Boot probe; logs the backend when found. */
+void ideapad_init(void);
+
+/* Fill out->battery[0] and the AC state from BAT1/ACAD. */
+void ideapad_power_read(struct power_info *out, int detail);
+
+#endif

+ 46 - 14
kernel/iwl_mvm.c

@@ -1,8 +1,10 @@
-/* Intel 7265D/3165 firmware command layer: see iwl_mvm.h.
+/* Intel 7265D/3165/8265 firmware command layer: see iwl_mvm.h.
  *
  * Follows Linux iwlmvm for the 7265D-29 API (no unified image, LMAC scan,
  * DQA queues, old station API, ADD_STA v7, ADD_STA_KEY v1, PHY context v1,
- * MAC context v1, TX_CMD v6, legacy RX_PHY + RX_MPDU):
+ * MAC context v1, TX_CMD v6, legacy RX_PHY + RX_MPDU).  The 8265 uses the
+ * same command layer with its 8000-family firmware; the transport handles
+ * the secure section loader and the MAC comes from the extended NVM.
  *
  *   INIT image: ALIVE -> BT config -> NVM (HW + SW sections) -> TX antennas
  *     -> PHY_CONFIGURATION -> CALIB_RES_NOTIF_PHY_DB ... INIT_COMPLETE
@@ -560,19 +562,49 @@ static int read_nvm(void)
 {
 	unsigned char *buf = M.scratch + 4096;   /* 4 KB is plenty for HW */
 	const unsigned char *a;
-	int n;
-
-	/* NVM HW section (nvm_hw_section_num = 0 on the 7000 family): the MAC
-	 * address is at word 0x15, stored as little-endian 16-bit words. */
-	n = nvm_read(0, buf, 4096 - 2048);
-	if (n < (0x15 + 3) * 2) {
-		logs("NVM HW section read failed");
-		return -1;
+	int n, i, valid = 0;
+
+	if (iwl_subfamily() == IWL_SUB_8265) {
+		/* 8000 extended NVM: the MAC address lives in the
+		 * MAC_OVERRIDE (MAO, section 11) at word 1; when that
+		 * section is absent, the firmware leaves it in the WFMP
+		 * registers instead (Linux iwl_set_hw_address_family_8000). */
+		n = nvm_read(11, buf, 2048);
+		if (n >= 8) {
+			a = buf + 2;
+			for (i = 0; i < 6; i++)
+				M.mac[i] = a[i];
+			valid = !(M.mac[0] & 1) &&
+				(M.mac[0] | M.mac[1] | M.mac[2] |
+				 M.mac[3] | M.mac[4] | M.mac[5]);
+		}
+		if (!valid) {
+			unsigned int m0 = iwl_rd_prph(0xa03080u);
+			unsigned int m1 = iwl_rd_prph(0xa03084u);
+
+			M.mac[0] = (m0 >> 24) & 0xff;
+			M.mac[1] = (m0 >> 16) & 0xff;
+			M.mac[2] = (m0 >> 8) & 0xff;
+			M.mac[3] = m0 & 0xff;
+			M.mac[4] = (m1 >> 8) & 0xff;
+			M.mac[5] = m1 & 0xff;
+		}
+		logs(valid ? "NVM MAC from MAO section" :
+		     "NVM MAC from WFMP registers");
+	} else {
+		/* NVM HW section (nvm_hw_section_num = 0 on the 7000
+		 * family): the MAC address is at word 0x15, stored as
+		 * little-endian 16-bit words. */
+		n = nvm_read(0, buf, 4096 - 2048);
+		if (n < (0x15 + 3) * 2) {
+			logs("NVM HW section read failed");
+			return -1;
+		}
+		a = buf + 0x15 * 2;
+		M.mac[0] = a[1]; M.mac[1] = a[0];
+		M.mac[2] = a[3]; M.mac[3] = a[2];
+		M.mac[4] = a[5]; M.mac[5] = a[4];
 	}
-	a = buf + 0x15 * 2;
-	M.mac[0] = a[1]; M.mac[1] = a[0];
-	M.mac[2] = a[3]; M.mac[3] = a[2];
-	M.mac[4] = a[5]; M.mac[5] = a[4];
 	if ((M.mac[0] & 1) || !(M.mac[0] | M.mac[1] | M.mac[2] | M.mac[3] |
 				 M.mac[4] | M.mac[5])) {
 		logs("NVM MAC address invalid");

+ 1 - 1
kernel/iwl_mvm.h

@@ -1,4 +1,4 @@
-/* Intel 7265D/3165 firmware command layer ("mvm"): see iwl_mvm.c.
+/* Intel 7265D/3165/8265 firmware command layer ("mvm"): see iwl_mvm.c.
  *
  * One station interface: MAC context 0, PHY context 0 (= binding 0), the aux
  * station 1 for scan probes and the AP station 0 on TX queue 4. */

+ 114 - 17
kernel/iwl_trans.c

@@ -25,7 +25,7 @@
  * headers. */
 struct iwl_family {
 	const char *fw_path;
-	unsigned char dvm;            /* DVM firmware (6000) vs MVM (7000) */
+	unsigned char dvm;            /* DVM firmware (6000) vs MVM (7000/8000) */
 	unsigned char tlv;            /* TLV .ucode vs the v2 fixed header */
 	unsigned char cmd_q, cmd_fifo, nq;
 	unsigned char wide_hdr;       /* mvm: trans->wide_cmd_header */
@@ -34,22 +34,31 @@ struct iwl_family {
 	unsigned char chain_ext_wa;   /* base_params->scd_chain_ext_wa */
 	unsigned char shadow_reg;     /* base_params->shadow_reg_enable */
 	unsigned char wake_me;        /* tell ME we leave (7000 family) */
+	unsigned char secure8000;     /* 8000: multi-CPU secure section load */
+	unsigned char apmg;           /* APMG clock/power block present */
+	unsigned char nvm_ext;        /* 8000 ext NVM: MAC from MAO/WFMP */
 	unsigned char q[4], q_slots[4]; /* data/mgmt queues to allocate */
 };
 
 static const struct iwl_family fam_7000 = {
 	"firmware/iwlwifi-7265D-29.ucode", 0, 1, IWL_Q_CMD, 7, 31,
-	1, 1, 1, 0, 1, 1,
+	1, 1, 1, 0, 1, 1, 0, 1, 0,
 	{ IWL_Q_AUX, IWL_Q_BSS, 0xff, 0xff }, { 8, 32, 0, 0 },
 };
 
 static const struct iwl_family fam_6000 = {
 	"firmware/iwlwifi-6000-4.ucode", 1, 0, IWL_DVM_Q_CMD, 7, 20,
-	0, 0, 0, 1, 0, 0,
+	0, 0, 0, 1, 0, 0, 0, 1, 0,
 	{ IWL_DVM_Q_VO, IWL_DVM_Q_VI, IWL_DVM_Q_BE, IWL_DVM_Q_BK },
 	{ 16, 4, 32, 4 },
 };
 
+static const struct iwl_family fam_8000 = {
+	"firmware/iwlwifi-8265-36.ucode", 0, 1, IWL_Q_CMD, 7, 31,
+	1, 1, 1, 0, 1, 0, 1, 0, 1,
+	{ IWL_Q_AUX, IWL_Q_BSS, 0xff, 0xff }, { 8, 32, 0, 0 },
+};
+
 /* ---- CSR / HBUS / FH / PRPH registers (iwl-csr.h, iwl-fh.h, iwl-prph.h) */
 #define CSR_HW_IF_CONFIG_REG     0x000
 #define CSR_INT_COALESCING       0x004
@@ -133,6 +142,12 @@ static const struct iwl_family fam_6000 = {
 #define LMPM_EXTENDED_ADDR       0x1u
 #define FW_MEM_EXT_START         0x40000u
 #define FW_MEM_EXT_END           0x57fffu
+#define FH_UCODE_LOAD_STATUS     0x1af0u   /* direct CSR */
+#define RELEASE_CPU_RESET        0x300cu   /* PRPH */
+#define RELEASE_CPU_RESET_BIT    (1u << 24)
+#define WFPM_GP2                 0xa030b4u /* PRPH */
+#define SEC_CPU1_CPU2            0xffffccccu
+#define SEC_PAGING               0xaaaabbbbu
 
 #define SCD_BASE                 0xa02c00
 #define SCD_SRAM_BASE_ADDR       (SCD_BASE + 0x0)
@@ -362,6 +377,10 @@ static const char *chip_for(unsigned int devid,
 	switch (devid) {
 	case 0x095a: case 0x095b: return "Intel Wireless 7265";
 	case 0x3165: case 0x3166: return "Intel Wireless 3165";
+	case 0x24fd:
+		*fam = &fam_8000;
+		*sub = IWL_SUB_8265;
+		return "Intel Wireless 8265";
 	}
 	*fam = &fam_6000;
 	switch (devid) {
@@ -528,7 +547,7 @@ int iwl_probe(void)
 				}
 				/* 0x095a/b: only rev-D silicon runs the 7265D
 				 * firmware (Linux: CSR_HW_REV_TYPE_7265D). */
-				if (!fam->dvm &&
+				if (!fam->dvm && !fam->secure8000 &&
 				    S->devid != 0x3165 && S->devid != 0x3166 &&
 				    (S->hw_rev & 0xfff0u) != 0x210u)
 					iwl_log("warning: not a 7265D; the 7265D firmware may fail");
@@ -718,10 +737,12 @@ static int apm_init(void)
 	}
 	if (grab_nic() < 0)
 		return -1;
-	iwl_wr_prph(APMG_CLK_EN_REG, APMG_CLK_DMA_RQT);
-	iwl_udelay(20);
-	prph_set(APMG_PCIDEV_STT_REG, APMG_PCIDEV_L1_ACT_DIS);
-	iwl_wr_prph(APMG_RTC_INT_STT_REG, APMG_RTC_INT_RFKILL);
+	if (S->fam->apmg) {
+		iwl_wr_prph(APMG_CLK_EN_REG, APMG_CLK_DMA_RQT);
+		iwl_udelay(20);
+		prph_set(APMG_PCIDEV_STT_REG, APMG_PCIDEV_L1_ACT_DIS);
+		iwl_wr_prph(APMG_RTC_INT_STT_REG, APMG_RTC_INT_RFKILL);
+	}
 	return 0;
 }
 
@@ -770,11 +791,14 @@ void iwl_stop_device(void)
 		for (c = 0; c < 8; c++)
 			iwl_wr(FH_TCSR_CONFIG(c), 0);
 		rx_stop();
-		iwl_wr_prph(APMG_CLK_EN_REG, APMG_CLK_DMA_RQT);
-		/* Inform ME that we are leaving (7000 family). */
-		if (S->fam->wake_me) {
-			prph_set(APMG_PCIDEV_STT_REG, APMG_PCIDEV_WAKE_ME);
-			iwl_udelay(5000);
+		if (S->fam->apmg) {
+			iwl_wr_prph(APMG_CLK_EN_REG, APMG_CLK_DMA_RQT);
+			/* Inform ME that we are leaving (7000 family). */
+			if (S->fam->wake_me) {
+				prph_set(APMG_PCIDEV_STT_REG,
+					 APMG_PCIDEV_WAKE_ME);
+				iwl_udelay(5000);
+			}
 		}
 	}
 	stop_master();
@@ -934,12 +958,81 @@ static int load_section(unsigned int dst, const unsigned char *p,
 	return 0;
 }
 
+/* 8000-family firmware: the TLV section list is split into CPU1 and CPU2
+ * lists by SEPARATOR_SECTION entries, each loaded section must be
+ * acknowledged in FH_UCODE_LOAD_STATUS, and the CPU reset is released
+ * through RELEASE_CPU_RESET (Linux iwl_pcie_load_given_ucode_8000()). */
+#define SEC_MAX 24
+
+struct fw_sec {
+	unsigned int off, len;
+	const unsigned char *data;
+};
+
+static int load_sections_8000(int img)
+{
+	unsigned int want = img == IWL_IMG_INIT ? TLV_SEC_INIT : TLV_SEC_RT;
+	const unsigned char *d = S->fw_data;
+	unsigned int off = 88, n = 0, i, val, sec_num;
+	struct fw_sec sec[SEC_MAX];
+
+	while (off + 8 <= S->fw_size && n < SEC_MAX) {
+		unsigned int t = le32(d + off), l = le32(d + off + 4);
+		const unsigned char *p = d + off + 8;
+
+		if (t == want && l > 4) {
+			sec[n].off = le32(p);
+			sec[n].len = l - 4;
+			sec[n].data = p + 4;
+			n++;
+		}
+		off += 8 + ((l + 3) & ~3u);
+	}
+	if (!n)
+		return -1;
+
+	iwl_wr_prph(WFPM_GP2, 0x01010101);
+	prph_set(RELEASE_CPU_RESET, RELEASE_CPU_RESET_BIT);
+
+	sec_num = 1;
+	for (i = 0; i < n; i++) {
+		if (sec[i].off == SEC_CPU1_CPU2 || sec[i].off == SEC_PAGING)
+			break;
+		if (load_section(sec[i].off, sec[i].data, sec[i].len) < 0)
+			return -1;
+		val = iwl_rd(FH_UCODE_LOAD_STATUS);
+		iwl_wr(FH_UCODE_LOAD_STATUS, val | sec_num);
+		sec_num = (sec_num << 1) | 1;
+	}
+	iwl_wr(FH_UCODE_LOAD_STATUS, 0xffffu);
+
+	if (i < n && sec[i].off == SEC_CPU1_CPU2) {
+		sec_num = 1;
+		for (i = i + 1; i < n; i++) {
+			if (sec[i].off == SEC_PAGING ||
+			    sec[i].off == SEC_CPU1_CPU2)
+				break;
+			if (load_section(sec[i].off, sec[i].data, sec[i].len) < 0)
+				return -1;
+			val = iwl_rd(FH_UCODE_LOAD_STATUS);
+			iwl_wr(FH_UCODE_LOAD_STATUS,
+			       val | (sec_num << 16));
+			sec_num = (sec_num << 1) | 1;
+		}
+	}
+	iwl_wr(FH_UCODE_LOAD_STATUS, 0xffffffffu);
+	return 0;
+}
+
 static int load_sections(int img)
 {
 	unsigned int want = img == IWL_IMG_INIT ? TLV_SEC_INIT : TLV_SEC_RT;
 	const unsigned char *d = S->fw_data;
 	unsigned int off = 88, nsec = 0;
 
+	if (S->fam->secure8000)
+		return load_sections_8000(img);
+
 	if (!S->fam->tlv) {
 		/* IWLAGN_RTC_INST_LOWER_BOUND / IWLAGN_RTC_DATA_LOWER_BOUND */
 		if (load_section(0x000000, S->img_inst[img],
@@ -988,8 +1081,10 @@ int iwl_load_fw(int img)
 	/* iwl_pcie_nic_init(): APM, power source VMAIN, NIC config, rings. */
 	if (apm_init() < 0)
 		return -1;
-	iwl_wr_prph(APMG_PS_CTRL_REG,
-		    iwl_rd_prph(APMG_PS_CTRL_REG) & ~APMG_PS_PWR_SRC_MSK);
+	if (S->fam->apmg)
+		iwl_wr_prph(APMG_PS_CTRL_REG,
+			    iwl_rd_prph(APMG_PS_CTRL_REG) &
+			    ~APMG_PS_PWR_SRC_MSK);
 	if (alloc_rings() < 0) {
 		iwl_log("out of memory for rings");
 		return -1;
@@ -1010,7 +1105,8 @@ int iwl_load_fw(int img)
 		return -1;
 	}
 	iwl_wr(CSR_INT, 0xffffffffu);
-	iwl_wr(CSR_RESET, 0);           /* release the CPU */
+	if (!S->fam->secure8000)
+		iwl_wr(CSR_RESET, 0);   /* release the CPU */
 	return 0;
 }
 
@@ -1072,7 +1168,8 @@ void iwl_fw_alive(unsigned int scd_base)
 		iwl_wr(FH_TCSR_CONFIG(c),
 		       FH_TCSR_DMA_ENABLE | FH_TCSR_CREDIT_ENABLE);
 	iwl_wr(FH_TX_CHICKEN_BITS, iwl_rd(FH_TX_CHICKEN_BITS) | 0x2u);
-	prph_clr(APMG_PCIDEV_STT_REG, APMG_PCIDEV_L1_ACT_DIS);
+	if (S->fam->apmg)
+		prph_clr(APMG_PCIDEV_STT_REG, APMG_PCIDEV_L1_ACT_DIS);
 }
 
 /* DQA data/mgmt queue (iwl_trans_pcie_txq_enable() with cfg == NULL: the

+ 4 - 2
kernel/iwl_trans.h

@@ -1,5 +1,6 @@
-/* Intel iwlwifi PCIe transport: the 7000 family (7265D/3165, MVM firmware)
- * and the 6000 family (6200/6300, DVM firmware).
+/* Intel iwlwifi PCIe transport: the 7000 family (7265D/3165, MVM firmware),
+ * the 8000 family (8265, MVM firmware with the secure multi-CPU section
+ * loader) and the 6000 family (6200/6300, DVM firmware).
  *
  * Polled, single RX queue, gen1 TFD TX queues.  Every ring and buffer comes
  * from the page allocator (nothing big in BSS: the kernel image must stay
@@ -26,6 +27,7 @@
 #define IWL_SUB_7265   1   /* 7265D / 3165: MVM firmware */
 #define IWL_SUB_6000I  2   /* 6200 (6000i): DVM, antennas B+C */
 #define IWL_SUB_6000   3   /* 6300: DVM, antennas A+B+C */
+#define IWL_SUB_8265   4   /* 8265: 8000 MVM firmware */
 
 /* Firmware images in the .ucode file. */
 #define IWL_IMG_RT    0

+ 37 - 5
kernel/kernel.c

@@ -8,6 +8,7 @@
 #include "cros_ec.h"
 #include "idle.h"
 #include "init.h"
+#include "ideapad.h"
 #include "io.h"
 #include "ioapic.h"
 #include "lapic.h"
@@ -92,6 +93,8 @@ unsigned int timer_tick_ms(void)
 
 void timer_tick_advance(void)
 {
+	if (ticks == 0)
+		bootcon_puts("tick\n");
 	ticks += tick_ms;
 }
 
@@ -185,7 +188,9 @@ static void timer_init(void)
 {
 	int i;
 
-	/* Remap PICs: master at 0x20, slave at 0x28. */
+	/* Remap PICs: master at 0x20, slave at 0x28.  Keep IRQ1 masked until
+	 * the PIT has proved it ticks: the first interrupt after sti must be
+	 * IRQ0, not a pending keyboard/EC byte. */
 	outb(0x20, 0x11);
 	outb(0xA0, 0x11);
 	outb(0x21, 0x20);
@@ -194,8 +199,9 @@ static void timer_init(void)
 	outb(0xA1, 0x02);
 	outb(0x21, 0x01);
 	outb(0xA1, 0x01);
-	outb(0x21, 0xFC);
+	outb(0x21, 0xFE);
 	outb(0xA1, 0xFF);
+	bootcon_puts("timer: pic\n");
 
 	/* Default handler for all 256 vectors: absorbs any unexpected
 	   interrupt (including spurious IRQ 7) with an EOI + iret. */
@@ -227,11 +233,26 @@ static void timer_init(void)
 	idtr.limit = (unsigned short)(sizeof(idt) - 1);
 	idtr.base  = (unsigned int)idt;
 	__asm__ volatile ("lidt %0" : : "m"(idtr));
+	bootcon_puts("timer: idt\n");
+
+	/* Enable the local APIC before the first interrupt.  Firmware that
+	 * leaves the LAPIC enabled (UEFI laptops) delivers the 8259's ExtINT
+	 * through it, so the stubs must EOI the LAPIC; doing it here also
+	 * masks any firmware LAPIC timer that would otherwise fire before
+	 * smp_init().  Machines without a usable LAPIC keep the PIC-only path
+	 * (lapic_eoi() then returns immediately). */
+	if (acpi_lapic_base()) {
+		lapic_set_base(acpi_lapic_base());
+		if (lapic_init_bsp())
+			bootcon_puts("timer: lapic\n");
+	}
 
 	/* Start the PIT at 1 kHz; schedule() drops it to 100 Hz while the BSP
 	 * is idle (see timer_set_hz). */
 	timer_set_hz(1000);
+	bootcon_puts("timer: pit\n");
 
+	bootcon_puts("timer: sti\n");
 	__asm__ volatile ("sti");
 }
 
@@ -330,15 +351,16 @@ static void boot_val(const char *name, unsigned int v)
 	serial_puts(SERIAL_COM1, "\n");
 }
 
-/* Bounded PIT self-test.  If the 8259 does not deliver IRQ0, every later
- * delay/timeout would spin on a frozen tick counter; say so and stop. */
+/* Bounded PIT self-test.  Require three ticks, not one: a single tick can
+ * arrive and then stop (a blocked LAPIC/PIC route), and smp_init()'s
+ * get_ticks_ms() timeouts would then wait forever without any message. */
 static int pit_ticking(void)
 {
 	unsigned int t0 = get_ticks_ms();
 	unsigned int n;
 
 	for (n = 0; n < 5000000u; n++) {
-		if (get_ticks_ms() != t0)
+		if (get_ticks_ms() - t0 >= 3)
 			return 1;
 		__asm__ volatile ("pause");
 	}
@@ -501,6 +523,7 @@ void kernel_main(void)
 	 * probe is skipped when the ThinkPad EC was found. */
 	tpec_init();
 	cros_ec_init();
+	ideapad_init();
 	boot_trace("ec");
 
 	/* process_init must run before timer_init: once the PIT is started (sti
@@ -517,18 +540,24 @@ void kernel_main(void)
 		for (;;)
 			__asm__ volatile ("cli; hlt");
 	}
+	/* The PIT path is proven; let the keyboard IRQ in for the WM. */
+	outb(0x21, 0xFC);
 	boot_val("timer ticks", get_ticks_ms());
 	/* The PIT (and its sti) is live, so the AP bring-up can use it as a
 	 * timeout clock.  APs idle until smp_enable_sched() after boot. */
 	smp_init();
 	boot_trace("smp");
 	boot_val("smp cpus", cpu_count);
+	bootcon_puts("ps2: init\n");
 	mouse_init();
 	boot_trace("ps2");
+	bootcon_puts("vga: init\n");
 	vga_shadow_init();
 	vga_fb_flush();
 	boot_trace("vga");
 
+	bootcon_puts("ramfs: init\n");
+
 	/* The command pack: read-only, mounted at /ramfs (see ramfs.c).  The
 	 * boot path copied it into RAM (the legacy stage's low gap, the UEFI
 	 * loader or kexec); ramfs_init takes its own copy so the boot region
@@ -591,8 +620,10 @@ void kernel_main(void)
 	/* Hand the userland over to PID 1 before touching disks.  Init starts
 	 * the WM and the services; if /ramfs/bin/init is absent there is no WM
 	 * and the boot console stays visible. */
+	bootcon_puts("wm: init\n");
 	wm_server_init();
 	boot_trace("wm init");
+	bootcon_puts("init: start\n");
 	init_server_start();
 	boot_trace("init");
 #else
@@ -611,6 +642,7 @@ void kernel_main(void)
 	vfs_scan_owner_pid = 0;
 	vfs_scan_busy = 1;
 #ifndef NOWM
+	bootcon_puts("terminal: ready\n");
 	wm_server_boot_ready();
 	boot_trace("terminal ready");
 #else

+ 130 - 2
kernel/power.c

@@ -45,12 +45,16 @@
 #define MSR_ATOM_CORE_VIDS     0x66B
 #define MSR_ATOM_CORE_TURBO_RATIOS 0x66C
 #define MSR_ATOM_CORE_TURBO_VIDS   0x66D
+#define MSR_PM_ENABLE              0x770
+#define MSR_IA32_HWP_CAPABILITIES  0x771
+#define MSR_IA32_HWP_REQUEST       0x774
 
 /* P-state ratios are the bus-ratio multipliers (133.33 MHz on Arrandale). */
 #define BCLK_MHZ 133u
 
 #define PLAT_NEHALEM 1
 #define PLAT_AIRMONT 2
+#define PLAT_KABYLAKE 3
 
 /* Airmont MWAIT C6N hint from Linux's intel_idle cht_cstates table. */
 #define MWAIT_C6N 0x58
@@ -105,6 +109,8 @@ static int atom_vid_valid;
 static unsigned int c6n_ok;
 static int c6n_enabled;
 static unsigned int plat_info_lo, plat_info_hi;
+static int hwp;			/* IA32_PM_ENABLE bit 0 */
+static unsigned int hwp_epp = 128;	/* balance_performance */
 
 static void cpuid_leaf(unsigned int leaf, unsigned int *a, unsigned int *b,
 		       unsigned int *c, unsigned int *d)
@@ -148,6 +154,10 @@ static int power_platform(unsigned int model)
 		return PLAT_NEHALEM;
 	case 0x4C:   /* Airmont: Braswell / Cherry Trail */
 		return PLAT_AIRMONT;
+	case 0x5E:   /* Skylake-U */
+	case 0x8E:   /* Kaby Lake-U (Yoga 720) */
+	case 0x9E:   /* Coffee Lake */
+		return PLAT_KABYLAKE;
 	default:
 		return 0;
 	}
@@ -185,6 +195,21 @@ static void power_write_ratio(unsigned int ratio)
 		ratio = min_ratio;
 	if (ratio > max_ratio)
 		ratio = max_ratio;
+	if (platform == PLAT_KABYLAKE) {
+		if (hwp) {
+			unsigned int req = (min_ratio & 0xFFu) |
+					   ((ratio & 0xFFu) << 8) |
+					   ((ratio & 0xFFu) << 16) |
+					   ((hwp_epp & 0xFFu) << 24);
+
+			wrmsr(MSR_IA32_HWP_REQUEST, req, 0);
+			return;
+		}
+		rdmsr(MSR_IA32_PERF_CTL, &lo, &hi);
+		lo = (lo & 0xFFFF0000u) | (ratio << 8);
+		wrmsr(MSR_IA32_PERF_CTL, lo, hi);
+		return;
+	}
 	rdmsr(MSR_IA32_PERF_CTL, &lo, &hi);
 	if (platform == PLAT_AIRMONT) {
 		lo = (lo & 0xFFFF0000u) | ((ratio & 0xFF) << 8) |
@@ -380,6 +405,90 @@ static void power_init_airmont(unsigned int max_leaf)
 	serial_puts(SERIAL_COM1, "\n");
 }
 
+static void power_init_kabylake(unsigned int max_leaf)
+{
+	unsigned int lo, hi, a, b, c, d;
+	unsigned int caps, req, misc_lo, misc_hi;
+	unsigned int highest, guaranteed, lowest;
+
+	bootcon_puts("power: kaby lake init\n");
+	rdmsr(MSR_PLATFORM_INFO, &plat_info_lo, &plat_info_hi);
+	max_ratio = (plat_info_lo >> 8) & 0xFFu;
+	min_ratio = (plat_info_hi >> 8) & 0xFFu;
+	if (max_ratio < 5 || max_ratio > 60 || min_ratio < 3 ||
+	    min_ratio > max_ratio) {
+		serial_puts(SERIAL_COM1,
+			    "power: implausible platform info, disabled\n");
+		return;
+	}
+	nominal_mhz = max_ratio * 100u;
+	ratio_shift = 8;
+	turbo_ratio = max_ratio;
+	hwp = 0;
+	hwp_epp = 128;
+
+	/* HWP/Speed Shift: IA32_HWP_CAPABILITIES reports highest (turbo),
+	 * guaranteed (max non-turbo), most efficient and lowest ratios.  The
+	 * governor uses the guaranteed..lowest range and leaves turbo
+	 * unrequested, like the other platforms. */
+	rdmsr(MSR_PM_ENABLE, &lo, &hi);
+	if (lo & 1u) {
+		hwp = 1;
+		rdmsr(MSR_IA32_HWP_CAPABILITIES, &caps, &hi);
+		highest = caps & 0xFFu;
+		guaranteed = (caps >> 8) & 0xFFu;
+		lowest = (caps >> 24) & 0xFFu;
+		if (highest >= max_ratio && highest <= 60)
+			turbo_ratio = highest;
+		if (guaranteed >= 5 && guaranteed <= 60)
+			max_ratio = guaranteed;
+		if (lowest >= 3 && lowest <= max_ratio)
+			min_ratio = lowest;
+		rdmsr(MSR_IA32_HWP_REQUEST, &req, &hi);
+		hwp_epp = (req >> 24) & 0xFFu;
+	}
+
+	rdmsr(MSR_MISC_ENABLE, &misc_lo, &misc_hi);
+	eist_on = (misc_lo >> 16) & 1;
+	turbo_disabled = (misc_hi >> 6) & 1;
+	if (max_leaf >= 6) {
+		cpuid_leaf(6, &a, &b, &c, &d);
+		has_arat = (a & 4u) ? 1 : 0;
+	}
+	supported = 1;
+	pstate_writes = 1;
+	has_aperf = 1;
+	pcs[0].req = max_ratio;
+	power_write_ratio(max_ratio);
+	pcs[0].aperf = rdmsr64(MSR_APERF);
+	pcs[0].mperf = rdmsr64(MSR_MPERF);
+	pcs[0].have_last = 1;
+	rdmsr(MSR_IA32_PERF_STATUS, &lo, &hi);
+	bootcon_puts("power: kaby lake ready\n");
+
+	serial_puts(SERIAL_COM1, "power: Kaby Lake, pstates ");
+	serial_putdec(SERIAL_COM1, min_ratio);
+	serial_puts(SERIAL_COM1, "..");
+	serial_putdec(SERIAL_COM1, max_ratio);
+	serial_puts(SERIAL_COM1, " (");
+	serial_putdec(SERIAL_COM1, nominal_mhz);
+	serial_puts(SERIAL_COM1, " MHz), turbo p");
+	serial_putdec(SERIAL_COM1, turbo_ratio);
+	serial_puts(SERIAL_COM1, ", hwp ");
+	serial_puts(SERIAL_COM1, hwp ? "on" : "off");
+	serial_puts(SERIAL_COM1, ", epp ");
+	serial_putdec(SERIAL_COM1, hwp_epp);
+	serial_puts(SERIAL_COM1, ", eist ");
+	serial_puts(SERIAL_COM1, eist_on ? "on" : "off");
+	serial_puts(SERIAL_COM1, ", turbo ");
+	serial_puts(SERIAL_COM1, turbo_disabled ? "disabled" : "enabled");
+	serial_puts(SERIAL_COM1, ", arat ");
+	serial_puts(SERIAL_COM1, has_arat ? "yes" : "no");
+	serial_puts(SERIAL_COM1, ", perf status ");
+	serial_puthex(SERIAL_COM1, lo);
+	serial_puts(SERIAL_COM1, "\n");
+}
+
 void power_init(void)
 {
 	unsigned int max_leaf, a, b, c, d;
@@ -447,6 +556,10 @@ void power_init(void)
 		power_init_airmont(max_leaf);
 		return;
 	}
+	if (platform == PLAT_KABYLAKE) {
+		power_init_kabylake(max_leaf);
+		return;
+	}
 
 	rdmsr(MSR_PLATFORM_INFO, &lo, &hi);
 	max_ratio = (lo >> 8) & 0xFF;
@@ -701,7 +814,9 @@ void power_tick(int idle, unsigned int ms)
 		 * unlike PERF_CTL, which takes the target in bits 15:8. */
 		rdmsr(MSR_IA32_PERF_STATUS, &da, &dm);
 		p->status = da & 0xFFFFu;
-		p->ratio = p->status & 0xFFu;
+		p->ratio = (platform == PLAT_KABYLAKE) ?
+			   (p->status >> 8) & 0xFFu :
+			   p->status & 0xFFu;
 
 		if (c->id == 0) {
 			unsigned long long pc3 = rdmsr64(MSR_PKG_C3_RESIDENCY);
@@ -796,7 +911,8 @@ void power_print(void)
 	}
 	io_putstr("power: ");
 	io_putstr(platform == PLAT_AIRMONT ? "airmont/braswell" :
-					    "nehalem/westmere");
+		  platform == PLAT_KABYLAKE ? "kaby lake/hwp" :
+					      "nehalem/westmere");
 	if (!pstate_writes)
 		io_putstr(" (probe only)");
 	io_putstr(", idle ");
@@ -875,6 +991,18 @@ void power_print(void)
 		return;
 	}
 
+	if (platform == PLAT_KABYLAKE) {
+		io_putstr("hwp ");
+		io_putstr(hwp ? "on" : "off");
+		io_putstr(", epp ");
+		put_dec(hwp_epp);
+		io_putstr(", turbo p");
+		put_dec(turbo_ratio);
+		io_putstr(", eist ");
+		io_putstr(eist_on ? "on" : "off");
+		io_putstr(", arat ");
+		io_putstr(has_arat ? "yes\n" : "no\n");
+	}
 	io_putstr("cst ");
 	put_dec(cst_limit);
 	io_putstr(cst_locked ? " locked" : " unlocked");

+ 5 - 0
kernel/power_src.c

@@ -1,6 +1,7 @@
 /* AC/battery backend selection; see power_src.h. */
 #include "power_src.h"
 #include "cros_ec.h"
+#include "ideapad.h"
 #include "tpec.h"
 
 void power_source_read(struct power_info *out, int detail)
@@ -9,5 +10,9 @@ void power_source_read(struct power_info *out, int detail)
 		tpec_power_read(out, detail);
 		return;
 	}
+	if (ideapad_present()) {
+		ideapad_power_read(out, detail);
+		return;
+	}
 	cros_ec_power_read(out, detail);
 }

+ 6 - 5
kernel/power_src.h

@@ -1,9 +1,9 @@
 /* Shared AC/battery snapshot for the board embedded controllers.
  *
- * Two backends fill this: the ThinkPad H8 EC (tpec.c) and the Chrome OS EC
- * (cros_ec.c).  sys_info.c copies it into struct sys_powerinfo for
- * SYS_POWER_INFO, so the WM top bar and the powerinfo command do not need to
- * know which laptop they are running on.
+ * Three backends fill this: the ThinkPad H8 EC (tpec.c), the IdeaPad/Yoga
+ * ACPI EC (ideapad.c) and the Chrome OS EC (cros_ec.c).  sys_info.c copies
+ * it into struct sys_powerinfo for SYS_POWER_INFO, so the WM top bar and the
+ * powerinfo command do not need to know which laptop they are running on.
  */
 #ifndef POWER_SRC_H
 #define POWER_SRC_H
@@ -48,7 +48,8 @@ struct power_info {
 	struct power_battery battery[POWER_BATT_MAX];
 };
 
-/* Fill out from the first available backend (ThinkPad EC, then Chrome EC).
+/* Fill out from the first available backend (ThinkPad EC, IdeaPad EC, then
+ * Chrome EC).
  * detail also reads design data and the manufacturer/model/serial strings;
  * the periodic WM query passes 0. */
 void power_source_read(struct power_info *out, int detail);

+ 35 - 4
kernel/serial.c

@@ -8,10 +8,28 @@
 
 static int serial_dead;   /* COM1 stopped answering (no UART present) */
 
+/* An absent 16550 sits on a floating bus that returns 0xFF from every
+ * register.  A real one cannot: LSR bit 7 is reserved-zero and a 16550's IIR
+ * is 0x01/0xC1, never 0xFF.  Detect it before programming the port and before
+ * the PIT starts polling it. */
+static int serial_absent(unsigned int port)
+{
+	return port_inb(port + 5) == 0xFF && port_inb(port + 2) == 0xFF;
+}
+
 void serial_init(unsigned int port)
 {
-	if (port == SERIAL_COM1)
+	if (port == SERIAL_COM1) {
 		serial_dead = 0;
+		if (serial_absent(port)) {
+			/* Keep the boot console and netlog mirrors working (they
+			 * are fed by serial_putc before the dead check), but
+			 * never touch the floating port again. */
+			serial_dead = 1;
+			bootcon_puts("com1: absent\n");
+			return;
+		}
+	}
 	port_outb(port + 1, 0x00);
 	port_outb(port + 3, 0x80);
 	port_outb(port + 0, 0x01); /* divisor low = 1  -> 115200 baud */
@@ -94,13 +112,26 @@ int serial_has_data(unsigned int port)
 
 void serial_poll(void)
 {
-	unsigned char c;
+	unsigned char c, lsr;
 	unsigned int guard = 0;
 
-	/* Bounded drain: a floating LSR (0xFF) has DR set forever. */
-	while (((port_inb(SERIAL_COM1 + 5) & 0x01) != 0) && guard++ < 256) {
+	if (serial_dead)
+		return;
+
+	/* Read the status before the data.  On a serial-less machine (the
+	 * floating bus returns 0xFF) the old drain loop did 256 LSR + 256 data
+	 * reads on every PIT tick.  Over eSPI those cost more than the 1 ms
+	 * tick itself and starved the boot after [process]; mark the port dead
+	 * instead.  A real UART is only polled while DR is set. */
+	lsr = (unsigned char)port_inb(SERIAL_COM1 + 5);
+	if (lsr == 0xFF) {
+		serial_dead = 1;
+		return;
+	}
+	while ((lsr & 0x01) != 0 && guard++ < 256) {
 		c = (unsigned char)port_inb(SERIAL_COM1);
 		serial_ring_push(c);
+		lsr = (unsigned char)port_inb(SERIAL_COM1 + 5);
 	}
 }
 

+ 5 - 0
kernel/smp.c

@@ -7,6 +7,7 @@
 
 #include "smp.h"
 #include "acpi.h"
+#include "bootcon.h"
 #include "cpu.h"
 #include "idle.h"
 #include "lapic.h"
@@ -122,6 +123,9 @@ void smp_init(void)
 			serial_puts(SERIAL_COM1, "smp: no stack for AP\n");
 			break;
 		}
+		bootcon_puts("smp: ap ");
+		bootcon_dec(i);
+		bootcon_puts("\n");
 		start_one_ap(i, top);
 		if (!ap_started[i]) {
 			serial_puts(SERIAL_COM1, "smp: AP ");
@@ -131,6 +135,7 @@ void smp_init(void)
 		}
 		online_aps++;
 		cpu_count = online_aps + 1;
+		bootcon_puts("smp: ap ok\n");
 		/* CR0 as the AP woke up (its CD/NW are cleared by the
 		 * trampoline): 0x60000011 means it would have run uncached. */
 		serial_puts(SERIAL_COM1, "smp: AP ");

+ 2 - 0
kernel/switch.S

@@ -48,6 +48,8 @@ pit_irq_stub:
 	call  timer_tick_advance
 	movb  $0x20, %al
 	outb  %al, $0x20
+	/* ExtINT delivered through the LAPIC needs a LAPIC EOI as well. */
+	call  lapic_eoi
 
 	/* Poll UART for received serial data (prevents FIFO overflow). */
 	call  serial_poll

+ 2 - 0
kernel/thermal.c

@@ -87,6 +87,7 @@ static int model_has_dts(unsigned int model)
 	case 0x2E:   /* Nehalem-EX */
 	case 0x2F:   /* Westmere-EX */
 	case 0x4C:   /* Airmont: Braswell / Cherry Trail */
+	case 0x8E:   /* Kaby Lake-U (Yoga 720) */
 		return 1;
 	default:
 		return 0;
@@ -108,6 +109,7 @@ static int model_has_msr_tjmax(unsigned int model)
 	case 0x2C:
 	case 0x2E:
 	case 0x2F:
+	case 0x8E:
 		return 1;
 	default:
 		return 0;

+ 16 - 3
kernel/timer.S

@@ -5,6 +5,8 @@
 
 .include "irqret.inc"
 
+.extern lapic_eoi
+
 .globl kbd_irq_stub
 kbd_irq_stub:
 	pusha
@@ -17,6 +19,7 @@ kbd_irq_stub:
 	movw  $0x28, %ax
 	movw  %ax, %gs
 	call  kbd_irq
+	call  lapic_eoi
 	IRQ_RETURN_DS 36
 	popa
 	iret
@@ -31,6 +34,7 @@ mouse_irq_stub:
 	movw  $0x28, %ax
 	movw  %ax, %gs
 	call  mouse_irq
+	call  lapic_eoi
 	IRQ_RETURN_DS 36
 	popa
 	iret
@@ -45,18 +49,27 @@ fdc_irq_stub:
 	movw  $0x28, %ax
 	movw  %ax, %gs
 	call  fdc_irq
+	call  lapic_eoi
 	IRQ_RETURN_DS 36
 	popa
 	iret
 
-/* Default IRQ handler: send EOI and return.  Catches spurious and
+/* Default IRQ handler: send both EOIs and return.  Catches spurious and
    unexpected hardware interrupts that would otherwise triple-fault. */
 .globl default_irq_stub
 default_irq_stub:
-	pushl %eax
+	pusha
+	movw  $0x10, %ax
+	movw  %ax, %ds
+	movw  %ax, %es
+	movw  %ax, %fs
+	movw  $0x28, %ax
+	movw  %ax, %gs
+	call  lapic_eoi
 	movb  $0x20, %al
 	outb  %al, $0x20
-	popl  %eax
+	IRQ_RETURN_DS 36
+	popa
 	iret
 
 /* CPU exception stubs (vectors 0-31).  The handler never returns; it gets a

+ 376 - 81
kernel/touchpad.c

@@ -1,22 +1,26 @@
-/* Elan HID-over-I2C touchpad on the Braswell LPSS I2C bus.
+/* Touchpads on the LPSS I2C buses.
  *
- * The HP Chromebook 11 G5 EE (setzer) wires its touchpad to LPSS I2C6 at
- * 0xD1327000, slave address 0x15.  The LPSS I2C functions are hidden from
- * PCI in ACPI mode, so the driver scans the two firmware BAR windows for
- * DesignWare component types instead of enumerating PCI.
+ * Two HID-over-I2C families are supported:
+ *  - Elan on the HP Chromebook 11 G5 EE (Braswell LPSS I2C6 at 0xD1327000,
+ *    slave 0x15, vendor report 0x5D);
+ *  - Synaptics 06CB:7F8F on the Lenovo Yoga 720-13IKB (Sunrise Point-LP
+ *    LPSS I2C0 at PCI 00:15.0, slave 0x2C, Windows-Precision report 3:
+ *    five 5-byte finger records, scan time, contact count and clickpad).
+ *
+ * The LPSS I2C functions are hidden from PCI in ACPI mode on Braswell, so
+ * that path scans the two firmware BAR windows for DesignWare component
+ * types; the Skylake/Kaby Lake path finds the PCI 00:15.0 function and uses
+ * its BAR.
  *
  * The report line is a GPIO we have no driver for, so the input register is
  * polled.  A read with no pending report returns a zero length immediately.
  * Reading the register back-to-back stalls the device: 25 ms (40 Hz) is the
  * rate it keeps up with, and the pointer still moves smoothly.
  *
- * Init follows Linux's elan_i2c: reset, consume the 2-byte reset
- * acknowledgement, read the HID descriptor and the max-X/Y commands, select
- * absolute mode (0x0300) and wake the device (0x0800).
- *
- * Report decoding is Elan-specific; the contact behaviour (pointer deltas,
+ * Init follows the HID-over-I2C descriptor and the vendor wake sequence.
+ * Report decoding is per-family; the contact behaviour (pointer deltas,
  * taps, the physical-button latch and two-finger scrolling) lives in
- * touchpad_gesture.c so another touchpad driver can reuse it.
+ * touchpad_gesture.c so the backends share it.
  */
 
 #include "cpu.h"
@@ -25,9 +29,11 @@
 #include "i2c.h"
 #include "io.h"
 #include "paging.h"
+#include "pci.h"
 #include "timer.h"
 
 #define TP_ADDR			0x15
+#define TP_SYN_ADDR		0x2c
 #define TP_CTRL_MAX		16
 #define TP_CTRL_STEP		0x1000u
 
@@ -42,6 +48,10 @@
 
 #define TP_DW_COMP_TYPE		0x44570140u
 #define TP_REPORT_ID		0x5d
+#define TP_SYN_REPORT_ID	3
+#define TP_SYN_REPORT_LEN	30
+#define TP_SYN_MAX_X		1219
+#define TP_SYN_MAX_Y		799
 
 #define TP_MAX_X_REG		0x0106
 #define TP_MAX_Y_REG		0x0107
@@ -50,9 +60,17 @@
 #define TP_MAX_INPUT		64
 #define TP_POLL_MS		25
 
+enum {
+	TP_KIND_NONE,
+	TP_KIND_ELAN,
+	TP_KIND_SYNAPTICS,
+};
+
 static unsigned int tp_base;
 static unsigned int tp_addr = TP_ADDR;
+static int tp_kind;
 static int tp_present;
+static int tp_invert_y;
 static unsigned int tp_in_reg = 0x0003;
 static unsigned int tp_max_in = 34;
 static unsigned int tp_cmd_reg = TP_CMD_REG;
@@ -63,6 +81,10 @@ static int tp_max_y = TP_ABS_MAX;
 static const char *tp_err;
 static unsigned int tp_err_val;
 
+/* Probe diagnostics for `touchpad` when the controller/device is absent. */
+static unsigned int tp_dbg_id, tp_dbg_bar, tp_dbg_cmd, tp_dbg_comp;
+static unsigned int tp_dbg_priv0, tp_dbg_priv4;
+
 static struct tpg_state tp_gesture;
 static int tp_last_buttons;
 static unsigned int tp_next_poll;
@@ -85,7 +107,8 @@ static void put_hex16(unsigned int v)
 
 static void print_summary(void)
 {
-	io_putstr("touchpad: elan ");
+	io_putstr("touchpad: ");
+	io_putstr(tp_kind == TP_KIND_SYNAPTICS ? "synaptics " : "elan ");
 	put_hex16(tp_vendor);
 	io_putchar(':');
 	put_hex16(tp_product);
@@ -116,6 +139,8 @@ static void print_status(void)
 		io_putstr((opts & TPG_SCROLL_INVERT) ?
 			  "traditional" : "natural");
 	}
+	io_putstr(" invert ");
+	io_putstr(tp_invert_y ? "on" : "off");
 	io_putstr(" corner x>=");
 	put_dec((unsigned int)(tp_max_x * TPG_CORNER_X_PCT / 100));
 	io_putstr(" y<=");
@@ -323,48 +348,215 @@ static int probe_controller(unsigned int base)
 	query_limits();
 	tpg_init(&tp_gesture, tp_max_x, tp_max_y, 2);
 
+	tp_present = 1;
+	tp_kind = TP_KIND_ELAN;
+	tp_addr = TP_ADDR;
+	tp_invert_y = 0;
+	tp_err = 0;
+	print_summary();
+	return 1;
+}
+
+/* Synaptics 06CB:7F8F Windows-Precision touchpad (Yoga 720-13IKB) on the
+ * Sunrise Point-LP LPSS I2C0.  The HID descriptor is the standard 30-byte
+ * HID-over-I2C block; report 3 is five 5-byte finger records (tip/confidence,
+ * contact id, 16-bit X, 16-bit Y), then scan time, contact count and the
+ * clickpad button. */
+static int probe_synaptics(unsigned int base)
+{
+	unsigned char desc[TP_HID_DESC_LEN + 2];
+	unsigned char ack[2];
+	unsigned int off, len, ver, i;
+	int tried_power = 0;
+
+	if (i2c_dw_init(base) != 0) {
+		tp_err = "i2c init failed";
+		return 0;
+	}
+	tp_base = base;
+	tp_addr = TP_SYN_ADDR;
+	tp_dbg_priv0 = *(volatile unsigned int *)(base + 0x200);
+	tp_dbg_priv4 = *(volatile unsigned int *)(base + 0x204);
+
+	/* Linux's i2c-hid first checks the address and reads the HID
+	 * descriptor; only the report-descriptor stage powers the device on
+	 * and resets it.  Do the same, with a power-on/retry fallback for a
+	 * device left asleep by a previous OS. */
+	if (i2c_dw_transfer(base, tp_addr, 0, 0, ack, 1) != 0) {
+		tp_err = "no device at 0x2c";
+		tp_err_val = i2c_last_abort;
+		return 0;
+	}
+	for (i = 0; i < 4; i++) {
+		if (hid_read_reg(tp_addr, TP_HID_DESC_REG, desc,
+				 sizeof(desc)) == 0)
+			break;
+		if (!tried_power) {
+			tried_power = 1;
+			hid_write_reg(tp_addr, TP_CMD_REG, TP_CMD_WAKE);
+			msleep(60);
+		} else {
+			hid_write_reg(tp_addr, TP_CMD_REG, TP_CMD_RESET);
+			msleep(200);
+		}
+	}
+	if (i == 4) {
+		tp_err = "descriptor read failed";
+		tp_err_val = i2c_last_abort;
+		return 0;
+	}
+
+	off = 0;
+	len = get16(desc + 0);
+	ver = get16(desc + 2);
+	if (len != TP_HID_DESC_LEN || ver != 0x0100) {
+		if (get16(desc + 2) == TP_HID_DESC_LEN &&
+		    get16(desc + 4) == 0x0100)
+			off = 2;
+		len = get16(desc + off);
+		ver = get16(desc + off + 2);
+	}
+	if (len != TP_HID_DESC_LEN || ver != 0x0100) {
+		tp_err = "bad hid descriptor";
+		return 0;
+	}
+
+	tp_in_reg = get16(desc + off + 8);
+	tp_max_in = get16(desc + off + 10);
+	tp_cmd_reg = get16(desc + off + 16);
+	tp_vendor = (unsigned short)get16(desc + off + 20);
+	tp_product = (unsigned short)get16(desc + off + 22);
+	if (tp_vendor != 0x06CB || tp_product != 0x7F8F) {
+		tp_err = "not a Synaptics 06CB:7F8F";
+		return 0;
+	}
+	if (tp_max_in < TP_SYN_REPORT_LEN + 2 || tp_max_in > TP_MAX_INPUT)
+		tp_max_in = TP_SYN_REPORT_LEN + 2;
+
+	/* i2c_hid_hwreset(): power on (60 ms), reset, then wait for the
+	 * zero-length reset-complete input report before using the device. */
+	hid_write_reg(tp_addr, tp_cmd_reg, TP_CMD_WAKE);
+	msleep(60);
+	hid_write_reg(tp_addr, tp_cmd_reg, TP_CMD_RESET);
+	for (i = 0; i < 40; i++) {
+		unsigned char z[TP_MAX_INPUT];
+
+		if (i2c_dw_transfer(base, tp_addr, 0, 0, z, tp_max_in) == 0 &&
+		    z[0] == 0 && z[1] == 0)
+			break;
+		msleep(25);
+	}
+	hid_write_reg(tp_addr, tp_cmd_reg, TP_CMD_WAKE);
+	msleep(60);
+
+	tp_kind = TP_KIND_SYNAPTICS;
+	/* The Windows-Precision report uses the logical frame from its
+	 * descriptor.  Default to Y-down (the usual HID digitizer frame);
+	 * `touchpad invert off` fixes a unit that reports Y-up. */
+	tp_invert_y = 1;
+	tp_max_x = TP_SYN_MAX_X;
+	tp_max_y = TP_SYN_MAX_Y;
+	tpg_init(&tp_gesture, tp_max_x, tp_max_y, 2);
+
 	tp_present = 1;
 	tp_err = 0;
 	print_summary();
 	return 1;
 }
 
+/* Sunrise Point-LP leaves the LPSS functions with memory decode off: Linux
+ * logs "intel-lpss 0000:00:15.0: enabling device (0000 -> 0002)" before it
+ * can even read the DesignWare component type.  A warm reboot from another
+ * OS can additionally leave the function in D3hot, so put it back in D0.
+ * Both steps are no-ops when firmware already did them. */
+static void lpss_pci_prepare(unsigned int dev, unsigned int func)
+{
+	unsigned int cmd, cap, pm;
+
+	cmd = pci_cfg_read32(0, dev, func, 0x04) & 0xFFFFu;
+	pci_cfg_write16(0, dev, func, 0x04,
+			(unsigned short)(cmd | 0x0006u));
+
+	cap = pci_cfg_read32(0, dev, func, 0x34) & 0xFFu;
+	if (cap >= 0x40 && (cap & 3) == 0) {
+		pm = (pci_cfg_read32(0, dev, func, cap) >> 16) & 0xFFFFu;
+		pci_cfg_write16(0, dev, func, cap + 4,
+				(unsigned short)(pm & ~3u));
+	}
+	msleep(10);
+}
+
 int touchpad_init(void)
 {
-	/* The ACPI _CRS address for the LPSS I2C blocks is 0x9132xxxx on
-	 * coreboot, but this firmware maps them at 0xD132xxxx.  Both
-	 * windows are scanned; page 7 (I2C6) is tried first. */
+	/* The ACPI _CRS address for the Braswell LPSS I2C blocks is
+	 * 0x9132xxxx on coreboot, but this firmware maps them at 0xD132xxxx.
+	 * Both windows are scanned; page 7 (I2C6) is tried first. */
 	static const unsigned int ranges[2] = { 0x91320000u, 0xd1320000u };
 	unsigned int r, k;
 
 	if (tp_present)
 		return 1;
-	/* The Elan touchpad sits behind the Braswell LPSS I2C blocks (the HP
-	 * Chromebook, Airmont family 6 model 0x4C).  Everywhere else the scan
-	 * below would only map and reset-cycle 32 fixed MMIO windows that
-	 * belong to nobody (2 ms each, ~64 ms of boot) or, worse, to some
-	 * other device, so skip it. */
-	if (cpu_family_model() != 0x64Cu) {
-		tp_err = "not an Airmont (Braswell) platform";
-		return 0;
+	tp_err = 0;
+	tp_err_val = 0;
+
+	/* Braswell (HP Chromebook 11 G5 EE): LPSS I2C6 is hidden from PCI. */
+	if (cpu_family_model() == 0x64Cu) {
+		for (r = 0; r < 2; r++) {
+			for (k = 0; k < TP_CTRL_MAX; k++) {
+				unsigned int i = (k + 7) % TP_CTRL_MAX;
+				unsigned int base = (unsigned int)ioremap(
+					ranges[r] + i * TP_CTRL_STEP, 0x1000,
+					IOREMAP_MMIO);
+
+				if (!base)
+					continue;
+				/* A block left in functional reset keeps its
+				 * register file but never clocks the I2C FSM. */
+				i2c_dw_reset_release(base);
+				if (probe_controller(base))
+					return 1;
+			}
+		}
 	}
 
-	for (r = 0; r < 2; r++) {
-		for (k = 0; k < TP_CTRL_MAX; k++) {
-			unsigned int i = (k + 7) % TP_CTRL_MAX;
-			unsigned int base = (unsigned int)ioremap(
-				ranges[r] + i * TP_CTRL_STEP, 0x1000,
-				IOREMAP_MMIO);
-
-			if (!base)
-				continue;
-			/* A block left in functional reset keeps its
-			 * register file but never clocks the I2C FSM. */
-			i2c_dw_reset_release(base);
-			if (probe_controller(base))
-				return 1;
+	/* Sunrise Point-LP LPSS I2C0/1/2 (Skylake/Kaby Lake): the functions
+	 * are visible at PCI 00:15.0/1/2.  The Yoga's Synaptics touchpad is
+	 * on I2C0 at 0x2C; the Wacom touchscreen on I2C1 is rejected by the
+	 * vendor/product check in probe_synaptics(). */
+	for (k = 0; k < 3; k++) {
+		unsigned int id = pci_cfg_read32(0, 0x15, k, 0x00);
+		unsigned int bar, base;
+
+		if (id != 0x9d608086u && id != 0x9d618086u &&
+		    id != 0x9d628086u)
+			continue;
+		lpss_pci_prepare(0x15, k);
+		bar = pci_cfg_read32(0, 0x15, k, 0x10) & ~0xFu;
+		if (!bar)
+			continue;
+		base = (unsigned int)ioremap(bar, 0x1000, IOREMAP_MMIO);
+		if (!base)
+			continue;
+		/* Release the LPSS function reset before reading the
+		 * DesignWare component type: the register file may answer
+		 * while the block is still in functional reset, and the
+		 * I2C FSM never clocks until 0x204 is released. */
+		i2c_dw_reset_release(base);
+		tp_dbg_id = id;
+		tp_dbg_bar = bar;
+		tp_dbg_cmd = pci_cfg_read32(0, 0x15, k, 0x04) & 0xFFFFu;
+		tp_dbg_comp = i2c_dw_comp_type(base);
+		if (!i2c_dw_present(base)) {
+			tp_err = "LPSS not a DesignWare I2C";
+			tp_err_val = tp_dbg_comp;
+			continue;
 		}
+		if (probe_synaptics(base))
+			return 1;
 	}
+
+	if (!tp_err)
+		tp_err = "no LPSS I2C touchpad";
 	return 0;
 }
 
@@ -388,10 +580,89 @@ unsigned short touchpad_product(void)
 	return tp_product;
 }
 
+static int elan_decode(const unsigned char *buf, struct tpg_frame *f,
+		       unsigned int now)
+{
+	unsigned int b, ti, off, i, n = 0;
+
+	for (b = 0; b < 6 && b + 6 < tp_max_in; b++)
+		if (buf[b] == TP_REPORT_ID)
+			break;
+	if (b >= 6 || b + 6 >= tp_max_in)
+		return 0;
+
+	ti = buf[b + 1];
+	off = b + 2;
+	f->count = 0;
+	f->mask = 0;
+	f->button = ti & 0x01;
+	f->now_ms = now;
+	for (i = 0; i < 5; i++) {
+		if (!(ti & (0x08u << i)))
+			continue;
+		f->count++;
+		if (n < TPG_CONTACTS && off + 4 < tp_max_in) {
+			unsigned int xh = buf[off];
+
+			f->contact[n].x = ((int)(xh & 0xf0) << 4) |
+					   buf[off + 1];
+			f->contact[n].y = ((int)(xh & 0x0f) << 8) |
+					   buf[off + 2];
+			if (tp_invert_y)
+				f->contact[n].y = tp_max_y - 1 -
+						  f->contact[n].y;
+			f->mask |= 1u << n;
+			n++;
+		}
+		off += 5;
+	}
+	return 1;
+}
+
+/* Windows-Precision report 3: five 5-byte finger records, then 2-byte scan
+ * time, contact count and the clickpad button bit. */
+static int synaptics_decode(const unsigned char *buf, struct tpg_frame *f,
+			    unsigned int now)
+{
+	unsigned int b, p, i, n = 0;
+
+	for (b = 0; b < 6 && b + TP_SYN_REPORT_LEN <= tp_max_in; b++)
+		if (buf[b] == TP_SYN_REPORT_ID)
+			break;
+	if (b >= 6 || b + TP_SYN_REPORT_LEN > tp_max_in)
+		return 0;
+
+	p = b + 1;
+	f->count = buf[b + 28];
+	f->mask = 0;
+	f->button = buf[b + 29] & 1;
+	f->now_ms = now;
+	for (i = 0; i < 5; i++, p += 5) {
+		unsigned int f0 = buf[p];
+		int x, y;
+
+		if (!(f0 & 0x01))
+			continue;
+		x = (int)get16(buf + p + 1);
+		y = (int)get16(buf + p + 3);
+		if (tp_invert_y)
+			y = tp_max_y - 1 - y;
+		if (n < TPG_CONTACTS) {
+			f->contact[n].x = x;
+			f->contact[n].y = y;
+			f->mask |= 1u << n;
+			n++;
+		}
+	}
+	if (f->count > 5)
+		f->count = 5;
+	return 1;
+}
+
 int touchpad_poll(int *buttons, int *dx, int *dy, int *scroll)
 {
 	unsigned char buf[TP_MAX_INPUT];
-	unsigned int now, b;
+	unsigned int now;
 	struct tpg_result res;
 
 	*buttons = 0;
@@ -419,44 +690,17 @@ int touchpad_poll(int *buttons, int *dx, int *dy, int *scroll)
 	if (hid_read_reg(tp_addr, tp_in_reg, buf, tp_max_in) != 0)
 		return 0;
 
-	/* The addressed read returns two status bytes, the 2-byte length
-	 * and then the report, so locate the 0x5D report ID instead of
-	 * trusting a fixed offset.  Layout after it (Linux hid-elan.c):
-	 * touch info (f5..f1 at bits 7..3, clickpad at bit 0), then 5
-	 * bytes per *active* finger (packed): x11:8/y11:9, x7:0, y7:0,
-	 * size, pressure. */
-	for (b = 0; b < 6 && b + 6 < tp_max_in; b++)
-		if (buf[b] == TP_REPORT_ID)
-			break;
-	if (b >= 6 || b + 6 >= tp_max_in)
-		return 0;
-
 	{
 		struct tpg_frame f;
-		unsigned int ti = buf[b + 1];
-		unsigned int off = b + 2;
-		unsigned int i, n = 0;
-
-		f.count = 0;
-		f.mask = 0;
-		f.button = ti & 0x01;
-		f.now_ms = now;
-		for (i = 0; i < 5; i++) {
-			if (!(ti & (0x08u << i)))
-				continue;
-			f.count++;
-			if (n < TPG_CONTACTS && off + 4 < tp_max_in) {
-				unsigned int xh = buf[off];
-
-				f.contact[n].x = ((int)(xh & 0xf0) << 4) |
-						 buf[off + 1];
-				f.contact[n].y = ((int)(xh & 0x0f) << 8) |
-						 buf[off + 2];
-				f.mask |= 1u << n;
-				n++;
-			}
-			off += 5;
+
+		if (tp_kind == TP_KIND_SYNAPTICS) {
+			if (!synaptics_decode(buf, &f, now))
+				return 0;
+		} else {
+			if (!elan_decode(buf, &f, now))
+				return 0;
 		}
+
 		tp_stat_fingers = (int)f.count;
 		tp_stat_f1 = (f.mask & 1u) != 0;
 		if (f.mask & 1u) {
@@ -477,16 +721,46 @@ int touchpad_poll(int *buttons, int *dx, int *dy, int *scroll)
 	return res.dx || res.dy || res.scroll;
 }
 
+static void print_absent(void)
+{
+	io_putstr("touchpad: absent (");
+	io_putstr(tp_err ? tp_err : "unknown");
+	if (tp_err_val) {
+		io_putstr(" val=");
+		io_puthex(tp_err_val);
+	}
+	io_putstr(")\n");
+	if (tp_dbg_id) {
+		io_putstr("touchpad: lpss id ");
+		io_puthex(tp_dbg_id);
+		io_putstr(" bar 0x");
+		io_puthex(tp_dbg_bar);
+		io_putstr(" cmd ");
+		io_puthex(tp_dbg_cmd);
+		io_putstr(" comp ");
+		io_puthex(tp_dbg_comp);
+		io_putstr(" priv ");
+		io_puthex(tp_dbg_priv0);
+		io_putchar('/');
+		io_puthex(tp_dbg_priv4);
+		io_putchar('\n');
+	}
+}
+
 void program_touchpad_main(const char *arg)
 {
+	arg = arg ? skip_spaces(arg) : 0;
+	if (arg && word_is(arg, "probe")) {
+		if (!tp_present)
+			touchpad_init();
+		if (tp_present)
+			print_status();
+		else
+			print_absent();
+		return;
+	}
 	if (!tp_present) {
-		io_putstr("touchpad: absent (");
-		io_putstr(tp_err ? tp_err : "unknown");
-		if (tp_err_val) {
-			io_putstr(" ab=");
-			io_puthex(tp_err_val);
-		}
-		io_putstr(")\n");
+		print_absent();
 		return;
 	}
 
@@ -586,8 +860,29 @@ void program_touchpad_main(const char *arg)
 			}
 			io_putchar('\n');
 			arg = skip_spaces(v + word_len(v));
+		} else if (word_is(arg, "invert")) {
+			const char *v = skip_spaces(arg + 6);
+
+			if (!*v) {
+				io_putstr("touchpad: invert ");
+				io_putstr(tp_invert_y ? "on" : "off");
+				io_putchar('\n');
+				return;
+			}
+			if (word_is(v, "on"))
+				tp_invert_y = 1;
+			else if (word_is(v, "off"))
+				tp_invert_y = 0;
+			else {
+				io_putstr("touchpad: invert on|off\n");
+				return;
+			}
+			io_putstr("touchpad: invert ");
+			io_putstr(tp_invert_y ? "on" : "off");
+			io_putchar('\n');
+			arg = skip_spaces(v + word_len(v));
 		} else {
-			io_putstr("touchpad: usage: touchpad [rightclick off|tap|corner|both | tapclick on|off | scroll on|off|natural|traditional]\n");
+			io_putstr("touchpad: usage: touchpad [probe | rightclick off|tap|corner|both | tapclick on|off | scroll on|off|natural|traditional | invert on|off]\n");
 			return;
 		}
 	}

+ 5 - 7
kernel/touchpad.h

@@ -1,11 +1,9 @@
-/* Elan HID-over-I2C touchpad (HP Chromebook 11 G5 EE / setzer).
+/* Elan and Synaptics HID-over-I2C touchpads.
  *
- * The controller is a DesignWare I2C block in the Braswell LPSS; the
- * touchpad answers at slave address 0x15 with the HID-over-I2C register
- * protocol (16-bit little-endian register addresses).  The device reports
- * absolute finger positions in the Elan 0x5D vendor report; the driver turns
- * successive positions into pointer deltas.
- */
+ * Two backends share this file: the Elan on the Braswell LPSS I2C6 and the
+ * Synaptics 06CB:7F8F on the Sunrise Point-LP LPSS I2C0 (Yoga 720-13IKB).
+ * Both use 16-bit HID-over-I2C register addresses; the report decoders differ
+ * and feed the same touchpad_gesture engine. */
 #ifndef TOUCHPAD_H
 #define TOUCHPAD_H
 

+ 30 - 0
kernel/tpec.c

@@ -230,6 +230,25 @@ static int str_eq(const char *a, const char *b)
 	return *a == *b;
 }
 
+static int str_has(const char *hay, const char *needle)
+{
+	const char *h, *n;
+
+	if (!*needle)
+		return 1;
+	for (; *hay; hay++) {
+		h = hay;
+		n = needle;
+		while (*h && *n && *h == *n) {
+			h++;
+			n++;
+		}
+		if (!*n)
+			return 1;
+	}
+	return 0;
+}
+
 static void log_info(void)
 {
 	serial_puts(SERIAL_COM1, "tpec: ");
@@ -271,6 +290,17 @@ void tpec_init(void)
 		return;
 	}
 
+	/* The H8 register map is ThinkPad-specific.  IdeaPads/Yogas are also
+	 * LENOVO but their ACPI EC answers different registers, so do not
+	 * write the ThinkPad battery page selector or report bogus sensors.
+	 * ThinkPads put the name in the product or version string depending on
+	 * the model (e.g. 20AX... / "ThinkPad X201"). */
+	if (!str_has(product, "ThinkPad") && !str_has(version, "ThinkPad")) {
+		log_info();
+		serial_puts(SERIAL_COM1, ": not a ThinkPad, no EC probe\n");
+		return;
+	}
+
 	if (ec_read(TP_FAN_LEVEL, &probe) != 0) {
 		log_info();
 		serial_puts(SERIAL_COM1, ": EC not responding\n");

+ 11 - 6
tools/qmp_cursor_test.py

@@ -169,11 +169,16 @@ def main():
 
         if mode == "hotplug":
             qmp_cmd(s, "device_add", {"driver": "usb-mouse", "id": "mouse"})
-            time.sleep(2)
+            time.sleep(4)
 
+        # Move to the empty desktop first: (100,100) sits over the terminal,
+        # whose I-beam/theme cursor is not the built-in arrow this test looks
+        # for.  The cursor movement itself is what is under test.
+        move(s, 1500, 500)
+        time.sleep(0.5)
         w, h, pix = screendump(s, ppm)
         start = find_cursor(w, h, pix)
-        move(s, 250, 150)
+        move(s, -250, -150)
         time.sleep(0.5)
         w, h, pix = screendump(s, ppm)
         end = find_cursor(w, h, pix)
@@ -182,18 +187,18 @@ def main():
             qmp_cmd(s, "device_del", {"id": "mouse"})
             time.sleep(1)
             qmp_cmd(s, "device_add", {"driver": "usb-mouse", "id": "mouse"})
-            time.sleep(2)
+            time.sleep(4)
             move(s, -100, -60)
             time.sleep(0.5)
             w, h, pix = screendump(s, ppm)
             end2 = find_cursor(w, h, pix)
-            ok = (start == (100, 100) and end == (350, 250) and
-                  end2 == (250, 190))
+            ok = (start == (1600, 600) and end == (1350, 450) and
+                  end2 == (1250, 390))
             print("mode=%s fb=%dx%d boot=%s plug=%s replug=%s -> %s"
                   % (mode, w, h, start, end, end2,
                      "ok" if ok else "MISMATCH"))
         else:
-            ok = start == (100, 100) and end == (350, 250)
+            ok = start == (1600, 600) and end == (1350, 450)
             print("mode=%s fb=%dx%d cursor %s -> %s : %s"
                   % (mode, w, h, start, end, "ok" if ok else "MISMATCH"))
 

+ 8 - 4
user/apps/powerinfo/ucmd_powerinfo.c

@@ -2,8 +2,8 @@
  *
  * The EC access lives in the kernel (SYS_POWER_INFO); this command only
  * formats the snapshot.  The same syscall feeds the WM's top-bar AC and
- * battery indicators.  Both the ThinkPad H8 EC and the Chrome OS EC fill
- * the same snapshot.
+ * battery indicators.  The ThinkPad H8 EC, the IdeaPad ACPI EC and the
+ * Chrome OS EC all fill the same snapshot.
  */
 #include "ucmd_lib.h"
 
@@ -143,6 +143,8 @@ void _start(void)
 		u_puts("chrome ec");
 	else if (p.source == SYS_POWER_SRC_TPEC)
 		u_puts("thinkpad");
+	else if (p.source == SYS_POWER_SRC_IDEAPAD)
+		u_puts("ideapad");
 	else
 		u_puts("embedded controller");
 	if (p.vendor[0]) {
@@ -157,8 +159,10 @@ void _start(void)
 		u_putc(' ');
 		u_puts(p.version);
 	}
-	u_puts(", EC rev ");
-	u_putdec(p.ec_rev);
+	if (p.ec_rev) {
+		u_puts(", EC rev ");
+		u_putdec(p.ec_rev);
+	}
 	u_putc('\n');
 
 	u_puts("ac adapter: ");