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>
26 #include <linux/slab.h>
29 #include "nouveau_drv.h"
31 struct nouveau_ctxprog {
36 } __attribute__ ((packed));
38 struct nouveau_ctxvals {
46 } __attribute__ ((packed));
49 nouveau_grctx_prog_load(struct drm_device *dev)
51 struct drm_nouveau_private *dev_priv = dev->dev_private;
52 struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
53 const int chipset = dev_priv->chipset;
54 const struct firmware *fw;
55 const struct nouveau_ctxprog *cp;
56 const struct nouveau_ctxvals *cv;
60 if (pgraph->accel_blocked)
63 if (!pgraph->ctxprog) {
64 sprintf(name, "nouveau/nv%02x.ctxprog", chipset);
65 ret = request_firmware(&fw, name, &dev->pdev->dev);
67 NV_ERROR(dev, "No ctxprog for NV%02x\n", chipset);
71 pgraph->ctxprog = kmalloc(fw->size, GFP_KERNEL);
72 if (!pgraph->ctxprog) {
73 NV_ERROR(dev, "OOM copying ctxprog\n");
77 memcpy(pgraph->ctxprog, fw->data, fw->size);
80 if (le32_to_cpu(cp->signature) != 0x5043564e ||
82 le16_to_cpu(cp->length) != ((fw->size - 7) / 4)) {
83 NV_ERROR(dev, "ctxprog invalid\n");
85 nouveau_grctx_fini(dev);
91 if (!pgraph->ctxvals) {
92 sprintf(name, "nouveau/nv%02x.ctxvals", chipset);
93 ret = request_firmware(&fw, name, &dev->pdev->dev);
95 NV_ERROR(dev, "No ctxvals for NV%02x\n", chipset);
96 nouveau_grctx_fini(dev);
100 pgraph->ctxvals = kmalloc(fw->size, GFP_KERNEL);
101 if (!pgraph->ctxvals) {
102 NV_ERROR(dev, "OOM copying ctxvals\n");
103 release_firmware(fw);
104 nouveau_grctx_fini(dev);
107 memcpy(pgraph->ctxvals, fw->data, fw->size);
109 cv = (void *)pgraph->ctxvals;
110 if (le32_to_cpu(cv->signature) != 0x5643564e ||
112 le32_to_cpu(cv->length) != ((fw->size - 9) / 8)) {
113 NV_ERROR(dev, "ctxvals invalid\n");
114 release_firmware(fw);
115 nouveau_grctx_fini(dev);
118 release_firmware(fw);
121 cp = pgraph->ctxprog;
123 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0);
124 for (i = 0; i < le16_to_cpu(cp->length); i++)
125 nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA,
126 le32_to_cpu(cp->data[i]));
132 nouveau_grctx_fini(struct drm_device *dev)
134 struct drm_nouveau_private *dev_priv = dev->dev_private;
135 struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
137 if (pgraph->ctxprog) {
138 kfree(pgraph->ctxprog);
139 pgraph->ctxprog = NULL;
142 if (pgraph->ctxvals) {
143 kfree(pgraph->ctxprog);
144 pgraph->ctxvals = NULL;
149 nouveau_grctx_vals_load(struct drm_device *dev, struct nouveau_gpuobj *ctx)
151 struct drm_nouveau_private *dev_priv = dev->dev_private;
152 struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
153 struct nouveau_ctxvals *cv = pgraph->ctxvals;
159 for (i = 0; i < le32_to_cpu(cv->length); i++)
160 nv_wo32(dev, ctx, le32_to_cpu(cv->data[i].offset),
161 le32_to_cpu(cv->data[i].value));