hybrid: /dev/pci -- a driver can live outside the kernel now
docs/plan/hybrid.md mechanisms 2 and 4: MMIO and DMA to a process.
A process can enumerate the bus, claim a device exclusively, map its BARs and
get memory the device can be pointed at. Proven end to end against an e1000e
-- the exact device class we cannot drive and would want a foreign driver for:
device 7: 8086:10d3 (network)
claimed
BAR0 at 0x81060000, 128 KB
regs[0..3] = 0x00140261 0x00000000 0x00080283 0x00000000
MMIO reaches the device
DMA 8 KB at virtual 0x40001000, physical 0x3f8eb000
Those are the e1000e's CTRL and STATUS with full-duplex and link-up set, which
is how you tell a real mapping from one reading 0xFFFFFFFF off an unmapped
address. Claiming a device the kernel drives is refused -- two writers of one
register set looks like hardware that has started lying -- and everything a
process held is released when it exits, because a driver that crashed must not
keep its hardware away from its replacement.
mmap's offset is the BAR's physical address, checked against the BARs of
devices *this process has claimed*. Without that check the device is /dev/mem
with extra steps and a process could map the kernel's own memory. Mappings are
write-through: a cached write to a doorbell arrives whenever the cache feels
like it, which from a driver's side is indistinguishable from hardware that
ignores you.
The interface is about PCI devices, not about any driver model, and its first
users will be SchOS's own drivers when virtio-gpu is evicted. That ordering is
the design rather than an accident: an interface whose first consumers are
native drivers is a general mechanism something foreign can use later, instead
of a hole shaped like something foreign.
Also: PROT_* and MAP_* moved to include/posix.h. They were defined only in
sys_mem.c, so cmd/fbinfo carried a private copy and this wanted a third --
two copies of a number the kernel compares against, where a mismatch shows up
as a mapping with the wrong permissions rather than an error.
No IOMMU, so this isolates a driver against its own bugs and not against its
own DMA. The plan says so at length and it is still true.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
This commit is contained in:
parent
6c70040f57
commit
24f79194ab
14 changed files with 678 additions and 11 deletions
|
|
@ -53,6 +53,12 @@ extern uint64 boot_tsc;
|
|||
void monotonic(uint64 *sec, uint64 *usec);
|
||||
int proc_write_schinit(int user_src, uint64 src, uint n);
|
||||
int proc_wedge(const char *name);
|
||||
void pciuser_init(void);
|
||||
int pciuser_ioctl(uint64 request, uint64 argp);
|
||||
int pciuser_read(struct inode*, uint64, char*, int);
|
||||
int pciuser_write(struct inode*, uint64, char*, int);
|
||||
int pciuser_mmio_ok(uint64 phys, uint64 len);
|
||||
void pciuser_release_all(struct proc*);
|
||||
int proc_reincarnate(int status);
|
||||
void proc_kill_init(void);
|
||||
extern uint init_generation;
|
||||
|
|
|
|||
Loading…
Reference in a new issue