On Sun, May 15, 2011 at 03:56:16PM +0530, Martin Pieuchot wrote:
> On 04/05/11(Wed) 20:29, Miod Vallat wrote:
> > > > Speaking of DELAY()... it is implemented using the processor internal
> > > > counter register. Is this register impacted by frequency changes? If so,
> > > > shouldn't you update the computed ns_per_tick delay() constant?
> > > 
> > > Reading the doc again, it's said that the time base register is clocked
> > > at one-fourth of the bus clock. But the DFS feature divides the processor 
> > > to system bus ratio. So, if I understand well there is no impact on the
> > > time base counter frequency.
> > 
> > Good. This is easy to check, does ntpd start complaining after running a
> > few minutes at `setperf=0' speed?
> > 
> > > Index: sys/arch/macppc/dev/dfs.c
> > 
> > > +#include <sys/param.h>
> > > +#include <sys/filedesc.h>
> > 
> > Could you use <sys/proc.h> instead of <sys/filedesc.h> here? This is the
> > preferred (yet objectionable) form of satisfying <sys/sysctl.h>
> > dependencies.
> > 
> > > +struct cfattach dfs_ca = {
> > > + sizeof(struct device), dfs_match, dfs_attach
> > 
> > This needs to be sizeof(struct dfs_softc) now. That is, unless you want
> > to get funny panics after dfs0 attaches.
> 
> After some tests and discussions with the powermac owners it appears
> that there is no obvious way to enable dfs on these machines. So no dfs
> support for the mac mini.
> 
> Updated diff, now looking for oks for the driver and the manpage.
> 
> Martin
> 
> Index: conf/GENERIC
> ===================================================================
> RCS file: /cvs/src/sys/arch/macppc/conf/GENERIC,v
> retrieving revision 1.207
> diff -u -p -r1.207 GENERIC
> --- conf/GENERIC      19 Apr 2011 23:07:54 -0000      1.207
> +++ conf/GENERIC      15 May 2011 09:25:14 -0000
> @@ -155,6 +155,7 @@ macgpio*  at macobio?     # GPIO, PMU interru
>  macgpio*     at macgpio?     # GPIO, PMU interrupt router.
>  sysbutton*   at macgpio?     # Xserve system id button.
>  pgs*         at macgpio?     # Programmer Switch.
> +dfs*         at macgpio?     # Dynamic Frequence Switching.
>  akbd*                at adb?         # ADB keyboard
>  wskbd*               at akbd? mux 1
>  ams*         at adb?         # ADB mouse
> Index: conf/files.macppc
> ===================================================================
> RCS file: /cvs/src/sys/arch/macppc/conf/files.macppc,v
> retrieving revision 1.63
> diff -u -p -r1.63 files.macppc
> --- conf/files.macppc 6 Dec 2010 20:10:18 -0000       1.63
> +++ conf/files.macppc 15 May 2011 09:25:14 -0000
> @@ -237,6 +237,10 @@ device   pgs {}
>  attach       pgs at macgpio
>  file arch/macppc/dev/pgs.c
>  
> +device       dfs {}
> +attach       dfs at macgpio
> +file arch/macppc/dev/dfs.c
> +
>  attach       wdc at mediabay, macobio, kauaiata with wdc_obio
>  file arch/macppc/dev/wdc_obio.c                      wdc_obio
>  
> Index: dev/dfs.c
> ===================================================================
> RCS file: dev/dfs.c
> diff -N dev/dfs.c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ dev/dfs.c 15 May 2011 09:25:14 -0000
> @@ -0,0 +1,167 @@
> +/*   $OpenBSD$       */
> +/*
> + * Copyright (c) 2011 Martin Pieuchot <m...@nolizard.org>
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> + */
> +
> +#include <sys/param.h>
> +#include <sys/proc.h>
> +#include <sys/sysctl.h>
> +
> +#include <dev/ofw/openfirm.h>
> +
> +#include <machine/cpu.h>
> +#include <machine/autoconf.h>
> +#include <macppc/pci/macobio.h>
> +
> +#define DFS2 (1 << 22)       /* Divide-by-Two */
> +#define DFS4 (1 << 23)       /* Divide-by-Four (MPC7448 Specific) */
> +
> +extern int perflevel;
> +
> +struct dfs_softc {
> +     struct device   sc_dev;
> +     int             sc_voltage;
> +};
> +
> +int  dfs_match(struct device *, void *, void *);
> +void dfs_attach(struct device *, struct device *, void *);
> +void dfs_setperf(int);
> +void dfs_scale_frequency(u_int);
> +
> +struct cfattach dfs_ca = {
> +     sizeof(struct dfs_softc), dfs_match, dfs_attach
> +};
> +
> +struct cfdriver dfs_cd = {
> +     NULL, "dfs", DV_DULL
> +};
> +
> +int
> +dfs_match(struct device *parent, void *arg, void *aux)
> +{
> +     struct confargs *ca = aux;
> +     uint16_t cpu;
> +
> +     if (strcmp(ca->ca_name, "cpu-vcore-select") != 0)
> +             return (0);
> +
> +     cpu = ppc_mfpvr() >> 16;
> +     if (cpu == PPC_CPU_MPC7447A || cpu == PPC_CPU_MPC7448)
> +                     return (1);
> +
> +     return (0);
> +}
> +
> +void
> +dfs_attach(struct device *parent, struct device *self, void *aux)
> +{
> +     struct dfs_softc *sc = (struct dfs_softc *)self;
> +     struct confargs *ca = aux;
> +     uint32_t hid1, reg;
> +     uint16_t cpu;
> +
> +     /*
> +      * On some models the vcore-select offset is relative to
> +      * its parent offset and not to the bus base address.
> +      */
> +     OF_getprop(OF_parent(ca->ca_node), "reg", &reg, sizeof(reg));
> +     if (reg > ca->ca_reg[0])
> +             sc->sc_voltage = reg + ca->ca_reg[0];
> +     else
> +             sc->sc_voltage = ca->ca_reg[0];
> +
> +     hid1 = ppc_mfhid1();
> +
> +     if (hid1 & DFS4) {
> +             ppc_curfreq = ppc_maxfreq / 4;
> +             perflevel = 25;
> +     } else if (hid1 & DFS2) {
> +             ppc_curfreq = ppc_maxfreq / 2;
> +             perflevel = 50;
> +     }
> +
> +     cpu_setperf = dfs_setperf;
> +
> +     printf(": speeds: %d, %d", ppc_maxfreq, ppc_maxfreq / 2);
> +
> +     cpu = ppc_mfpvr() >> 16;
> +     if (cpu == PPC_CPU_MPC7448)
> +             printf(", %d", ppc_maxfreq / 4);
> +     printf(" MHz\n");
> +}
> +
> +void
> +dfs_setperf(int perflevel)
> +{
> +     struct dfs_softc *sc = dfs_cd.cd_devs[0];
> +
> +     if (perflevel > 50) {
> +             if (ppc_curfreq != ppc_maxfreq) {
> +                     macobio_write(sc->sc_voltage, GPIO_DDR_OUTPUT | 1);
> +                     delay(1000);
> +                     dfs_scale_frequency(FREQ_FULL);
> +             }
> +     } else {
> +             uint16_t cpu;
> +
> +             cpu = ppc_mfpvr() >> 16;
> +             if (cpu == PPC_CPU_MPC7448 && perflevel <= 25)  {
> +                     if (ppc_curfreq != ppc_maxfreq / 4) {
> +                             dfs_scale_frequency(FREQ_QUARTER);
> +                             macobio_write(sc->sc_voltage,
> +                                 GPIO_DDR_OUTPUT | 0);
> +                             delay(1000);
> +                     }
> +             } else {
> +                     if (ppc_curfreq != ppc_maxfreq / 2) {
> +                             dfs_scale_frequency(FREQ_HALF);
> +                             macobio_write(sc->sc_voltage,
> +                                 GPIO_DDR_OUTPUT | 0);
> +                             delay(1000);
> +                     }
> +             }
> +     }
> +}
> +
> +void
> +dfs_scale_frequency(u_int freq_scale)
> +{
> +     uint32_t hid1;
> +     int s;
> +
> +     s = splhigh();
> +     hid1 = ppc_mfhid1();
> +
> +     hid1 &= ~(DFS2 | DFS4);
> +     switch (freq_scale) {
> +     case FREQ_QUARTER:
> +             hid1 |= DFS4;
> +             ppc_curfreq = ppc_maxfreq / 4;
> +             break;
> +     case FREQ_HALF:
> +             hid1 |= DFS2;
> +             ppc_curfreq = ppc_maxfreq / 2;
> +             break;
> +     case FREQ_FULL: /* FALLTHROUGH */
> +     default:
> +             ppc_curfreq = ppc_maxfreq;
> +     }
> +
> +     asm volatile ("sync");
> +     ppc_mthid1(hid1);
> +     asm volatile ("sync; isync");
> +
> +     splx(s);
> +}
> 
> 
> Index: Makefile
> ===================================================================
> RCS file: /cvs/src/share/man/man4/man4.macppc/Makefile,v
> retrieving revision 1.33
> diff -u -p -r1.33 Makefile
> --- Makefile  9 Apr 2010 19:25:38 -0000       1.33
> +++ Makefile  15 May 2011 09:34:50 -0000
> @@ -3,7 +3,7 @@
>  #    Id: Makefile,v 1.4 1995/12/14 05:41:38 deraadt Exp $
>  
>  MAN= abtn.4 adb.4 aoa.4 apm.4 asms.4 autoconf.4 awacs.4 \
> -     bm.4 daca.4 esp.4 fcu.4 ht.4 intro.4 \
> +     bm.4 daca.4 dfs.4 esp.4 fcu.4 ht.4 intro.4 \
>       kauaiata.4 kiic.4 macobio.4 macgpio.4 mc.4 mediabay.4 mem.4 memc.4 \
>       mesh.4 mpcpcibr.4 openpic.4 openprom.4 onyx.4 pgs.4 piic.4 smu.4 \
>       snapper.4 sysbutton.4 tpms.4 tumbler.4 xlights.4 zs.4
> Index: dfs.4
> ===================================================================
> RCS file: dfs.4
> diff -N dfs.4
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ dfs.4     15 May 2011 09:34:50 -0000
> @@ -0,0 +1,53 @@
> +.\"  $OpenBSD$
> +.\"
> +.\" Copyright (c) 2011 Martin Pieuchot <m...@nolizard.org>
> +.\"
> +.\" Permission to use, copy, modify, and distribute this software for any
> +.\" purpose with or without fee is hereby granted, provided that the above
> +.\" copyright notice and this permission notice appear in all copies.
> +.\"
> +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
> +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
> +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
> +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
> +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
> +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
> +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
> +.\"
> +.Dd $Mdocdate: April 27 2011 $
> +.Dt DFS 4 macppc
> +.Os
> +.Sh NAME
> +.Nm dfs
> +.Nd Dynamic Frequence Switching
> +.Sh SYNOPSIS
> +.Cd "dfs* at macgpio?"
> +.Sh DESCRIPTION
> +The
> +.Nm
> +driver provides support for the Dynamic Frequence Switching
> +feature found on some PowerPC microprocessors.
> +.Pp
> +It conserves power by lowering the processor operating frequency.
> +Depending on the processor model, the processor-to-system bus ratio can
> +be divided by two or four.
> +.Sh HARDWARE
> +Processors supported by the
> +.Nm
> +driver are part of the PowerPC G4 family and are found on various iBook
> +and PowerBook machines:
> +.Bd -literal -offset indent
> +MPC7447A     PowerPC 7447 "Apollo 7"
> +MPC7448              PowerPC 7448 "Apollo 8"
> +.Ed
> +.Sh SEE ALSO
> +.Xr macgpio 4 ,
> +.Xr sysctl 8 ,
> +.Rs
> +.%T MPC7450 RISC Microprocessor Family Reference Manual
> +.Re
> +.Sh HISTORY
> +Support for the
> +.Nm
> +driver first appeared in
> +.Ox 5.0 .

Man page looks ok to me. Changes to GENERIC we usually wait for Theo to
ok as I understand it. The driver itself, as a mac mini owner, I can't
test so I won't comment on other to say that it reads fine to me.

.... Ken

Reply via email to