From owner-freebsd-acpi@FreeBSD.ORG Sat Jun 16 18:00:46 2007 Return-Path: X-Original-To: acpi@freebsd.org Delivered-To: freebsd-acpi@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 477F416A47F for ; Sat, 16 Jun 2007 18:00:46 +0000 (UTC) (envelope-from nate@root.org) Received: from root.org (root.org [67.118.192.226]) by mx1.freebsd.org (Postfix) with ESMTP id 2B33713C44B for ; Sat, 16 Jun 2007 18:00:46 +0000 (UTC) (envelope-from nate@root.org) Received: (qmail 11778 invoked from network); 16 Jun 2007 17:09:33 -0000 Received: from ppp-71-139-42-13.dsl.snfc21.pacbell.net (HELO ?10.0.0.15?) (nate-mail@71.139.42.13) by root.org with ESMTPA; 16 Jun 2007 17:09:33 -0000 Message-ID: <46741947.3050200@root.org> Date: Sat, 16 Jun 2007 10:09:27 -0700 From: Nate Lawson User-Agent: Thunderbird 2.0.0.0 (X11/20070511) MIME-Version: 1.0 To: current References: <46735262.50601@root.org> <4673768D.1050805@root.org> In-Reply-To: <4673768D.1050805@root.org> X-Enigmail-Version: 0.95.0 Content-Type: multipart/mixed; boundary="------------000906000805010402060001" Cc: acpi@freebsd.org Subject: Re: smi speedstep patch X-BeenThere: freebsd-acpi@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: ACPI and power management development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 Jun 2007 18:00:46 -0000 This is a multi-part message in MIME format. --------------000906000805010402060001 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Nate Lawson wrote: > Nate Lawson wrote: >> If you have a pentium 3 that works for speedstep, please try this patch. >> It fixes the PAE case. Compile-tested. > > Hmm, I see it's no longer getting the physical address, just virtual. > So need to fix that part. Attached is the updated patch. It uses the low kernel map where P=V and fixes the callback. I just need someone who is using smi-speedstep (440bx chipset with pentium 3) to make sure the device still attaches. Patch should work on 6.x and 7.x. -- Nate --------------000906000805010402060001 Content-Type: text/x-patch; name="smist.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="smist.diff" Index: sys/i386/cpufreq/smist.c =================================================================== RCS file: /home/ncvs/src/sys/i386/cpufreq/smist.c,v retrieving revision 1.1 diff -u -r1.1 smist.c --- sys/i386/cpufreq/smist.c 19 Apr 2005 16:38:24 -0000 1.1 +++ sys/i386/cpufreq/smist.c 16 Jun 2007 16:58:34 -0000 @@ -45,6 +45,7 @@ #include #include +#include #include #include @@ -71,6 +72,8 @@ struct cf_setting sets[2]; /* Only two settings. */ }; +static char smist_magic[] = "Copyright (c) 1999 Intel Corporation"; + static void smist_identify(driver_t *driver, device_t parent); static int smist_probe(device_t dev); static int smist_attach(device_t dev); @@ -147,34 +150,86 @@ return (0); } -static int -set_ownership(device_t dev) -{ - int result; - struct smist_softc *sc; - vm_paddr_t pmagic; - static char magic[] = "Copyright (c) 1999 Intel Corporation"; +/* Temporary structure to hold mapped page and status. */ +struct set_ownership_data { + int smi_cmd; + int command; + int result; + void *buf; +}; - sc = device_get_softc(dev); - if (!sc) - return (ENXIO); +/* Perform actual SMI call to enable SpeedStep. */ +static void +set_ownership_cb(void *arg, bus_dma_segment_t *segs, int nsegs, int error) +{ + struct set_ownership_data *data; - pmagic = vtophys(magic); + data = arg; + if (error) { + data->result = error; + return; + } + strlcpy(data->buf, smist_magic, PAGE_SIZE); __asm __volatile( "movl $-1, %%edi\n\t" "out %%al, (%%dx)\n" - : "=D" (result) - : "a" (sc->command), + : "=D" (data->result) + : "a" (data->command), "b" (0), "c" (0), - "d" (sc->smi_cmd), - "S" (pmagic) + "d" (data->smi_cmd), + "S" ((uint32_t)segs[0].ds_addr) ); +} + +static int +set_ownership(device_t dev) +{ + struct smist_softc *sc; + struct set_ownership_data cb_data; + bus_dma_tag_t tag; + bus_dmamap_t map; + + /* + * Specify the region to store the magic string. Since its address is + * passed to the BIOS in a 32-bit register, we have to make sure it is + * located in a physical page below 4 GB (i.e., for PAE.) Since the + * kernel has an identity map for the first 2 MB, we can get a V=P + * page in the first 1 MB and use it for this purpose. + */ + sc = device_get_softc(dev); + if (bus_dma_tag_create(/*parent*/ NULL, + /*alignment*/ PAGE_SIZE, /*no boundary*/ 0, + /*lowaddr*/ 0x9ffff, /*highaddr*/ BUS_SPACE_MAXADDR, + NULL, NULL, /*maxsize*/ PAGE_SIZE, /*segments*/ 1, + /*maxsegsize*/ PAGE_SIZE, + 0, busdma_lock_mutex, &Giant, &tag) != 0) { + device_printf(dev, "can't create mem tag\n"); + return (ENXIO); + } + if (bus_dmamem_alloc(tag, &cb_data.buf, BUS_DMA_NOWAIT, &map) != 0) { + bus_dma_tag_destroy(tag); + device_printf(dev, "can't alloc mapped mem\n"); + return (ENXIO); + } + + cb_data.smi_cmd = sc->smi_cmd; + cb_data.command = sc->command; + if (bus_dmamap_load(tag, map, cb_data.buf, PAGE_SIZE, set_ownership_cb, + &cb_data, BUS_DMA_NOWAIT) != 0) { + bus_dmamem_free(tag, cb_data.buf, map); + bus_dma_tag_destroy(tag); + device_printf(dev, "can't load mem\n"); + return (ENXIO); + }; - DPRINT(dev, "taking ownership over BIOS return %d\n", result); + DPRINT(dev, "taking ownership over BIOS return %d\n", cb_data.result); - return (result ? ENXIO : 0); + bus_dmamap_unload(tag, map); + bus_dmamem_free(tag, cb_data.buf, map); + bus_dma_tag_destroy(tag); + return (cb_data.result ? ENXIO : 0); } static int --------------000906000805010402060001--