2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Ben Widawsky <ben@bwidawsk.net>
25 * Jeff McGee <jeff.mcgee@intel.com>
36 static bool verbose = false;
37 static int origmin, origmax;
39 #define restore_assert(COND) do { \
41 writeval(stuff[MIN].filp, origmin); \
42 writeval(stuff[MAX].filp, origmax); \
47 static const char sysfs_base_path[] = "/sys/class/drm/card%d/gt_%s_freq_mhz";
62 { "cur", "r", NULL }, { "min", "rb+", NULL }, { "max", "rb+", NULL }, { "RP0", "r", NULL }, { "RP1", "r", NULL }, { "RPn", "r", NULL }, { NULL, NULL, NULL }
65 static int readval(FILE *filp)
71 scanned = fscanf(filp, "%d", &val);
72 igt_assert(scanned == 1);
77 static int do_writeval(FILE *filp, int val, int lerrno)
81 ret = fprintf(filp, "%d", val);
83 igt_assert(errno = lerrno);
86 #define writeval(filp, val) do_writeval(filp, val, 0)
88 #define fcur (readval(stuff[CUR].filp))
89 #define fmin (readval(stuff[MIN].filp))
90 #define fmax (readval(stuff[MAX].filp))
91 #define frp0 (readval(stuff[RP0].filp))
92 #define frp1 (readval(stuff[RP1].filp))
93 #define frpn (readval(stuff[RPn].filp))
95 static void setfreq(int val)
97 writeval(stuff[MIN].filp, val);
98 writeval(stuff[MAX].filp, val);
101 static void checkit(void)
103 restore_assert(fmin <= fmax);
104 restore_assert(fcur <= fmax);
105 restore_assert(fmin <= fcur);
106 restore_assert(frpn <= fmin);
107 restore_assert(fmax <= frp0);
108 restore_assert(frp1 <= frp0);
109 restore_assert(frpn <= frp1);
110 restore_assert(frp0 != 0);
111 restore_assert(frp1 != 0);
114 static void dumpit(void)
116 struct junk *junk = stuff;
118 printf("gt frequency %s (MHz): %d\n", junk->name, readval(junk->filp));
120 } while(junk->name != NULL);
128 const int device = drm_get_card();
129 struct junk *junk = stuff;
132 igt_skip_on_simulation();
134 /* Use drm_open_any to verify device existence */
141 ret = asprintf(&path, sysfs_base_path, device, junk->name);
142 igt_assert(ret != -1);
143 junk->filp = fopen(path, junk->mode);
144 igt_require(junk->filp);
145 setbuf(junk->filp, NULL);
147 val = readval(junk->filp);
148 igt_assert(val >= 0);
150 } while(junk->name != NULL);
156 printf("Original min = %d\nOriginal max = %d\n", origmin, origmax);
165 restore_assert(fcur == fmin);
169 restore_assert(fcur == fmax);
172 /* And some errors */
173 writeval(stuff[MIN].filp, frpn - 1);
174 writeval(stuff[MAX].filp, frp0 + 1000);
177 writeval(stuff[MIN].filp, fmax + 1000);
178 writeval(stuff[MAX].filp, fmin - 1);
181 do_writeval(stuff[MIN].filp, 0x11111110, EINVAL);
182 do_writeval(stuff[MAX].filp, 0, EINVAL);
184 writeval(stuff[MIN].filp, origmin);
185 writeval(stuff[MAX].filp, origmax);