Subject: Re: Making a common API for cpu frequency drivers
To: None <>
From: Juan RP <>
List: tech-kern
Date: 09/02/2006 19:46:35
On Fri, 1 Sep 2006 09:03:56 +0200
Juan RP <> wrote:

> Hi,
> Cube suggested that the way to go for drivers changing CPU frequency
> (speedstep, powernow, longrun, etc) is to use a new sysmon object.
> Before starting the work, I would like to know what do I need exactly.
> I've come up with the following plan:

I need more help, see the following:

struct sysmon_cpufreq {
        const char *smcf_name;  /* cpufreq device name */
        uint8_t smcf_refcnt;    /* references */

         * callback to a function that will give us the array that
         * will contain the frequencies stored in integer objects.
        prop_array_t (*smcpufreq_gdata)(struct sysmon_cpufreq *);

        /* callback to a function that will give us the current frequency */
        prop_number_t (*smcpufreq_gcurfreq)(struct sysmon_cpufreq *);

        /* callback to a function that will set new frequency */
        int (*smcpufreq_snewfreq)(struct sysmon_cpufreq *);

        LIST_ENTRY(sysmon_cpufreq) smcpufreq_list;

int     sysmonopen_cpufreq(dev_t, int, int, struct lwp *);
int     sysmonclose_cpufreq(dev_t, int, int, struct lwp *);
int     sysmonioctl_cpufreq(dev_t, u_long, caddr_t, int, struct lwp *);

int     sysmon_cpufreq_register(struct sysmon_cpufreq *);
void    sysmon_cpufreq_unregister(struct sysmon_cpufreq *);


And I think that adding just one ioctl (I named SMCPUFREQ_GDICT) is
enough because it will return a dictionary (which has the key of the
array and the array with the integers returned by the function callbacks).

The ioctl SMCPUFREQ_GDICT in sysmon_cpufreq.c will return to
userland the dictionary via prop_dictionary_copyout_ioctl().

Now I'm not sure if the function callback to get the current frequency:

prop_number_t (*smcpufreq_gcurfreq)(struct sysmon_cpufreq *);

needs to return prop_number_t or just an unsigned int and convert to
a prop_number_t in sysmon_cpufreq.

What do you think about this? do you have any suggestion?