diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2009-11-05 20:30:48 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2009-11-05 20:30:48 +0000 |
commit | 4053e3a000003ae604e38a47f7812d6207b95c85 (patch) | |
tree | 965ff8656006552875459b308db1e5ae6d196bfe /sys/dev/pci | |
parent | f151de983fbddb3f03159901963c29f64d1c139f (diff) |
Add a new PCIOCGETROMLEN ioctl, to give users of PCIOGETROM a chance to
allocate a buffer of the right size.
ok oga@
Diffstat (limited to 'sys/dev/pci')
-rw-r--r-- | sys/dev/pci/pci.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index f5a869d820d..a0eae5a59cd 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pci.c,v 1.67 2009/07/26 13:21:18 kettenis Exp $ */ +/* $OpenBSD: pci.c,v 1.68 2009/11/05 20:30:47 kettenis Exp $ */ /* $NetBSD: pci.c,v 1.31 1997/06/06 23:48:04 thorpej Exp $ */ /* @@ -800,6 +800,7 @@ pciioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) if (!(flag & FWRITE)) return EPERM; break; + case PCIOCGETROMLEN: case PCIOCGETROM: break; default: @@ -857,6 +858,7 @@ pciioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) } break; + case PCIOCGETROMLEN: case PCIOCGETROM: { pcireg_t addr, mask, bhlc; @@ -865,6 +867,8 @@ pciioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) char buf[256]; int s; + rom = (struct pci_rom *)data; + bhlc = pci_conf_read(pc, tag, PCI_BHLC_REG); if (PCI_HDRTYPE_TYPE(bhlc) != 0) return (ENODEV); @@ -888,7 +892,12 @@ pciioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p) PCI_ROM_SIZE(mask) % sizeof(buf)) != 0) return (ENODEV); - rom = (struct pci_rom *)data; + /* If we're just after the size, skip reading the ROM. */ + if (cmd == PCIOCGETROMLEN) { + error = 0; + goto fail; + } + if (rom->pr_romlen < PCI_ROM_SIZE(mask)) { error = ENOMEM; goto fail; |