Am 21.07.2011 um 19:51 schrieb Scott Wood <scottw...@freescale.com>:
> On Thu, 21 Jul 2011 03:27:25 +0200
> Alexander Graf <ag...@suse.de> wrote:
>
>> +/* Try to find a device tree node for a CPU with clock-frequency property */
>> +static int kvmppc_find_cpu_dt(char *buf, int buf_len)
>> +{
>> + struct dirent *dirp;
>> + DIR *dp;
>> +
>> + if ((dp = opendir(PROC_DEVTREE_CPU)) == NULL) {
>> + printf("Can't open directory " PROC_DEVTREE_CPU "\n");
>> + return -1;
>> + }
>> +
>> + buf[0] = '\0';
>> + while ((dirp = readdir(dp)) != NULL) {
>> + FILE *f;
>> + snprintf(buf, buf_len, "%s%s/clock-frequency", PROC_DEVTREE_CPU,
>> + dirp->d_name);
>> + f = fopen(buf, "r");
>> + if (f) {
>> + snprintf(buf, buf_len, "%scpus/%s", PROC_DEVTREE_CPU,
>> dirp->d_name);
>> + fclose(f);
>> + break;
>> + }
>> + buf[0] = '\0';
>> + }
>> + closedir(dp);
>> + if (buf[0] == '\0') {
>> + printf("Unknown host!\n");
>> + return -1;
>> + }
>
> "Unknown host!" is a little vague for an error message.
>
>> +uint32_t kvmppc_get_clockfreq(void)
>> +{
>> + char buf[512];
>> + uint32_t tb;
>> + FILE *f;
>> + int len;
>> +
>> + if (kvmppc_find_cpu_dt(buf, sizeof(buf))) {
>> + return 0;
>> + }
>> +
>> + snprintf(buf, sizeof(buf), "%s/clock-frequency", buf);
>> +
>> + f = fopen(buf, "rb");
>> + if (!f) {
>> + return -1;
>> + }
>> +
>> + len = fread(&tb, sizeof(tb), 1, f);
>> + if (len != 1) {
>> + goto err;
>> + }
>> +
>> + return tb;
>> +err:
>> + fclose(f);
>> + return 0;
>> +}
>
> Need to convert endian from big to host.
Hm. This is kvm specific code for ppc, so only ever runs on host==big :)
> Also, the frequency can be 64-bit.
Would the parameter just be 2 cells then? Got an example how this works?
Alex
>
> -Scott
>