diff options
author | Ben Skeggs <bskeggs@redhat.com> | 2009-12-15 07:02:47 -0500 |
---|---|---|
committer | Ben Skeggs <bskeggs@redhat.com> | 2009-12-16 02:05:39 -0500 |
commit | 054b93e444550a72aef17115363cdef253b9ee7c (patch) | |
tree | 667d10b686c62d64e0b998115209c65884bcc6de /drivers/gpu/drm/nouveau/nouveau_grctx.c | |
parent | 15bee69ee1532a29e13124b298027ee6ef54bac8 (diff) |
drm/nv40: implement ctxprog/state generation
The context programs are *very* simple compared to the ones used by
the binary driver. There's notes in nv40_grctx.c explaining most of
the things we don't implement. If we discover if/why any of it is
required further down the track, we'll handle it then.
The PGRAPH state generated for each chipset should match what NVIDIA
do almost exactly (there's a couple of exceptions). If someone has
a lot of time on their hands, they could figure out the mapping of
object/method to PGRAPH register and demagic the initial state a little,
it's not terribly important however.
At time of commit, confirmed to be working at least well enough for
accelerated X (and where tested, for 3D apps) on NV40, NV43, NV44, NV46,
NV49, NV4A, NV4B and NV4E.
A module option has been added to force the use of external firmware
blobs if it becomes required.
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/nouveau/nouveau_grctx.c')
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_grctx.c | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/drivers/gpu/drm/nouveau/nouveau_grctx.c b/drivers/gpu/drm/nouveau/nouveau_grctx.c new file mode 100644 index 000000000000..d5d84c87f757 --- /dev/null +++ b/drivers/gpu/drm/nouveau/nouveau_grctx.c | |||
@@ -0,0 +1,158 @@ | |||
1 | /* | ||
2 | * Copyright 2009 Red Hat Inc. | ||
3 | * | ||
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: | ||
10 | * | ||
11 | * The above copyright notice and this permission notice shall be included in | ||
12 | * all copies or substantial portions of the Software. | ||
13 | * | ||
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. | ||
21 | * | ||
22 | * Authors: Ben Skeggs | ||
23 | */ | ||
24 | |||
25 | #include <linux/firmware.h> | ||
26 | |||
27 | #include "drmP.h" | ||
28 | #include "nouveau_drv.h" | ||
29 | |||
30 | struct nouveau_ctxprog { | ||
31 | uint32_t signature; | ||
32 | uint8_t version; | ||
33 | uint16_t length; | ||
34 | uint32_t data[]; | ||
35 | } __attribute__ ((packed)); | ||
36 | |||
37 | struct nouveau_ctxvals { | ||
38 | uint32_t signature; | ||
39 | uint8_t version; | ||
40 | uint32_t length; | ||
41 | struct { | ||
42 | uint32_t offset; | ||
43 | uint32_t value; | ||
44 | } data[]; | ||
45 | } __attribute__ ((packed)); | ||
46 | |||
47 | int | ||
48 | nouveau_grctx_prog_load(struct drm_device *dev) | ||
49 | { | ||
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; | ||
56 | char name[32]; | ||
57 | int ret, i; | ||
58 | |||
59 | if (!pgraph->ctxprog) { | ||
60 | sprintf(name, "nouveau/nv%02x.ctxprog", chipset); | ||
61 | ret = request_firmware(&fw, name, &dev->pdev->dev); | ||
62 | if (ret) { | ||
63 | NV_ERROR(dev, "No ctxprog for NV%02x\n", chipset); | ||
64 | return ret; | ||
65 | } | ||
66 | |||
67 | pgraph->ctxprog = kmalloc(fw->size, GFP_KERNEL); | ||
68 | if (!pgraph->ctxprog) { | ||
69 | NV_ERROR(dev, "OOM copying ctxprog\n"); | ||
70 | release_firmware(fw); | ||
71 | return -ENOMEM; | ||
72 | } | ||
73 | memcpy(pgraph->ctxprog, fw->data, fw->size); | ||
74 | |||
75 | cp = pgraph->ctxprog; | ||
76 | if (le32_to_cpu(cp->signature) != 0x5043564e || | ||
77 | cp->version != 0 || | ||
78 | le16_to_cpu(cp->length) != ((fw->size - 7) / 4)) { | ||
79 | NV_ERROR(dev, "ctxprog invalid\n"); | ||
80 | release_firmware(fw); | ||
81 | nouveau_grctx_fini(dev); | ||
82 | return -EINVAL; | ||
83 | } | ||
84 | release_firmware(fw); | ||
85 | } | ||
86 | |||
87 | if (!pgraph->ctxvals) { | ||
88 | sprintf(name, "nouveau/nv%02x.ctxvals", chipset); | ||
89 | ret = request_firmware(&fw, name, &dev->pdev->dev); | ||
90 | if (ret) { | ||
91 | NV_ERROR(dev, "No ctxvals for NV%02x\n", chipset); | ||
92 | nouveau_grctx_fini(dev); | ||
93 | return ret; | ||
94 | } | ||
95 | |||
96 | pgraph->ctxvals = kmalloc(fw->size, GFP_KERNEL); | ||
97 | if (!pgraph->ctxprog) { | ||
98 | NV_ERROR(dev, "OOM copying ctxprog\n"); | ||
99 | release_firmware(fw); | ||
100 | nouveau_grctx_fini(dev); | ||
101 | return -ENOMEM; | ||
102 | } | ||
103 | memcpy(pgraph->ctxvals, fw->data, fw->size); | ||
104 | |||
105 | cv = (void *)pgraph->ctxvals; | ||
106 | if (le32_to_cpu(cv->signature) != 0x5643564e || | ||
107 | cv->version != 0 || | ||
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); | ||
112 | return -EINVAL; | ||
113 | } | ||
114 | release_firmware(fw); | ||
115 | } | ||
116 | |||
117 | cp = pgraph->ctxprog; | ||
118 | |||
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])); | ||
123 | |||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | void | ||
128 | nouveau_grctx_fini(struct drm_device *dev) | ||
129 | { | ||
130 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
131 | struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph; | ||
132 | |||
133 | if (pgraph->ctxprog) { | ||
134 | kfree(pgraph->ctxprog); | ||
135 | pgraph->ctxprog = NULL; | ||
136 | } | ||
137 | |||
138 | if (pgraph->ctxvals) { | ||
139 | kfree(pgraph->ctxprog); | ||
140 | pgraph->ctxvals = NULL; | ||
141 | } | ||
142 | } | ||
143 | |||
144 | void | ||
145 | nouveau_grctx_vals_load(struct drm_device *dev, struct nouveau_gpuobj *ctx) | ||
146 | { | ||
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; | ||
150 | int i; | ||
151 | |||
152 | if (!cv) | ||
153 | return; | ||
154 | |||
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)); | ||
158 | } | ||