2 * Copyright 2013 Red Hat Inc.
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 shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
22 * Authors: Ben Skeggs <bskeggs@redhat.com>
25 #include <core/client.h>
26 #include <core/object.h>
27 #include <nvif/unpack.h>
28 #include <nvif/class.h>
29 #include <nvif/ioctl.h>
31 #include <subdev/clock.h>
36 nouveau_control_mthd_pstate_info(struct nouveau_object *object,
40 struct nvif_control_pstate_info_v0 v0;
42 struct nouveau_clock *clk = nouveau_clock(object);
45 nv_ioctl(object, "control pstate info size %d\n", size);
46 if (nvif_unpack(args->v0, 0, 0, false)) {
47 nv_ioctl(object, "control pstate info vers %d\n",
53 args->v0.count = clk->state_nr;
54 args->v0.ustate_ac = clk->ustate_ac;
55 args->v0.ustate_dc = clk->ustate_dc;
56 args->v0.pwrsrc = clk->pwrsrc;
57 args->v0.pstate = clk->pstate;
60 args->v0.ustate_ac = NVIF_CONTROL_PSTATE_INFO_V0_USTATE_DISABLE;
61 args->v0.ustate_dc = NVIF_CONTROL_PSTATE_INFO_V0_USTATE_DISABLE;
62 args->v0.pwrsrc = -ENOSYS;
63 args->v0.pstate = NVIF_CONTROL_PSTATE_INFO_V0_PSTATE_UNKNOWN;
70 nouveau_control_mthd_pstate_attr(struct nouveau_object *object,
74 struct nvif_control_pstate_attr_v0 v0;
76 struct nouveau_clock *clk = nouveau_clock(object);
77 struct nouveau_clocks *domain;
78 struct nouveau_pstate *pstate;
79 struct nouveau_cstate *cstate;
84 nv_ioctl(object, "control pstate attr size %d\n", size);
85 if (nvif_unpack(args->v0, 0, 0, false)) {
86 nv_ioctl(object, "control pstate attr vers %d state %d "
88 args->v0.version, args->v0.state, args->v0.index);
91 if (args->v0.state < NVIF_CONTROL_PSTATE_ATTR_V0_STATE_CURRENT)
93 if (args->v0.state >= clk->state_nr)
97 domain = clk->domains;
99 while (domain->name != nv_clk_src_max) {
100 if (domain->mname && ++j == args->v0.index)
105 if (domain->name == nv_clk_src_max)
108 if (args->v0.state != NVIF_CONTROL_PSTATE_ATTR_V0_STATE_CURRENT) {
109 list_for_each_entry(pstate, &clk->states, head) {
110 if (i++ == args->v0.state)
114 lo = pstate->base.domain[domain->name];
116 list_for_each_entry(cstate, &pstate->list, head) {
117 lo = min(lo, cstate->domain[domain->name]);
118 hi = max(hi, cstate->domain[domain->name]);
121 args->v0.state = pstate->pstate;
123 lo = max(clk->read(clk, domain->name), 0);
127 snprintf(args->v0.name, sizeof(args->v0.name), "%s", domain->mname);
128 snprintf(args->v0.unit, sizeof(args->v0.unit), "MHz");
129 args->v0.min = lo / domain->mdiv;
130 args->v0.max = hi / domain->mdiv;
133 while ((++domain)->name != nv_clk_src_max) {
135 args->v0.index = ++j;
144 nouveau_control_mthd_pstate_user(struct nouveau_object *object,
145 void *data, u32 size)
148 struct nvif_control_pstate_user_v0 v0;
150 struct nouveau_clock *clk = nouveau_clock(object);
153 nv_ioctl(object, "control pstate user size %d\n", size);
154 if (nvif_unpack(args->v0, 0, 0, false)) {
155 nv_ioctl(object, "control pstate user vers %d ustate %d "
156 "pwrsrc %d\n", args->v0.version,
157 args->v0.ustate, args->v0.pwrsrc);
163 if (args->v0.pwrsrc >= 0) {
164 ret |= nouveau_clock_ustate(clk, args->v0.ustate, args->v0.pwrsrc);
166 ret |= nouveau_clock_ustate(clk, args->v0.ustate, 0);
167 ret |= nouveau_clock_ustate(clk, args->v0.ustate, 1);
174 nouveau_control_mthd(struct nouveau_object *object, u32 mthd,
175 void *data, u32 size)
178 case NVIF_CONTROL_PSTATE_INFO:
179 return nouveau_control_mthd_pstate_info(object, data, size);
180 case NVIF_CONTROL_PSTATE_ATTR:
181 return nouveau_control_mthd_pstate_attr(object, data, size);
182 case NVIF_CONTROL_PSTATE_USER:
183 return nouveau_control_mthd_pstate_user(object, data, size);
190 static struct nouveau_ofuncs
191 nouveau_control_ofuncs = {
192 .ctor = _nouveau_object_ctor,
193 .dtor = nouveau_object_destroy,
194 .init = nouveau_object_init,
195 .fini = nouveau_object_fini,
196 .mthd = nouveau_control_mthd,
199 struct nouveau_oclass
200 nouveau_control_oclass[] = {
201 { .handle = NVIF_IOCTL_NEW_V0_CONTROL,
202 .ofuncs = &nouveau_control_ofuncs