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 static const char sysfs_base_path[] = "/sys/class/drm/card%d/gt_%s_freq_mhz";
54 { "cur", "r", NULL }, { "min", "rb+", NULL }, { "max", "rb+", NULL }, { "RP0", "r", NULL }, { "RP1", "r", NULL }, { "RPn", "r", NULL }, { NULL, NULL, NULL }
57 static int readval(FILE *filp)
63 scanned = fscanf(filp, "%d", &val);
64 igt_assert(scanned == 1);
69 static int do_writeval(FILE *filp, int val, int lerrno)
75 ret = fprintf(filp, "%d", val);
78 /* Expecting specific error */
79 igt_assert(ret == EOF && errno == lerrno);
80 igt_assert(readval(filp) == orig);
82 /* Expecting no error */
83 igt_assert(ret != EOF);
84 igt_assert(readval(filp) == val);
89 #define writeval(filp, val) do_writeval(filp, val, 0)
90 #define writeval_inval(filp, val) do_writeval(filp, val, EINVAL)
92 #define fcur (readval(stuff[CUR].filp))
93 #define fmin (readval(stuff[MIN].filp))
94 #define fmax (readval(stuff[MAX].filp))
95 #define frp0 (readval(stuff[RP0].filp))
96 #define frp1 (readval(stuff[RP1].filp))
97 #define frpn (readval(stuff[RPn].filp))
99 static void setfreq(int val)
102 writeval(stuff[MAX].filp, val);
103 writeval(stuff[MIN].filp, val);
105 writeval(stuff[MIN].filp, val);
106 writeval(stuff[MAX].filp, val);
110 static void checkit(void)
112 igt_assert(fmin <= fmax);
113 igt_assert(fcur <= fmax);
114 igt_assert(fmin <= fcur);
115 igt_assert(frpn <= fmin);
116 igt_assert(fmax <= frp0);
117 igt_assert(frp1 <= frp0);
118 igt_assert(frpn <= frp1);
119 igt_assert(frp0 != 0);
120 igt_assert(frp1 != 0);
123 static void dumpit(void)
125 struct junk *junk = stuff;
127 printf("gt frequency %s (MHz): %d\n", junk->name, readval(junk->filp));
129 } while(junk->name != NULL);
134 static void pm_rps_exit_handler(int sig)
136 if (origmin > fmax) {
137 writeval(stuff[MAX].filp, origmax);
138 writeval(stuff[MIN].filp, origmin);
140 writeval(stuff[MIN].filp, origmin);
141 writeval(stuff[MAX].filp, origmax);
147 igt_skip_on_simulation();
150 const int device = drm_get_card();
151 struct junk *junk = stuff;
154 /* Use drm_open_any to verify device existence */
161 ret = asprintf(&path, sysfs_base_path, device, junk->name);
162 igt_assert(ret != -1);
163 junk->filp = fopen(path, junk->mode);
164 igt_require(junk->filp);
165 setbuf(junk->filp, NULL);
167 val = readval(junk->filp);
168 igt_assert(val >= 0);
170 } while(junk->name != NULL);
175 igt_install_exit_handler(pm_rps_exit_handler);
178 igt_subtest("min-max-config-at-idle") {
180 printf("Original min = %d\nOriginal max = %d\n",
190 igt_assert(fcur == fmin);
194 igt_assert(fcur == fmax);
197 /* And some errors */
198 writeval_inval(stuff[MIN].filp, frpn - 1);
199 writeval_inval(stuff[MAX].filp, frp0 + 1000);
202 writeval_inval(stuff[MIN].filp, fmax + 1000);
203 writeval_inval(stuff[MAX].filp, fmin - 1);
206 writeval_inval(stuff[MIN].filp, 0x11111110);
207 writeval_inval(stuff[MAX].filp, 0);
209 writeval(stuff[MIN].filp, origmin);
210 writeval(stuff[MAX].filp, origmax);