From: miod Date: Thu, 13 Apr 2023 15:07:42 +0000 (+0000) Subject: Remove intentionally undocumented pci_{io,mem}_find and convert their last X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=7b44a1936692c43037237f4ab19894e4923dda49;p=openbsd Remove intentionally undocumented pci_{io,mem}_find and convert their last few users to pci_mapreg_info(). ok jsg@ --- diff --git a/share/man/man9/pci_mapreg_map.9 b/share/man/man9/pci_mapreg_map.9 index 67ba3eed653..1cf53d40d88 100644 --- a/share/man/man9/pci_mapreg_map.9 +++ b/share/man/man9/pci_mapreg_map.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pci_mapreg_map.9,v 1.1 2019/02/23 04:54:25 dlg Exp $ +.\" $OpenBSD: pci_mapreg_map.9,v 1.2 2023/04/13 15:07:42 miod Exp $ .\" .\" Copyright (c) 2019 David Gwynne .\" All rights reserved. @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: February 23 2019 $ +.Dd $Mdocdate: April 13 2023 $ .Dt PCI_MAPREG_MAP 9 .Os .Sh NAME @@ -23,8 +23,6 @@ .Nm pci_mapreg_info , .Nm pci_mapreg_probe , .Nm pci_mapreg_type -.\" .Nm pci_mem_find , -.\" .Nm pci_io_find .Nd PCI register mappings .Sh SYNOPSIS .In dev/pci/pcivar.h @@ -63,24 +61,6 @@ .Fa "pcitag_t tag" .Fa "int reg" .Fc -.\" .Ft int -.\" .Fo pci_mem_find -.\" .Fa "pci_chipset_tag_t pc" -.\" .Fa "pcitag_t pcitag" -.\" .Fa "int reg" -.\" .Fa "bus_addr_t *basep" -.\" .Fa "bus_size_t *sizep" -.\" .Fa "int *cacheablep" -.\" .Fc -.\" .Ft int -.\" .Fo pci_io_find -.\" .Fa "pci_chipset_tag_t pc" -.\" .Fa "pcitag_t pcitag" -.\" .Fa "int reg" -.\" .Fa "bus_addr_t *basep" -.\" .Fa "bus_size_t *sizep" -.\" .Fa "int *cacheablep" -.\" .Fc .Sh DESCRIPTION These functions provide wrappers and helpers around .Xr bus_space 9 diff --git a/sys/arch/hppa/dev/sti_pci_machdep.c b/sys/arch/hppa/dev/sti_pci_machdep.c index 169e10c1cbc..4071535e0aa 100644 --- a/sys/arch/hppa/dev/sti_pci_machdep.c +++ b/sys/arch/hppa/dev/sti_pci_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sti_pci_machdep.c,v 1.2 2009/04/10 17:11:27 miod Exp $ */ +/* $OpenBSD: sti_pci_machdep.c,v 1.3 2023/04/13 15:07:43 miod Exp $ */ /* * Copyright (c) 2007, 2009 Miodrag Vallat. @@ -51,22 +51,13 @@ sti_pci_is_console(struct pci_attach_args *paa, bus_addr_t *bases) * matches what PAGE0 says, then we are the console, and it * doesn't matter which BAR matched. */ - for (bar = PCI_MAPREG_START; bar <= PCI_MAPREG_PPB_END; ) { + for (bar = PCI_MAPREG_START; bar <= PCI_MAPREG_PPB_END; bar += 4) { cf = pci_conf_read(paa->pa_pc, paa->pa_tag, bar); - - if (PCI_MAPREG_TYPE(cf) == PCI_MAPREG_TYPE_IO) { - rc = pci_io_find(paa->pa_pc, paa->pa_tag, bar, &addr, - NULL); + rc = pci_mapreg_info(paa->pa_pc, paa->pa_tag, bar, + _PCI_MAPREG_TYPEBITS(cf), &addr, NULL, NULL); + if (PCI_MAPREG_TYPE(cf) == PCI_MAPREG_TYPE_MEM && + PCI_MAPREG_MEM_TYPE(cf) == PCI_MAPREG_MEM_TYPE_64BIT) bar += 4; - } else { - rc = pci_mem_find(paa->pa_pc, paa->pa_tag, bar, &addr, - NULL, NULL); - if (PCI_MAPREG_MEM_TYPE(cf) == - PCI_MAPREG_MEM_TYPE_64BIT) - bar += 8; - else - bar += 4; - } if (rc == 0 && (hppa_hpa_t)addr == (hppa_hpa_t)PAGE0->mem_cons.pz_hpa) diff --git a/sys/arch/macppc/pci/vgafb.c b/sys/arch/macppc/pci/vgafb.c index f7be0086be0..af88664d981 100644 --- a/sys/arch/macppc/pci/vgafb.c +++ b/sys/arch/macppc/pci/vgafb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vgafb.c,v 1.64 2022/12/31 05:06:18 gkoehler Exp $ */ +/* $OpenBSD: vgafb.c,v 1.65 2023/04/13 15:07:43 miod Exp $ */ /* $NetBSD: vga.c,v 1.3 1996/12/02 22:24:54 cgd Exp $ */ /* @@ -508,7 +508,7 @@ vgafb_mapregs(struct vgafb_softc *sc, struct pci_attach_args *pa) bus_addr_t ba; bus_size_t bs; int hasmem = 0, hasmmio = 0; - uint32_t i, cf; + uint32_t bar, cf; int rv; /* @@ -517,12 +517,12 @@ vgafb_mapregs(struct vgafb_softc *sc, struct pci_attach_args *pa) * For nvidia, this finds mmio 0x10 and frame memory 0x14. * Some nvidias have a 3rd mem region 0x18, which we ignore. */ - for (i = PCI_MAPREG_START; i <= PCI_MAPREG_PPB_END; i += 4) { - cf = pci_conf_read(pa->pa_pc, pa->pa_tag, i); + for (bar = PCI_MAPREG_START; bar <= PCI_MAPREG_PPB_END; bar += 4) { + cf = pci_conf_read(pa->pa_pc, pa->pa_tag, bar); if (PCI_MAPREG_TYPE(cf) == PCI_MAPREG_TYPE_MEM) { /* Memory mapping... frame memory or mmio? */ - rv = pci_mem_find(pa->pa_pc, pa->pa_tag, i, - &ba, &bs, NULL); + rv = pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, + _PCI_MAPREG_TYPEBITS(cf), &ba, &bs, NULL); if (rv != 0) continue; @@ -558,6 +558,9 @@ vgafb_mapregs(struct vgafb_softc *sc, struct pci_attach_args *pa) /* Ignore any other mem region. */ break; } + if (PCI_MAPREG_MEM_TYPE(cf) == + PCI_MAPREG_MEM_TYPE_64BIT) + bar += 4; } } diff --git a/sys/arch/sparc64/dev/vgafb.c b/sys/arch/sparc64/dev/vgafb.c index d5624a4c517..abab50a835f 100644 --- a/sys/arch/sparc64/dev/vgafb.c +++ b/sys/arch/sparc64/dev/vgafb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vgafb.c,v 1.68 2022/07/15 17:57:26 kettenis Exp $ */ +/* $OpenBSD: vgafb.c,v 1.69 2023/04/13 15:07:43 miod Exp $ */ /* * Copyright (c) 2001 Jason L. Wright (jason@thought.net) @@ -377,31 +377,32 @@ vgafb_mapregs(struct vgafb_softc *sc, struct pci_attach_args *pa) bus_addr_t ba; bus_size_t bs; int hasio = 0, hasmem = 0, hasmmio = 0; - u_int32_t i, cf; + u_int32_t bar, cf; int rv; - for (i = PCI_MAPREG_START; i <= PCI_MAPREG_PPB_END; i += 4) { - cf = pci_conf_read(pa->pa_pc, pa->pa_tag, i); + for (bar = PCI_MAPREG_START; bar <= PCI_MAPREG_PPB_END; bar += 4) { + cf = pci_conf_read(pa->pa_pc, pa->pa_tag, bar); if (PCI_MAPREG_TYPE(cf) == PCI_MAPREG_TYPE_IO) { if (hasio) continue; - rv = pci_io_find(pa->pa_pc, pa->pa_tag, i, - &sc->sc_io_addr, &sc->sc_io_size); + rv = pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, + _PCI_MAPREG_TYPEBITS(cf), + &sc->sc_io_addr, &sc->sc_io_size, NULL); if (rv != 0) { if (rv != ENOENT) printf("%s: failed to find io at 0x%x\n", - sc->sc_sunfb.sf_dev.dv_xname, i); + sc->sc_sunfb.sf_dev.dv_xname, bar); continue; } hasio = 1; } else { /* Memory mapping... frame memory or mmio? */ - rv = pci_mem_find(pa->pa_pc, pa->pa_tag, i, - &ba, &bs, NULL); + rv = pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, + _PCI_MAPREG_TYPEBITS(cf), &ba, &bs, NULL); if (rv != 0) { if (rv != ENOENT) printf("%s: failed to find mem at 0x%x\n", - sc->sc_sunfb.sf_dev.dv_xname, i); + sc->sc_sunfb.sf_dev.dv_xname, bar); continue; } @@ -435,6 +436,9 @@ vgafb_mapregs(struct vgafb_softc *sc, struct pci_attach_args *pa) sc->sc_mem_size = bs; } } + if (PCI_MAPREG_MEM_TYPE(cf) == + PCI_MAPREG_MEM_TYPE_64BIT) + bar += 4; } } diff --git a/sys/dev/pci/pci_map.c b/sys/dev/pci/pci_map.c index 3cc0e61c0df..dd469f79707 100644 --- a/sys/dev/pci/pci_map.c +++ b/sys/dev/pci/pci_map.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pci_map.c,v 1.32 2019/06/17 11:04:06 kettenis Exp $ */ +/* $OpenBSD: pci_map.c,v 1.33 2023/04/13 15:07:43 miod Exp $ */ /* $NetBSD: pci_map.c,v 1.7 2000/05/10 16:58:42 thorpej Exp $ */ /*- @@ -254,21 +254,6 @@ obsd_pci_mem_find(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t type, return (0); } -int -pci_io_find(pci_chipset_tag_t pc, pcitag_t pcitag, int reg, - bus_addr_t *iobasep, bus_size_t *iosizep) -{ - return (obsd_pci_io_find(pc, pcitag, reg, 0, iobasep, iosizep, 0)); -} - -int -pci_mem_find(pci_chipset_tag_t pc, pcitag_t pcitag, int reg, - bus_addr_t *membasep, bus_size_t *memsizep, int *cacheablep) -{ - return (obsd_pci_mem_find(pc, pcitag, reg, -1, membasep, memsizep, - cacheablep)); -} - pcireg_t pci_mapreg_type(pci_chipset_tag_t pc, pcitag_t tag, int reg) { diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h index 70380813498..fa009f96b28 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pcivar.h,v 1.77 2022/01/04 20:43:44 deraadt Exp $ */ +/* $OpenBSD: pcivar.h,v 1.78 2023/04/13 15:07:43 miod Exp $ */ /* $NetBSD: pcivar.h,v 1.23 1997/06/06 23:48:05 thorpej Exp $ */ /* @@ -231,11 +231,6 @@ int pci_mapreg_map(struct pci_attach_args *, int, pcireg_t, int, bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *, bus_size_t *, bus_size_t); -int pci_io_find(pci_chipset_tag_t, pcitag_t, int, bus_addr_t *, - bus_size_t *); -int pci_mem_find(pci_chipset_tag_t, pcitag_t, int, bus_addr_t *, - bus_size_t *, int *); - int pci_get_capability(pci_chipset_tag_t, pcitag_t, int, int *, pcireg_t *); int pci_get_ht_capability(pci_chipset_tag_t, pcitag_t, int, diff --git a/sys/dev/pci/ppb.c b/sys/dev/pci/ppb.c index e081932356f..cf7cb120cc1 100644 --- a/sys/dev/pci/ppb.c +++ b/sys/dev/pci/ppb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ppb.c,v 1.71 2023/01/20 15:11:44 kettenis Exp $ */ +/* $OpenBSD: ppb.c,v 1.72 2023/04/13 15:07:43 miod Exp $ */ /* $NetBSD: ppb.c,v 1.16 1997/06/06 23:48:05 thorpej Exp $ */ /* @@ -637,6 +637,10 @@ ppb_alloc_resources(struct ppb_softc *sc, struct pci_attach_args *pa) io_count++; else mem_count++; + + if (type == (PCI_MAPREG_TYPE_MEM | + PCI_MAPREG_MEM_TYPE_64BIT)) + reg += 4; } if (reg_rom != 0) { diff --git a/sys/dev/pci/rtsx_pci.c b/sys/dev/pci/rtsx_pci.c index 39058b7c553..08b4ab7a136 100644 --- a/sys/dev/pci/rtsx_pci.c +++ b/sys/dev/pci/rtsx_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsx_pci.c,v 1.15 2022/03/11 18:00:51 mpi Exp $ */ +/* $OpenBSD: rtsx_pci.c,v 1.16 2023/04/13 15:07:43 miod Exp $ */ /* * Copyright (c) 2006 Uwe Stuehler @@ -83,6 +83,7 @@ rtsx_pci_attach(struct device *parent, struct device *self, void *aux) bus_size_t size; int flags; int bar = RTSX_PCI_BAR; + pcireg_t type; if ((pci_conf_read(pa->pa_pc, pa->pa_tag, RTSX_CFG_PCI) & RTSX_CFG_ASIC) != 0) { @@ -121,13 +122,13 @@ rtsx_pci_attach(struct device *parent, struct device *self, void *aux) break; } - if (pci_mem_find(pa->pa_pc, pa->pa_tag, bar, NULL, NULL, NULL) != 0) { + type = pci_mapreg_type(pa->pa_pc, pa->pa_tag, bar); + if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, type, NULL, NULL, + NULL) != 0) { printf("%s: can't find registers\n", sc->sc.sc_dev.dv_xname); return; } - - if (pci_mapreg_map(pa, bar, PCI_MAPREG_TYPE_MEM, 0, &iot, &ioh, NULL, - &size, 0)) { + if (pci_mapreg_map(pa, bar, type, 0, &iot, &ioh, NULL, &size, 0)) { printf("%s: can't map registers\n", sc->sc.sc_dev.dv_xname); return; } diff --git a/sys/dev/pci/sti_pci.c b/sys/dev/pci/sti_pci.c index a84f3f394e1..cd51403de1c 100644 --- a/sys/dev/pci/sti_pci.c +++ b/sys/dev/pci/sti_pci.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sti_pci.c,v 1.12 2023/04/03 18:59:47 miod Exp $ */ +/* $OpenBSD: sti_pci.c,v 1.13 2023/04/13 15:07:43 miod Exp $ */ /* * Copyright (c) 2006, 2007, 2023 Miodrag Vallat. @@ -316,7 +316,7 @@ sti_readbar(struct sti_softc *sc, struct pci_attach_args *pa, u_int region, { bus_addr_t addr; bus_size_t size; - u_int32_t cf; + pcireg_t type; int rc; if (bar == 0) { @@ -332,15 +332,9 @@ sti_readbar(struct sti_softc *sc, struct pci_attach_args *pa, u_int region, return EINVAL; } - cf = pci_conf_read(pa->pa_pc, pa->pa_tag, bar); - - if (PCI_MAPREG_TYPE(cf) == PCI_MAPREG_TYPE_IO) { - rc = pci_io_find(pa->pa_pc, pa->pa_tag, bar, - &addr, &size); - } else { - rc = pci_mem_find(pa->pa_pc, pa->pa_tag, bar, - &addr, &size, NULL); - } + type = pci_mapreg_type(pa->pa_pc, pa->pa_tag, bar); + rc = pci_mapreg_info(pa->pa_pc, pa->pa_tag, bar, type, &addr, &size, + NULL); if (rc != 0) { printf("%s: invalid bar %02x for region %d\n", sc->sc_dev.dv_xname, bar, region);