static int my_cmd_demo(int argc, char **argv) { char *usage[] = { "set load demo (1 | 2 | 3)", "get print current demo configuration", 0 }; if (check_cmd(argc, "demo", usage)) // check for existing arguments return -1; if (strcmp("get", argv[0]) == 0) { if (check_argc(argc, 1, 1, "")) // check # of arguments return -1; // get demo configuration xil_printf("demo configuration %d\n", get_demo()); } else if (strcmp("set", argv[0]) == 0) { if (check_argc(argc, 2, 2, "demo set ID")) // check # of args: 2 required return -1; // set demo configuration unsigned long val = wsh_extract_val(argv[1]); // extract numeric value if ((val < 1) || (val > 3)) { print_unknown_arg(argv[1]); return -1; } set_demo(val); xil_printf("selecting demo %d\n", get_demo()); } else { print_unknown_cmd(argv[0]); return -1; } return 0; }
int cmd_freq_set(int argc, char **argv) { extern char *optarg; extern int optind, opterr, optopt; int ret = 0, cont = 1; int double_parm = 0, related = 0, policychange = 0; unsigned long freq = 0; char gov[20]; unsigned int cpu; struct cpufreq_policy new_pol = { .min = 0, .max = 0, .governor = NULL, }; /* parameter parsing */ do { ret = getopt_long(argc, argv, "d:u:g:f:hr", set_opts, NULL); switch (ret) { case '?': print_unknown_arg(); return -EINVAL; case 'h': freq_set_help(); return 0; case -1: cont = 0; break; case 'r': if (related) double_parm++; related++; break; case 'd': if (new_pol.min) double_parm++; policychange++; new_pol.min = string_to_frequency(optarg); if (new_pol.min == 0) { print_unknown_arg(); return -EINVAL; } break; case 'u': if (new_pol.max) double_parm++; policychange++; new_pol.max = string_to_frequency(optarg); if (new_pol.max == 0) { print_unknown_arg(); return -EINVAL; } break; case 'f': if (freq) double_parm++; freq = string_to_frequency(optarg); if (freq == 0) { print_unknown_arg(); return -EINVAL; } break; case 'g': if (new_pol.governor) double_parm++; policychange++; if ((strlen(optarg) < 3) || (strlen(optarg) > 18)) { print_unknown_arg(); return -EINVAL; } if ((sscanf(optarg, "%s", gov)) != 1) { print_unknown_arg(); return -EINVAL; } new_pol.governor = gov; break; } } while (cont); /* parameter checking */ if (double_parm) { printf("the same parameter was passed more than once\n"); return -EINVAL; } if (freq && policychange) { printf(_("the -f/--freq parameter cannot be combined with -d/--min, -u/--max or\n" "-g/--governor parameters\n")); return -EINVAL; } if (!freq && !policychange) { printf(_("At least one parameter out of -f/--freq, -d/--min, -u/--max, and\n" "-g/--governor must be passed\n")); return -EINVAL; } /* Default is: set all CPUs */ if (bitmask_isallclear(cpus_chosen)) bitmask_setall(cpus_chosen); /* Also set frequency settings for related CPUs if -r is passed */ if (related) { for (cpu = bitmask_first(cpus_chosen); cpu <= bitmask_last(cpus_chosen); cpu++) { struct cpufreq_affected_cpus *cpus; if (!bitmask_isbitset(cpus_chosen, cpu) || cpufreq_cpu_exists(cpu)) continue; cpus = cpufreq_get_related_cpus(cpu); if (!cpus) break; while (cpus->next) { bitmask_setbit(cpus_chosen, cpus->cpu); cpus = cpus->next; } cpufreq_put_related_cpus(cpus); } } /* loop over CPUs */ for (cpu = bitmask_first(cpus_chosen); cpu <= bitmask_last(cpus_chosen); cpu++) { if (!bitmask_isbitset(cpus_chosen, cpu) || cpufreq_cpu_exists(cpu)) continue; printf(_("Setting cpu: %d\n"), cpu); ret = do_one_cpu(cpu, &new_pol, freq, policychange); if (ret) break; } if (ret) print_error(); return ret; }