From owner-freebsd-current@FreeBSD.ORG Mon Jun 2 13:06:13 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id ED75437B401 for ; Mon, 2 Jun 2003 13:06:13 -0700 (PDT) Received: from postfix4-1.free.fr (postfix4-1.free.fr [213.228.0.62]) by mx1.FreeBSD.org (Postfix) with ESMTP id ED21A43F75 for ; Mon, 2 Jun 2003 13:06:12 -0700 (PDT) (envelope-from nsouch@free.fr) Received: from armor.fastether (nas-cbv-7-62-147-154-133.dial.proxad.net [62.147.154.133]) by postfix4-1.free.fr (Postfix) with SMTP id CBE5E3AE75 for ; Mon, 2 Jun 2003 22:06:02 +0200 (CEST) Received: (qmail 20883 invoked by uid 1001); 2 Jun 2003 22:20:09 -0000 Date: Mon, 2 Jun 2003 22:20:09 +0000 From: Nicolas Souchu To: Dag-Erling Smorgrav Message-ID: <20030602222009.A16160@armor.free.fr> References: <20030531210600.GA670@tombstone.localnet.gomerbud.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="HcAYCG3uE/tztfnV" Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from des@ofug.org on Sun, Jun 01, 2003 at 01:52:57AM +0200 cc: "David P. Reese Jr." cc: current@freebsd.org Subject: Re: viapropm doesnt like sys/dev/pci.c rev 1.214 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jun 2003 20:06:14 -0000 --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sun, Jun 01, 2003 at 01:52:57AM +0200, Dag-Erling Smorgrav wrote: > "David P. Reese Jr." writes: > > In rev 1.214 of sys/dev/pci/pci.c, we have started checking if a > > pci_set_command_bit() was successful with a subsequent PCI_READ_CONFIG > > and comparing the results. For some odd reason, this doesnt work when > > my viapropm tries to attach. > > viapropm is seriously broken for other reasons and needs professional > help. What kind of breakage? Setting resources in probe? Right. Anybody having the viapm driver loaded usually should please try the attached patch. > > pci_set_command_bit(dev, child, bit); > > command = PCI_READ_CONFIG(dev, child, PCIR_COMMAND, 2); > > if (command & bit) > > return (0); > > It should allow the register to "settle" between write and read, which > may take some time (see chipset docs for timing details). DELAY(1000) > should be OK in an attach function. The datasheet states that the command bits are RW but "fixed at 0". Nicholas -- Nicholas Souchu - nsouch@free.fr - nsouch@FreeBSD.org --HcAYCG3uE/tztfnV Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="viapm.diffs" Index: viapm.c =================================================================== RCS file: /home/ncvs/src/sys/pci/viapm.c,v retrieving revision 1.2 diff -u -r1.2 viapm.c --- viapm.c 9 Nov 2002 20:13:16 -0000 1.2 +++ viapm.c 25 May 2003 22:00:03 -0000 @@ -79,7 +79,6 @@ #define VIAPM_TYP_8233 5 struct viapm_softc { - int type; u_int32_t base; bus_space_tag_t st; bus_space_handle_t sh; @@ -179,137 +178,42 @@ static int viapm_586b_probe(device_t dev) { - struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev); - u_int32_t l; - u_int16_t s; - u_int8_t c; + if (pci_get_devid(dev) != VIA_586B_PMU_ID) + return ENXIO; - switch (pci_get_devid(dev)) { - case VIA_586B_PMU_ID: - - bzero(viapm, sizeof(struct viapm_softc)); - - l = pci_read_config(dev, VIAPM_586B_REVID, 1); - switch (l) { - case VIAPM_586B_OEM_REV_E: - viapm->type = VIAPM_TYP_586B_3040E; - viapm->iorid = VIAPM_586B_3040E_BASE; - - /* Activate IO block access */ - s = pci_read_config(dev, VIAPM_586B_3040E_ACTIV, 2); - pci_write_config(dev, VIAPM_586B_3040E_ACTIV, s | 0x1, 2); - break; - - case VIAPM_586B_OEM_REV_F: - case VIAPM_586B_PROD_REV_A: - default: - viapm->type = VIAPM_TYP_586B_3040F; - viapm->iorid = VIAPM_586B_3040F_BASE; - - /* Activate IO block access */ - c = pci_read_config(dev, VIAPM_586B_3040F_ACTIV, 1); - pci_write_config(dev, VIAPM_586B_3040F_ACTIV, c | 0x80, 1); - break; - } - - viapm->base = pci_read_config(dev, viapm->iorid, 4) & - VIAPM_586B_BA_MASK; - - /* - * We have to set the I/O resources by hand because it is - * described outside the viapmope of the traditional maps - */ - if (bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid, - viapm->base, 256)) { - device_printf(dev, "could not set bus resource\n"); - return ENXIO; - } - device_set_desc(dev, "VIA VT82C586B Power Management Unit"); - return 0; - - default: - break; - } - - return ENXIO; + device_set_desc(dev, "VIA VT82C586B Power Management Unit"); + return 0; } - static int viapm_pro_probe(device_t dev) { - struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev); -#ifdef VIAPM_BASE_ADDR - u_int32_t l; -#endif - u_int32_t base_cfgreg; char *desc; switch (pci_get_devid(dev)) { case VIA_596A_PMU_ID: desc = "VIA VT82C596A Power Management Unit"; - viapm->type = VIAPM_TYP_596B; - base_cfgreg = VIAPM_PRO_BASE; - goto viapro; + break; case VIA_596B_PMU_ID: desc = "VIA VT82C596B Power Management Unit"; - viapm->type = VIAPM_TYP_596B; - base_cfgreg = VIAPM_PRO_BASE; - goto viapro; + break; case VIA_686A_PMU_ID: desc = "VIA VT82C686A Power Management Unit"; - viapm->type = VIAPM_TYP_686A; - base_cfgreg = VIAPM_PRO_BASE; - goto viapro; + break; case VIA_8233_PMU_ID: desc = "VIA VT8233 Power Management Unit"; - viapm->type = VIAPM_TYP_UNKNOWN; - base_cfgreg = VIAPM_8233_BASE; - goto viapro; - - viapro: - -#ifdef VIAPM_BASE_ADDR - /* force VIAPM I/O base address */ - - /* enable the SMBus controller function */ - l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1); - pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 1, 1); - - /* write the base address */ - pci_write_config(dev, base_cfgreg, - VIAPM_BASE_ADDR & VIAPM_PRO_BA_MASK, 4); -#endif - - viapm->base = pci_read_config(dev, base_cfgreg, 4) & VIAPM_PRO_BA_MASK; - - /* - * We have to set the I/O resources by hand because it is - * described outside the viapmope of the traditional maps - */ - viapm->iorid = base_cfgreg; - if (bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid, - viapm->base, 16)) { - device_printf(dev, "could not set bus resource 0x%x\n", - viapm->base); - return ENXIO; - } - - if (1 || bootverbose) { - device_printf(dev, "SMBus I/O base at 0x%x\n", viapm->base); - } - - device_set_desc(dev, desc); - return 0; + break; default: - break; + return ENXIO; + /* not reached */ } - return ENXIO; + device_set_desc(dev, desc); + return 0; } static int @@ -317,6 +221,39 @@ { struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev); u_int32_t l; + u_int32_t base_cfgreg; + + bzero(viapm, sizeof(struct viapm_softc)); + + if (pci_get_devid(dev) == VIA_8233_PMU_ID) + base_cfgreg = VIAPM_8233_BASE; + else + base_cfgreg = VIAPM_PRO_BASE; + +#ifdef VIAPM_BASE_ADDR + /* force VIAPM I/O base address */ + + /* enable the SMBus controller function */ + l = pci_read_config(dev, VIAPM_PRO_SMBCTRL, 1); + pci_write_config(dev, VIAPM_PRO_SMBCTRL, l | 1, 1); + + /* write the base address */ + pci_write_config(dev, base_cfgreg, + VIAPM_BASE_ADDR & VIAPM_PRO_BA_MASK, 4); +#endif + + viapm->base = pci_read_config(dev, base_cfgreg, 4) & VIAPM_PRO_BA_MASK; + + /* + * We have to set the I/O resources by hand because it is + * described outside the viapmope of the traditional maps + */ + viapm->iorid = base_cfgreg; + bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid, viapm->base, 16); + + if (1 || bootverbose) { + device_printf(dev, "SMBus I/O base at 0x%x\n", viapm->base); + } if (!(viapm->iores = bus_alloc_resource(dev, SYS_RES_IOPORT, &viapm->iorid, 0l, ~0l, 1, RF_ACTIVE))) { @@ -385,6 +322,40 @@ viapm_586b_attach(device_t dev) { struct viapm_softc *viapm = (struct viapm_softc *)device_get_softc(dev); + u_int32_t l; + u_int16_t s; + u_int8_t c; + + bzero(viapm, sizeof(struct viapm_softc)); + + l = pci_read_config(dev, VIAPM_586B_REVID, 1); + switch (l) { + case VIAPM_586B_OEM_REV_E: + viapm->iorid = VIAPM_586B_3040E_BASE; + + /* Activate IO block access */ + s = pci_read_config(dev, VIAPM_586B_3040E_ACTIV, 2); + pci_write_config(dev, VIAPM_586B_3040E_ACTIV, s | 0x1, 2); + break; + + case VIAPM_586B_OEM_REV_F: + case VIAPM_586B_PROD_REV_A: + default: + viapm->iorid = VIAPM_586B_3040F_BASE; + + /* Activate IO block access */ + c = pci_read_config(dev, VIAPM_586B_3040F_ACTIV, 1); + pci_write_config(dev, VIAPM_586B_3040F_ACTIV, c | 0x80, 1); + break; + } + + viapm->base = pci_read_config(dev, viapm->iorid, 4) & VIAPM_586B_BA_MASK; + + /* + * We have to set the I/O resources by hand because it is + * described outside the viapmope of the traditional maps + */ + bus_set_resource(dev, SYS_RES_IOPORT, viapm->iorid, viapm->base, 256); if (!(viapm->iores = bus_alloc_resource(dev, SYS_RES_IOPORT, &viapm->iorid, 0ul, ~0ul, 1, RF_ACTIVE | RF_SHAREABLE))) { --HcAYCG3uE/tztfnV--