2 * Copyright 2009 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.
25 #include <linux/firmware.h>
28 #include "nouveau_drv.h"
30 struct nouveau_ctxprog {
35 } __attribute__ ((packed));
37 struct nouveau_ctxvals {
45 } __attribute__ ((packed));
48 nouveau_grctx_prog_load(struct drm_device *dev)
50 struct drm_nouveau_private *dev_priv = dev->dev_private;
51 struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
52 const int chipset = dev_priv->chipset;
53 const struct firmware *fw;
54 const struct nouveau_ctxprog *cp;
55 const struct nouveau_ctxvals *cv;
59 if (!pgraph->ctxprog) {
60 sprintf(name, "nouveau/nv%02x.ctxprog", chipset);
61 ret = request_firmware(&fw, name, &dev->pdev->dev);
63 NV_ERROR(dev, "No ctxprog for NV%02x\n", chipset);
67 pgraph->ctxprog = kmalloc(fw->size, GFP_KERNEL);
68 if (!pgraph->ctxprog) {
69 NV_ERROR(dev, "OOM copying ctxprog\n");
73 memcpy(pgraph->ctxprog, fw->data, fw->size);
76 if (le32_to_cpu(cp->signature) != 0x5043564e ||
78 le16_to_cpu(cp->length) != ((fw->size - 7) / 4)) {
79 NV_ERROR(dev, "ctxprog invalid\n");
81 nouveau_grctx_fini(dev);
87 if (!pgraph->ctxvals) {
88 sprintf(name, "nouveau/nv%02x.ctxvals", chipset);
89 ret = request_firmware(&fw, name, &dev->pdev->dev);
91 NV_ERROR(dev, "No ctxvals for NV%02x\n", chipset);
92 nouveau_grctx_fini(dev);
96 pgraph->ctxvals = kmalloc(fw->size, GFP_KERNEL);
97 if (!pgraph->ctxprog) {
98 NV_ERROR(dev, "OOM copying ctxprog\n");
100 nouveau_grctx_fini(dev);
103 memcpy(pgraph->ctxvals, fw->data, fw->size);
105 cv = (void *)pgraph->ctxvals;
106 if (le32_to_cpu(cv->signature) != 0x5643564e ||
108 le32_to_cpu(cv->length) != ((fw->size - 9) / 8)) {
109 NV_ERROR(dev, "ctxvals invalid\n");
110 release_firmware(fw);
111 nouveau_grctx_fini(dev);
114 release_firmware(fw);
117 cp = pgraph->ctxprog;
119 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0);
120 for (i = 0; i < le16_to_cpu(cp->length); i++)
121 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA,
122 le32_to_cpu(cp->data[i]));
128 nouveau_grctx_fini(struct drm_device *dev)
130 struct drm_nouveau_private *dev_priv = dev->dev_private;
131 struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
133 if (pgraph->ctxprog) {
134 kfree(pgraph->ctxprog);
135 pgraph->ctxprog = NULL;
138 if (pgraph->ctxvals) {
139 kfree(pgraph->ctxprog);
140 pgraph->ctxvals = NULL;
145 nouveau_grctx_vals_load(struct drm_device *dev, struct nouveau_gpuobj *ctx)
147 struct drm_nouveau_private *dev_priv = dev->dev_private;
148 struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
149 struct nouveau_ctxvals *cv = pgraph->ctxvals;
155 for (i = 0; i < le32_to_cpu(cv->length); i++)
156 nv_wo32(dev, ctx, le32_to_cpu(cv->data[i].offset),
157 le32_to_cpu(cv->data[i].value));