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 | |
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')
-rw-r--r-- | drivers/gpu/drm/nouveau/Makefile | 5 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_drv.c | 4 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_drv.h | 13 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_grctx.c | 158 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nouveau_grctx.h | 133 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nv40_graph.c | 212 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nv40_grctx.c | 678 | ||||
-rw-r--r-- | drivers/gpu/drm/nouveau/nv50_graph.c | 10 |
8 files changed, 1031 insertions, 182 deletions
diff --git a/drivers/gpu/drm/nouveau/Makefile b/drivers/gpu/drm/nouveau/Makefile index 1d90d4d0144f..48c290b5da8c 100644 --- a/drivers/gpu/drm/nouveau/Makefile +++ b/drivers/gpu/drm/nouveau/Makefile | |||
@@ -8,14 +8,15 @@ nouveau-y := nouveau_drv.o nouveau_state.o nouveau_channel.o nouveau_mem.o \ | |||
8 | nouveau_sgdma.o nouveau_dma.o \ | 8 | nouveau_sgdma.o nouveau_dma.o \ |
9 | nouveau_bo.o nouveau_fence.o nouveau_gem.o nouveau_ttm.o \ | 9 | nouveau_bo.o nouveau_fence.o nouveau_gem.o nouveau_ttm.o \ |
10 | nouveau_hw.o nouveau_calc.o nouveau_bios.o nouveau_i2c.o \ | 10 | nouveau_hw.o nouveau_calc.o nouveau_bios.o nouveau_i2c.o \ |
11 | nouveau_display.o nouveau_connector.o nouveau_fbcon.o \ | 11 | nouveau_display.o nouveau_connector.o nouveau_fbcon.o \ |
12 | nouveau_dp.o \ | 12 | nouveau_dp.o nouveau_grctx.o \ |
13 | nv04_timer.o \ | 13 | nv04_timer.o \ |
14 | nv04_mc.o nv40_mc.o nv50_mc.o \ | 14 | nv04_mc.o nv40_mc.o nv50_mc.o \ |
15 | nv04_fb.o nv10_fb.o nv40_fb.o \ | 15 | nv04_fb.o nv10_fb.o nv40_fb.o \ |
16 | nv04_fifo.o nv10_fifo.o nv40_fifo.o nv50_fifo.o \ | 16 | nv04_fifo.o nv10_fifo.o nv40_fifo.o nv50_fifo.o \ |
17 | nv04_graph.o nv10_graph.o nv20_graph.o \ | 17 | nv04_graph.o nv10_graph.o nv20_graph.o \ |
18 | nv40_graph.o nv50_graph.o \ | 18 | nv40_graph.o nv50_graph.o \ |
19 | nv40_grctx.o \ | ||
19 | nv04_instmem.o nv50_instmem.o \ | 20 | nv04_instmem.o nv50_instmem.o \ |
20 | nv50_crtc.o nv50_dac.o nv50_sor.o \ | 21 | nv50_crtc.o nv50_dac.o nv50_sor.o \ |
21 | nv50_cursor.o nv50_display.o nv50_fbcon.o \ | 22 | nv50_cursor.o nv50_display.o nv50_fbcon.o \ |
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.c b/drivers/gpu/drm/nouveau/nouveau_drv.c index 35249c35118f..78662cc1c8d5 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drv.c +++ b/drivers/gpu/drm/nouveau/nouveau_drv.c | |||
@@ -35,6 +35,10 @@ | |||
35 | 35 | ||
36 | #include "drm_pciids.h" | 36 | #include "drm_pciids.h" |
37 | 37 | ||
38 | MODULE_PARM_DESC(ctxfw, "Use external firmware blob for grctx init (NV40)"); | ||
39 | int nouveau_ctxfw = 0; | ||
40 | module_param_named(ctxfw, nouveau_ctxfw, int, 0400); | ||
41 | |||
38 | MODULE_PARM_DESC(noagp, "Disable AGP"); | 42 | MODULE_PARM_DESC(noagp, "Disable AGP"); |
39 | int nouveau_noagp; | 43 | int nouveau_noagp; |
40 | module_param_named(noagp, nouveau_noagp, int, 0400); | 44 | module_param_named(noagp, nouveau_noagp, int, 0400); |
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h index bc6ffa5eeac7..5f8cbb79c499 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h | |||
@@ -54,6 +54,7 @@ struct nouveau_fpriv { | |||
54 | #include "nouveau_drm.h" | 54 | #include "nouveau_drm.h" |
55 | #include "nouveau_reg.h" | 55 | #include "nouveau_reg.h" |
56 | #include "nouveau_bios.h" | 56 | #include "nouveau_bios.h" |
57 | struct nouveau_grctx; | ||
57 | 58 | ||
58 | #define MAX_NUM_DCB_ENTRIES 16 | 59 | #define MAX_NUM_DCB_ENTRIES 16 |
59 | 60 | ||
@@ -317,6 +318,7 @@ struct nouveau_pgraph_engine { | |||
317 | bool accel_blocked; | 318 | bool accel_blocked; |
318 | void *ctxprog; | 319 | void *ctxprog; |
319 | void *ctxvals; | 320 | void *ctxvals; |
321 | int grctx_size; | ||
320 | 322 | ||
321 | int (*init)(struct drm_device *); | 323 | int (*init)(struct drm_device *); |
322 | void (*takedown)(struct drm_device *); | 324 | void (*takedown)(struct drm_device *); |
@@ -647,6 +649,7 @@ extern int nouveau_fbpercrtc; | |||
647 | extern char *nouveau_tv_norm; | 649 | extern char *nouveau_tv_norm; |
648 | extern int nouveau_reg_debug; | 650 | extern int nouveau_reg_debug; |
649 | extern char *nouveau_vbios; | 651 | extern char *nouveau_vbios; |
652 | extern int nouveau_ctxfw; | ||
650 | 653 | ||
651 | /* nouveau_state.c */ | 654 | /* nouveau_state.c */ |
652 | extern void nouveau_preclose(struct drm_device *dev, struct drm_file *); | 655 | extern void nouveau_preclose(struct drm_device *dev, struct drm_file *); |
@@ -959,9 +962,7 @@ extern int nv40_graph_create_context(struct nouveau_channel *); | |||
959 | extern void nv40_graph_destroy_context(struct nouveau_channel *); | 962 | extern void nv40_graph_destroy_context(struct nouveau_channel *); |
960 | extern int nv40_graph_load_context(struct nouveau_channel *); | 963 | extern int nv40_graph_load_context(struct nouveau_channel *); |
961 | extern int nv40_graph_unload_context(struct drm_device *); | 964 | extern int nv40_graph_unload_context(struct drm_device *); |
962 | extern int nv40_grctx_init(struct drm_device *); | 965 | extern void nv40_grctx_init(struct nouveau_grctx *); |
963 | extern void nv40_grctx_fini(struct drm_device *); | ||
964 | extern void nv40_grctx_vals_load(struct drm_device *, struct nouveau_gpuobj *); | ||
965 | 966 | ||
966 | /* nv50_graph.c */ | 967 | /* nv50_graph.c */ |
967 | extern struct nouveau_pgraph_object_class nv50_graph_grclass[]; | 968 | extern struct nouveau_pgraph_object_class nv50_graph_grclass[]; |
@@ -975,6 +976,12 @@ extern int nv50_graph_load_context(struct nouveau_channel *); | |||
975 | extern int nv50_graph_unload_context(struct drm_device *); | 976 | extern int nv50_graph_unload_context(struct drm_device *); |
976 | extern void nv50_graph_context_switch(struct drm_device *); | 977 | extern void nv50_graph_context_switch(struct drm_device *); |
977 | 978 | ||
979 | /* nouveau_grctx.c */ | ||
980 | extern int nouveau_grctx_prog_load(struct drm_device *); | ||
981 | extern void nouveau_grctx_vals_load(struct drm_device *, | ||
982 | struct nouveau_gpuobj *); | ||
983 | extern void nouveau_grctx_fini(struct drm_device *); | ||
984 | |||
978 | /* nv04_instmem.c */ | 985 | /* nv04_instmem.c */ |
979 | extern int nv04_instmem_init(struct drm_device *); | 986 | extern int nv04_instmem_init(struct drm_device *); |
980 | extern void nv04_instmem_takedown(struct drm_device *); | 987 | extern void nv04_instmem_takedown(struct drm_device *); |
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 | } | ||
diff --git a/drivers/gpu/drm/nouveau/nouveau_grctx.h b/drivers/gpu/drm/nouveau/nouveau_grctx.h new file mode 100644 index 000000000000..5d39c4ce8006 --- /dev/null +++ b/drivers/gpu/drm/nouveau/nouveau_grctx.h | |||
@@ -0,0 +1,133 @@ | |||
1 | #ifndef __NOUVEAU_GRCTX_H__ | ||
2 | #define __NOUVEAU_GRCTX_H__ | ||
3 | |||
4 | struct nouveau_grctx { | ||
5 | struct drm_device *dev; | ||
6 | |||
7 | enum { | ||
8 | NOUVEAU_GRCTX_PROG, | ||
9 | NOUVEAU_GRCTX_VALS | ||
10 | } mode; | ||
11 | void *data; | ||
12 | |||
13 | uint32_t ctxprog_max; | ||
14 | uint32_t ctxprog_len; | ||
15 | uint32_t ctxprog_reg; | ||
16 | int ctxprog_label[32]; | ||
17 | uint32_t ctxvals_pos; | ||
18 | uint32_t ctxvals_base; | ||
19 | }; | ||
20 | |||
21 | #ifdef CP_CTX | ||
22 | static inline void | ||
23 | cp_out(struct nouveau_grctx *ctx, uint32_t inst) | ||
24 | { | ||
25 | uint32_t *ctxprog = ctx->data; | ||
26 | |||
27 | if (ctx->mode != NOUVEAU_GRCTX_PROG) | ||
28 | return; | ||
29 | |||
30 | BUG_ON(ctx->ctxprog_len == ctx->ctxprog_max); | ||
31 | ctxprog[ctx->ctxprog_len++] = inst; | ||
32 | } | ||
33 | |||
34 | static inline void | ||
35 | cp_lsr(struct nouveau_grctx *ctx, uint32_t val) | ||
36 | { | ||
37 | cp_out(ctx, CP_LOAD_SR | val); | ||
38 | } | ||
39 | |||
40 | static inline void | ||
41 | cp_ctx(struct nouveau_grctx *ctx, uint32_t reg, uint32_t length) | ||
42 | { | ||
43 | ctx->ctxprog_reg = (reg - 0x00400000) >> 2; | ||
44 | |||
45 | ctx->ctxvals_base = ctx->ctxvals_pos; | ||
46 | ctx->ctxvals_pos = ctx->ctxvals_base + length; | ||
47 | |||
48 | if (length > (CP_CTX_COUNT >> CP_CTX_COUNT_SHIFT)) { | ||
49 | cp_lsr(ctx, length); | ||
50 | length = 0; | ||
51 | } | ||
52 | |||
53 | cp_out(ctx, CP_CTX | (length << CP_CTX_COUNT_SHIFT) | ctx->ctxprog_reg); | ||
54 | } | ||
55 | |||
56 | static inline void | ||
57 | cp_name(struct nouveau_grctx *ctx, int name) | ||
58 | { | ||
59 | uint32_t *ctxprog = ctx->data; | ||
60 | int i; | ||
61 | |||
62 | if (ctx->mode != NOUVEAU_GRCTX_PROG) | ||
63 | return; | ||
64 | |||
65 | ctx->ctxprog_label[name] = ctx->ctxprog_len; | ||
66 | for (i = 0; i < ctx->ctxprog_len; i++) { | ||
67 | if ((ctxprog[i] & 0xfff00000) != 0xff400000) | ||
68 | continue; | ||
69 | if ((ctxprog[i] & CP_BRA_IP) != ((name) << CP_BRA_IP_SHIFT)) | ||
70 | continue; | ||
71 | ctxprog[i] = (ctxprog[i] & 0x00ff00ff) | | ||
72 | (ctx->ctxprog_len << CP_BRA_IP_SHIFT); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | static inline void | ||
77 | _cp_bra(struct nouveau_grctx *ctx, u32 mod, int flag, int state, int name) | ||
78 | { | ||
79 | int ip = 0; | ||
80 | |||
81 | if (mod != 2) { | ||
82 | ip = ctx->ctxprog_label[name] << CP_BRA_IP_SHIFT; | ||
83 | if (ip == 0) | ||
84 | ip = 0xff000000 | (name << CP_BRA_IP_SHIFT); | ||
85 | } | ||
86 | |||
87 | cp_out(ctx, CP_BRA | (mod << 18) | ip | flag | | ||
88 | (state ? 0 : CP_BRA_IF_CLEAR)); | ||
89 | } | ||
90 | #define cp_bra(c,f,s,n) _cp_bra((c), 0, CP_FLAG_##f, CP_FLAG_##f##_##s, n) | ||
91 | #ifdef CP_BRA_MOD | ||
92 | #define cp_cal(c,f,s,n) _cp_bra((c), 1, CP_FLAG_##f, CP_FLAG_##f##_##s, n) | ||
93 | #define cp_ret(c,f,s) _cp_bra((c), 2, CP_FLAG_##f, CP_FLAG_##f##_##s, 0) | ||
94 | #endif | ||
95 | |||
96 | static inline void | ||
97 | _cp_wait(struct nouveau_grctx *ctx, int flag, int state) | ||
98 | { | ||
99 | cp_out(ctx, CP_WAIT | flag | (state ? CP_WAIT_SET : 0)); | ||
100 | } | ||
101 | #define cp_wait(c,f,s) _cp_wait((c), CP_FLAG_##f, CP_FLAG_##f##_##s) | ||
102 | |||
103 | static inline void | ||
104 | _cp_set(struct nouveau_grctx *ctx, int flag, int state) | ||
105 | { | ||
106 | cp_out(ctx, CP_SET | flag | (state ? CP_SET_1 : 0)); | ||
107 | } | ||
108 | #define cp_set(c,f,s) _cp_set((c), CP_FLAG_##f, CP_FLAG_##f##_##s) | ||
109 | |||
110 | static inline void | ||
111 | cp_pos(struct nouveau_grctx *ctx, int offset) | ||
112 | { | ||
113 | ctx->ctxvals_pos = offset; | ||
114 | ctx->ctxvals_base = ctx->ctxvals_pos; | ||
115 | |||
116 | cp_lsr(ctx, ctx->ctxvals_pos); | ||
117 | cp_out(ctx, CP_SET_CONTEXT_POINTER); | ||
118 | } | ||
119 | |||
120 | static inline void | ||
121 | gr_def(struct nouveau_grctx *ctx, uint32_t reg, uint32_t val) | ||
122 | { | ||
123 | if (ctx->mode != NOUVEAU_GRCTX_VALS) | ||
124 | return; | ||
125 | |||
126 | reg = (reg - 0x00400000) / 4; | ||
127 | reg = (reg - ctx->ctxprog_reg) + ctx->ctxvals_base; | ||
128 | |||
129 | nv_wo32(ctx->dev, ctx->data, reg, val); | ||
130 | } | ||
131 | #endif | ||
132 | |||
133 | #endif | ||
diff --git a/drivers/gpu/drm/nouveau/nv40_graph.c b/drivers/gpu/drm/nouveau/nv40_graph.c index 7e8547cb5833..2b332bb55acf 100644 --- a/drivers/gpu/drm/nouveau/nv40_graph.c +++ b/drivers/gpu/drm/nouveau/nv40_graph.c | |||
@@ -24,36 +24,10 @@ | |||
24 | * | 24 | * |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #include <linux/firmware.h> | ||
28 | |||
29 | #include "drmP.h" | 27 | #include "drmP.h" |
30 | #include "drm.h" | 28 | #include "drm.h" |
31 | #include "nouveau_drv.h" | 29 | #include "nouveau_drv.h" |
32 | 30 | #include "nouveau_grctx.h" | |
33 | MODULE_FIRMWARE("nouveau/nv40.ctxprog"); | ||
34 | MODULE_FIRMWARE("nouveau/nv40.ctxvals"); | ||
35 | MODULE_FIRMWARE("nouveau/nv41.ctxprog"); | ||
36 | MODULE_FIRMWARE("nouveau/nv41.ctxvals"); | ||
37 | MODULE_FIRMWARE("nouveau/nv42.ctxprog"); | ||
38 | MODULE_FIRMWARE("nouveau/nv42.ctxvals"); | ||
39 | MODULE_FIRMWARE("nouveau/nv43.ctxprog"); | ||
40 | MODULE_FIRMWARE("nouveau/nv43.ctxvals"); | ||
41 | MODULE_FIRMWARE("nouveau/nv44.ctxprog"); | ||
42 | MODULE_FIRMWARE("nouveau/nv44.ctxvals"); | ||
43 | MODULE_FIRMWARE("nouveau/nv46.ctxprog"); | ||
44 | MODULE_FIRMWARE("nouveau/nv46.ctxvals"); | ||
45 | MODULE_FIRMWARE("nouveau/nv47.ctxprog"); | ||
46 | MODULE_FIRMWARE("nouveau/nv47.ctxvals"); | ||
47 | MODULE_FIRMWARE("nouveau/nv49.ctxprog"); | ||
48 | MODULE_FIRMWARE("nouveau/nv49.ctxvals"); | ||
49 | MODULE_FIRMWARE("nouveau/nv4a.ctxprog"); | ||
50 | MODULE_FIRMWARE("nouveau/nv4a.ctxvals"); | ||
51 | MODULE_FIRMWARE("nouveau/nv4b.ctxprog"); | ||
52 | MODULE_FIRMWARE("nouveau/nv4b.ctxvals"); | ||
53 | MODULE_FIRMWARE("nouveau/nv4c.ctxprog"); | ||
54 | MODULE_FIRMWARE("nouveau/nv4c.ctxvals"); | ||
55 | MODULE_FIRMWARE("nouveau/nv4e.ctxprog"); | ||
56 | MODULE_FIRMWARE("nouveau/nv4e.ctxvals"); | ||
57 | 31 | ||
58 | struct nouveau_channel * | 32 | struct nouveau_channel * |
59 | nv40_graph_channel(struct drm_device *dev) | 33 | nv40_graph_channel(struct drm_device *dev) |
@@ -83,27 +57,30 @@ nv40_graph_create_context(struct nouveau_channel *chan) | |||
83 | { | 57 | { |
84 | struct drm_device *dev = chan->dev; | 58 | struct drm_device *dev = chan->dev; |
85 | struct drm_nouveau_private *dev_priv = dev->dev_private; | 59 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
86 | struct nouveau_gpuobj *ctx; | 60 | struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph; |
87 | int ret; | 61 | int ret; |
88 | 62 | ||
89 | /* Allocate a 175KiB block of PRAMIN to store the context. This | 63 | ret = nouveau_gpuobj_new_ref(dev, chan, NULL, 0, pgraph->grctx_size, |
90 | * is massive overkill for a lot of chipsets, but it should be safe | 64 | 16, NVOBJ_FLAG_ZERO_ALLOC, |
91 | * until we're able to implement this properly (will happen at more | 65 | &chan->ramin_grctx); |
92 | * or less the same time we're able to write our own context programs. | ||
93 | */ | ||
94 | ret = nouveau_gpuobj_new_ref(dev, chan, NULL, 0, 175*1024, 16, | ||
95 | NVOBJ_FLAG_ZERO_ALLOC, | ||
96 | &chan->ramin_grctx); | ||
97 | if (ret) | 66 | if (ret) |
98 | return ret; | 67 | return ret; |
99 | ctx = chan->ramin_grctx->gpuobj; | ||
100 | 68 | ||
101 | /* Initialise default context values */ | 69 | /* Initialise default context values */ |
102 | dev_priv->engine.instmem.prepare_access(dev, true); | 70 | dev_priv->engine.instmem.prepare_access(dev, true); |
103 | nv40_grctx_vals_load(dev, ctx); | 71 | if (!pgraph->ctxprog) { |
104 | nv_wo32(dev, ctx, 0, ctx->im_pramin->start); | 72 | struct nouveau_grctx ctx = {}; |
105 | dev_priv->engine.instmem.finish_access(dev); | ||
106 | 73 | ||
74 | ctx.dev = chan->dev; | ||
75 | ctx.mode = NOUVEAU_GRCTX_VALS; | ||
76 | ctx.data = chan->ramin_grctx->gpuobj; | ||
77 | nv40_grctx_init(&ctx); | ||
78 | } else { | ||
79 | nouveau_grctx_vals_load(dev, chan->ramin_grctx->gpuobj); | ||
80 | } | ||
81 | nv_wo32(dev, chan->ramin_grctx->gpuobj, 0, | ||
82 | chan->ramin_grctx->gpuobj->im_pramin->start); | ||
83 | dev_priv->engine.instmem.finish_access(dev); | ||
107 | return 0; | 84 | return 0; |
108 | } | 85 | } |
109 | 86 | ||
@@ -204,139 +181,6 @@ nv40_graph_unload_context(struct drm_device *dev) | |||
204 | return ret; | 181 | return ret; |
205 | } | 182 | } |
206 | 183 | ||
207 | struct nouveau_ctxprog { | ||
208 | uint32_t signature; | ||
209 | uint8_t version; | ||
210 | uint16_t length; | ||
211 | uint32_t data[]; | ||
212 | } __attribute__ ((packed)); | ||
213 | |||
214 | struct nouveau_ctxvals { | ||
215 | uint32_t signature; | ||
216 | uint8_t version; | ||
217 | uint32_t length; | ||
218 | struct { | ||
219 | uint32_t offset; | ||
220 | uint32_t value; | ||
221 | } data[]; | ||
222 | } __attribute__ ((packed)); | ||
223 | |||
224 | int | ||
225 | nv40_grctx_init(struct drm_device *dev) | ||
226 | { | ||
227 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
228 | struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph; | ||
229 | const int chipset = dev_priv->chipset; | ||
230 | const struct firmware *fw; | ||
231 | const struct nouveau_ctxprog *cp; | ||
232 | const struct nouveau_ctxvals *cv; | ||
233 | char name[32]; | ||
234 | int ret, i; | ||
235 | |||
236 | pgraph->accel_blocked = true; | ||
237 | |||
238 | if (!pgraph->ctxprog) { | ||
239 | sprintf(name, "nouveau/nv%02x.ctxprog", chipset); | ||
240 | ret = request_firmware(&fw, name, &dev->pdev->dev); | ||
241 | if (ret) { | ||
242 | NV_ERROR(dev, "No ctxprog for NV%02x\n", chipset); | ||
243 | return ret; | ||
244 | } | ||
245 | |||
246 | pgraph->ctxprog = kmalloc(fw->size, GFP_KERNEL); | ||
247 | if (!pgraph->ctxprog) { | ||
248 | NV_ERROR(dev, "OOM copying ctxprog\n"); | ||
249 | release_firmware(fw); | ||
250 | return -ENOMEM; | ||
251 | } | ||
252 | memcpy(pgraph->ctxprog, fw->data, fw->size); | ||
253 | |||
254 | cp = pgraph->ctxprog; | ||
255 | if (le32_to_cpu(cp->signature) != 0x5043564e || | ||
256 | cp->version != 0 || | ||
257 | le16_to_cpu(cp->length) != ((fw->size - 7) / 4)) { | ||
258 | NV_ERROR(dev, "ctxprog invalid\n"); | ||
259 | release_firmware(fw); | ||
260 | nv40_grctx_fini(dev); | ||
261 | return -EINVAL; | ||
262 | } | ||
263 | release_firmware(fw); | ||
264 | } | ||
265 | |||
266 | if (!pgraph->ctxvals) { | ||
267 | sprintf(name, "nouveau/nv%02x.ctxvals", chipset); | ||
268 | ret = request_firmware(&fw, name, &dev->pdev->dev); | ||
269 | if (ret) { | ||
270 | NV_ERROR(dev, "No ctxvals for NV%02x\n", chipset); | ||
271 | nv40_grctx_fini(dev); | ||
272 | return ret; | ||
273 | } | ||
274 | |||
275 | pgraph->ctxvals = kmalloc(fw->size, GFP_KERNEL); | ||
276 | if (!pgraph->ctxprog) { | ||
277 | NV_ERROR(dev, "OOM copying ctxprog\n"); | ||
278 | release_firmware(fw); | ||
279 | nv40_grctx_fini(dev); | ||
280 | return -ENOMEM; | ||
281 | } | ||
282 | memcpy(pgraph->ctxvals, fw->data, fw->size); | ||
283 | |||
284 | cv = (void *)pgraph->ctxvals; | ||
285 | if (le32_to_cpu(cv->signature) != 0x5643564e || | ||
286 | cv->version != 0 || | ||
287 | le32_to_cpu(cv->length) != ((fw->size - 9) / 8)) { | ||
288 | NV_ERROR(dev, "ctxvals invalid\n"); | ||
289 | release_firmware(fw); | ||
290 | nv40_grctx_fini(dev); | ||
291 | return -EINVAL; | ||
292 | } | ||
293 | release_firmware(fw); | ||
294 | } | ||
295 | |||
296 | cp = pgraph->ctxprog; | ||
297 | |||
298 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0); | ||
299 | for (i = 0; i < le16_to_cpu(cp->length); i++) | ||
300 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, | ||
301 | le32_to_cpu(cp->data[i])); | ||
302 | |||
303 | pgraph->accel_blocked = false; | ||
304 | return 0; | ||
305 | } | ||
306 | |||
307 | void | ||
308 | nv40_grctx_fini(struct drm_device *dev) | ||
309 | { | ||
310 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
311 | struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph; | ||
312 | |||
313 | if (pgraph->ctxprog) { | ||
314 | kfree(pgraph->ctxprog); | ||
315 | pgraph->ctxprog = NULL; | ||
316 | } | ||
317 | |||
318 | if (pgraph->ctxvals) { | ||
319 | kfree(pgraph->ctxprog); | ||
320 | pgraph->ctxvals = NULL; | ||
321 | } | ||
322 | } | ||
323 | |||
324 | void | ||
325 | nv40_grctx_vals_load(struct drm_device *dev, struct nouveau_gpuobj *ctx) | ||
326 | { | ||
327 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
328 | struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph; | ||
329 | struct nouveau_ctxvals *cv = pgraph->ctxvals; | ||
330 | int i; | ||
331 | |||
332 | if (!cv) | ||
333 | return; | ||
334 | |||
335 | for (i = 0; i < le32_to_cpu(cv->length); i++) | ||
336 | nv_wo32(dev, ctx, le32_to_cpu(cv->data[i].offset), | ||
337 | le32_to_cpu(cv->data[i].value)); | ||
338 | } | ||
339 | |||
340 | /* | 184 | /* |
341 | * G70 0x47 | 185 | * G70 0x47 |
342 | * G71 0x49 | 186 | * G71 0x49 |
@@ -359,7 +203,26 @@ nv40_graph_init(struct drm_device *dev) | |||
359 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | | 203 | nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | |
360 | NV_PMC_ENABLE_PGRAPH); | 204 | NV_PMC_ENABLE_PGRAPH); |
361 | 205 | ||
362 | nv40_grctx_init(dev); | 206 | if (nouveau_ctxfw) { |
207 | nouveau_grctx_prog_load(dev); | ||
208 | dev_priv->engine.graph.grctx_size = 175 * 1024; | ||
209 | } | ||
210 | |||
211 | if (!dev_priv->engine.graph.ctxprog) { | ||
212 | struct nouveau_grctx ctx = {}; | ||
213 | uint32_t cp[256]; | ||
214 | |||
215 | ctx.dev = dev; | ||
216 | ctx.mode = NOUVEAU_GRCTX_PROG; | ||
217 | ctx.data = cp; | ||
218 | ctx.ctxprog_max = 256; | ||
219 | nv40_grctx_init(&ctx); | ||
220 | dev_priv->engine.graph.grctx_size = ctx.ctxvals_pos * 4; | ||
221 | |||
222 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0); | ||
223 | for (i = 0; i < ctx.ctxprog_len; i++) | ||
224 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, cp[i]); | ||
225 | } | ||
363 | 226 | ||
364 | /* No context present currently */ | 227 | /* No context present currently */ |
365 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0x00000000); | 228 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0x00000000); |
@@ -539,6 +402,7 @@ nv40_graph_init(struct drm_device *dev) | |||
539 | 402 | ||
540 | void nv40_graph_takedown(struct drm_device *dev) | 403 | void nv40_graph_takedown(struct drm_device *dev) |
541 | { | 404 | { |
405 | nouveau_grctx_fini(dev); | ||
542 | } | 406 | } |
543 | 407 | ||
544 | struct nouveau_pgraph_object_class nv40_graph_grclass[] = { | 408 | struct nouveau_pgraph_object_class nv40_graph_grclass[] = { |
diff --git a/drivers/gpu/drm/nouveau/nv40_grctx.c b/drivers/gpu/drm/nouveau/nv40_grctx.c new file mode 100644 index 000000000000..11b11c31f543 --- /dev/null +++ b/drivers/gpu/drm/nouveau/nv40_grctx.c | |||
@@ -0,0 +1,678 @@ | |||
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 | /* NVIDIA context programs handle a number of other conditions which are | ||
26 | * not implemented in our versions. It's not clear why NVIDIA context | ||
27 | * programs have this code, nor whether it's strictly necessary for | ||
28 | * correct operation. We'll implement additional handling if/when we | ||
29 | * discover it's necessary. | ||
30 | * | ||
31 | * - On context save, NVIDIA set 0x400314 bit 0 to 1 if the "3D state" | ||
32 | * flag is set, this gets saved into the context. | ||
33 | * - On context save, the context program for all cards load nsource | ||
34 | * into a flag register and check for ILLEGAL_MTHD. If it's set, | ||
35 | * opcode 0x60000d is called before resuming normal operation. | ||
36 | * - Some context programs check more conditions than the above. NV44 | ||
37 | * checks: ((nsource & 0x0857) || (0x400718 & 0x0100) || (intr & 0x0001)) | ||
38 | * and calls 0x60000d before resuming normal operation. | ||
39 | * - At the very beginning of NVIDIA's context programs, flag 9 is checked | ||
40 | * and if true 0x800001 is called with count=0, pos=0, the flag is cleared | ||
41 | * and then the ctxprog is aborted. It looks like a complicated NOP, | ||
42 | * its purpose is unknown. | ||
43 | * - In the section of code that loads the per-vs state, NVIDIA check | ||
44 | * flag 10. If it's set, they only transfer the small 0x300 byte block | ||
45 | * of state + the state for a single vs as opposed to the state for | ||
46 | * all vs units. It doesn't seem likely that it'll occur in normal | ||
47 | * operation, especially seeing as it appears NVIDIA may have screwed | ||
48 | * up the ctxprogs for some cards and have an invalid instruction | ||
49 | * rather than a cp_lsr(ctx, dwords_for_1_vs_unit) instruction. | ||
50 | * - There's a number of places where context offset 0 (where we place | ||
51 | * the PRAMIN offset of the context) is loaded into either 0x408000, | ||
52 | * 0x408004 or 0x408008. Not sure what's up there either. | ||
53 | * - The ctxprogs for some cards save 0x400a00 again during the cleanup | ||
54 | * path for auto-loadctx. | ||
55 | */ | ||
56 | |||
57 | #define CP_FLAG_CLEAR 0 | ||
58 | #define CP_FLAG_SET 1 | ||
59 | #define CP_FLAG_SWAP_DIRECTION ((0 * 32) + 0) | ||
60 | #define CP_FLAG_SWAP_DIRECTION_LOAD 0 | ||
61 | #define CP_FLAG_SWAP_DIRECTION_SAVE 1 | ||
62 | #define CP_FLAG_USER_SAVE ((0 * 32) + 5) | ||
63 | #define CP_FLAG_USER_SAVE_NOT_PENDING 0 | ||
64 | #define CP_FLAG_USER_SAVE_PENDING 1 | ||
65 | #define CP_FLAG_USER_LOAD ((0 * 32) + 6) | ||
66 | #define CP_FLAG_USER_LOAD_NOT_PENDING 0 | ||
67 | #define CP_FLAG_USER_LOAD_PENDING 1 | ||
68 | #define CP_FLAG_STATUS ((3 * 32) + 0) | ||
69 | #define CP_FLAG_STATUS_IDLE 0 | ||
70 | #define CP_FLAG_STATUS_BUSY 1 | ||
71 | #define CP_FLAG_AUTO_SAVE ((3 * 32) + 4) | ||
72 | #define CP_FLAG_AUTO_SAVE_NOT_PENDING 0 | ||
73 | #define CP_FLAG_AUTO_SAVE_PENDING 1 | ||
74 | #define CP_FLAG_AUTO_LOAD ((3 * 32) + 5) | ||
75 | #define CP_FLAG_AUTO_LOAD_NOT_PENDING 0 | ||
76 | #define CP_FLAG_AUTO_LOAD_PENDING 1 | ||
77 | #define CP_FLAG_UNK54 ((3 * 32) + 6) | ||
78 | #define CP_FLAG_UNK54_CLEAR 0 | ||
79 | #define CP_FLAG_UNK54_SET 1 | ||
80 | #define CP_FLAG_ALWAYS ((3 * 32) + 8) | ||
81 | #define CP_FLAG_ALWAYS_FALSE 0 | ||
82 | #define CP_FLAG_ALWAYS_TRUE 1 | ||
83 | #define CP_FLAG_UNK57 ((3 * 32) + 9) | ||
84 | #define CP_FLAG_UNK57_CLEAR 0 | ||
85 | #define CP_FLAG_UNK57_SET 1 | ||
86 | |||
87 | #define CP_CTX 0x00100000 | ||
88 | #define CP_CTX_COUNT 0x000fc000 | ||
89 | #define CP_CTX_COUNT_SHIFT 14 | ||
90 | #define CP_CTX_REG 0x00003fff | ||
91 | #define CP_LOAD_SR 0x00200000 | ||
92 | #define CP_LOAD_SR_VALUE 0x000fffff | ||
93 | #define CP_BRA 0x00400000 | ||
94 | #define CP_BRA_IP 0x0000ff00 | ||
95 | #define CP_BRA_IP_SHIFT 8 | ||
96 | #define CP_BRA_IF_CLEAR 0x00000080 | ||
97 | #define CP_BRA_FLAG 0x0000007f | ||
98 | #define CP_WAIT 0x00500000 | ||
99 | #define CP_WAIT_SET 0x00000080 | ||
100 | #define CP_WAIT_FLAG 0x0000007f | ||
101 | #define CP_SET 0x00700000 | ||
102 | #define CP_SET_1 0x00000080 | ||
103 | #define CP_SET_FLAG 0x0000007f | ||
104 | #define CP_NEXT_TO_SWAP 0x00600007 | ||
105 | #define CP_NEXT_TO_CURRENT 0x00600009 | ||
106 | #define CP_SET_CONTEXT_POINTER 0x0060000a | ||
107 | #define CP_END 0x0060000e | ||
108 | #define CP_LOAD_MAGIC_UNK01 0x00800001 /* unknown */ | ||
109 | #define CP_LOAD_MAGIC_NV44TCL 0x00800029 /* per-vs state (0x4497) */ | ||
110 | #define CP_LOAD_MAGIC_NV40TCL 0x00800041 /* per-vs state (0x4097) */ | ||
111 | |||
112 | #include "drmP.h" | ||
113 | #include "nouveau_drv.h" | ||
114 | #include "nouveau_grctx.h" | ||
115 | |||
116 | /* TODO: | ||
117 | * - get vs count from 0x1540 | ||
118 | * - document unimplemented bits compared to nvidia | ||
119 | * - nsource handling | ||
120 | * - R0 & 0x0200 handling | ||
121 | * - single-vs handling | ||
122 | * - 400314 bit 0 | ||
123 | */ | ||
124 | |||
125 | static int | ||
126 | nv40_graph_4097(struct drm_device *dev) | ||
127 | { | ||
128 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
129 | |||
130 | if ((dev_priv->chipset & 0xf0) == 0x60) | ||
131 | return 0; | ||
132 | |||
133 | return !!(0x0baf & (1 << dev_priv->chipset)); | ||
134 | } | ||
135 | |||
136 | static int | ||
137 | nv40_graph_vs_count(struct drm_device *dev) | ||
138 | { | ||
139 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
140 | |||
141 | switch (dev_priv->chipset) { | ||
142 | case 0x47: | ||
143 | case 0x49: | ||
144 | case 0x4b: | ||
145 | return 8; | ||
146 | case 0x40: | ||
147 | return 6; | ||
148 | case 0x41: | ||
149 | case 0x42: | ||
150 | return 5; | ||
151 | case 0x43: | ||
152 | case 0x44: | ||
153 | case 0x46: | ||
154 | case 0x4a: | ||
155 | return 3; | ||
156 | case 0x4c: | ||
157 | case 0x4e: | ||
158 | case 0x67: | ||
159 | default: | ||
160 | return 1; | ||
161 | } | ||
162 | } | ||
163 | |||
164 | |||
165 | enum cp_label { | ||
166 | cp_check_load = 1, | ||
167 | cp_setup_auto_load, | ||
168 | cp_setup_load, | ||
169 | cp_setup_save, | ||
170 | cp_swap_state, | ||
171 | cp_swap_state3d_3_is_save, | ||
172 | cp_prepare_exit, | ||
173 | cp_exit, | ||
174 | }; | ||
175 | |||
176 | static void | ||
177 | nv40_graph_construct_general(struct nouveau_grctx *ctx) | ||
178 | { | ||
179 | struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; | ||
180 | int i; | ||
181 | |||
182 | cp_ctx(ctx, 0x4000a4, 1); | ||
183 | gr_def(ctx, 0x4000a4, 0x00000008); | ||
184 | cp_ctx(ctx, 0x400144, 58); | ||
185 | gr_def(ctx, 0x400144, 0x00000001); | ||
186 | cp_ctx(ctx, 0x400314, 1); | ||
187 | gr_def(ctx, 0x400314, 0x00000000); | ||
188 | cp_ctx(ctx, 0x400400, 10); | ||
189 | cp_ctx(ctx, 0x400480, 10); | ||
190 | cp_ctx(ctx, 0x400500, 19); | ||
191 | gr_def(ctx, 0x400514, 0x00040000); | ||
192 | gr_def(ctx, 0x400524, 0x55555555); | ||
193 | gr_def(ctx, 0x400528, 0x55555555); | ||
194 | gr_def(ctx, 0x40052c, 0x55555555); | ||
195 | gr_def(ctx, 0x400530, 0x55555555); | ||
196 | cp_ctx(ctx, 0x400560, 6); | ||
197 | gr_def(ctx, 0x400568, 0x0000ffff); | ||
198 | gr_def(ctx, 0x40056c, 0x0000ffff); | ||
199 | cp_ctx(ctx, 0x40057c, 5); | ||
200 | cp_ctx(ctx, 0x400710, 3); | ||
201 | gr_def(ctx, 0x400710, 0x20010001); | ||
202 | gr_def(ctx, 0x400714, 0x0f73ef00); | ||
203 | cp_ctx(ctx, 0x400724, 1); | ||
204 | gr_def(ctx, 0x400724, 0x02008821); | ||
205 | cp_ctx(ctx, 0x400770, 3); | ||
206 | if (dev_priv->chipset == 0x40) { | ||
207 | cp_ctx(ctx, 0x400814, 4); | ||
208 | cp_ctx(ctx, 0x400828, 5); | ||
209 | cp_ctx(ctx, 0x400840, 5); | ||
210 | gr_def(ctx, 0x400850, 0x00000040); | ||
211 | cp_ctx(ctx, 0x400858, 4); | ||
212 | gr_def(ctx, 0x400858, 0x00000040); | ||
213 | gr_def(ctx, 0x40085c, 0x00000040); | ||
214 | gr_def(ctx, 0x400864, 0x80000000); | ||
215 | cp_ctx(ctx, 0x40086c, 9); | ||
216 | gr_def(ctx, 0x40086c, 0x80000000); | ||
217 | gr_def(ctx, 0x400870, 0x80000000); | ||
218 | gr_def(ctx, 0x400874, 0x80000000); | ||
219 | gr_def(ctx, 0x400878, 0x80000000); | ||
220 | gr_def(ctx, 0x400888, 0x00000040); | ||
221 | gr_def(ctx, 0x40088c, 0x80000000); | ||
222 | cp_ctx(ctx, 0x4009c0, 8); | ||
223 | gr_def(ctx, 0x4009cc, 0x80000000); | ||
224 | gr_def(ctx, 0x4009dc, 0x80000000); | ||
225 | } else { | ||
226 | cp_ctx(ctx, 0x400840, 20); | ||
227 | if (!nv40_graph_4097(ctx->dev)) { | ||
228 | for (i = 0; i < 8; i++) | ||
229 | gr_def(ctx, 0x400860 + (i * 4), 0x00000001); | ||
230 | } | ||
231 | gr_def(ctx, 0x400880, 0x00000040); | ||
232 | gr_def(ctx, 0x400884, 0x00000040); | ||
233 | gr_def(ctx, 0x400888, 0x00000040); | ||
234 | cp_ctx(ctx, 0x400894, 11); | ||
235 | gr_def(ctx, 0x400894, 0x00000040); | ||
236 | if (nv40_graph_4097(ctx->dev)) { | ||
237 | for (i = 0; i < 8; i++) | ||
238 | gr_def(ctx, 0x4008a0 + (i * 4), 0x80000000); | ||
239 | } | ||
240 | cp_ctx(ctx, 0x4008e0, 2); | ||
241 | cp_ctx(ctx, 0x4008f8, 2); | ||
242 | if (dev_priv->chipset == 0x4c || | ||
243 | (dev_priv->chipset & 0xf0) == 0x60) | ||
244 | cp_ctx(ctx, 0x4009f8, 1); | ||
245 | } | ||
246 | cp_ctx(ctx, 0x400a00, 73); | ||
247 | gr_def(ctx, 0x400b0c, 0x0b0b0b0c); | ||
248 | cp_ctx(ctx, 0x401000, 4); | ||
249 | cp_ctx(ctx, 0x405004, 1); | ||
250 | switch (dev_priv->chipset) { | ||
251 | case 0x47: | ||
252 | case 0x49: | ||
253 | case 0x4b: | ||
254 | cp_ctx(ctx, 0x403448, 1); | ||
255 | gr_def(ctx, 0x403448, 0x00001010); | ||
256 | break; | ||
257 | default: | ||
258 | cp_ctx(ctx, 0x403440, 1); | ||
259 | switch (dev_priv->chipset) { | ||
260 | case 0x40: | ||
261 | gr_def(ctx, 0x403440, 0x00000010); | ||
262 | break; | ||
263 | case 0x44: | ||
264 | case 0x46: | ||
265 | case 0x4a: | ||
266 | gr_def(ctx, 0x403440, 0x00003010); | ||
267 | break; | ||
268 | case 0x41: | ||
269 | case 0x42: | ||
270 | case 0x43: | ||
271 | case 0x4c: | ||
272 | case 0x4e: | ||
273 | case 0x67: | ||
274 | default: | ||
275 | gr_def(ctx, 0x403440, 0x00001010); | ||
276 | break; | ||
277 | } | ||
278 | break; | ||
279 | } | ||
280 | } | ||
281 | |||
282 | static void | ||
283 | nv40_graph_construct_state3d(struct nouveau_grctx *ctx) | ||
284 | { | ||
285 | struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; | ||
286 | int i; | ||
287 | |||
288 | if (dev_priv->chipset == 0x40) { | ||
289 | cp_ctx(ctx, 0x401880, 51); | ||
290 | gr_def(ctx, 0x401940, 0x00000100); | ||
291 | } else | ||
292 | if (dev_priv->chipset == 0x46 || dev_priv->chipset == 0x47 || | ||
293 | dev_priv->chipset == 0x49 || dev_priv->chipset == 0x4b) { | ||
294 | cp_ctx(ctx, 0x401880, 32); | ||
295 | for (i = 0; i < 16; i++) | ||
296 | gr_def(ctx, 0x401880 + (i * 4), 0x00000111); | ||
297 | if (dev_priv->chipset == 0x46) | ||
298 | cp_ctx(ctx, 0x401900, 16); | ||
299 | cp_ctx(ctx, 0x401940, 3); | ||
300 | } | ||
301 | cp_ctx(ctx, 0x40194c, 18); | ||
302 | gr_def(ctx, 0x401954, 0x00000111); | ||
303 | gr_def(ctx, 0x401958, 0x00080060); | ||
304 | gr_def(ctx, 0x401974, 0x00000080); | ||
305 | gr_def(ctx, 0x401978, 0xffff0000); | ||
306 | gr_def(ctx, 0x40197c, 0x00000001); | ||
307 | gr_def(ctx, 0x401990, 0x46400000); | ||
308 | if (dev_priv->chipset == 0x40) { | ||
309 | cp_ctx(ctx, 0x4019a0, 2); | ||
310 | cp_ctx(ctx, 0x4019ac, 5); | ||
311 | } else { | ||
312 | cp_ctx(ctx, 0x4019a0, 1); | ||
313 | cp_ctx(ctx, 0x4019b4, 3); | ||
314 | } | ||
315 | gr_def(ctx, 0x4019bc, 0xffff0000); | ||
316 | switch (dev_priv->chipset) { | ||
317 | case 0x46: | ||
318 | case 0x47: | ||
319 | case 0x49: | ||
320 | case 0x4b: | ||
321 | cp_ctx(ctx, 0x4019c0, 18); | ||
322 | for (i = 0; i < 16; i++) | ||
323 | gr_def(ctx, 0x4019c0 + (i * 4), 0x88888888); | ||
324 | break; | ||
325 | } | ||
326 | cp_ctx(ctx, 0x401a08, 8); | ||
327 | gr_def(ctx, 0x401a10, 0x0fff0000); | ||
328 | gr_def(ctx, 0x401a14, 0x0fff0000); | ||
329 | gr_def(ctx, 0x401a1c, 0x00011100); | ||
330 | cp_ctx(ctx, 0x401a2c, 4); | ||
331 | cp_ctx(ctx, 0x401a44, 26); | ||
332 | for (i = 0; i < 16; i++) | ||
333 | gr_def(ctx, 0x401a44 + (i * 4), 0x07ff0000); | ||
334 | gr_def(ctx, 0x401a8c, 0x4b7fffff); | ||
335 | if (dev_priv->chipset == 0x40) { | ||
336 | cp_ctx(ctx, 0x401ab8, 3); | ||
337 | } else { | ||
338 | cp_ctx(ctx, 0x401ab8, 1); | ||
339 | cp_ctx(ctx, 0x401ac0, 1); | ||
340 | } | ||
341 | cp_ctx(ctx, 0x401ad0, 8); | ||
342 | gr_def(ctx, 0x401ad0, 0x30201000); | ||
343 | gr_def(ctx, 0x401ad4, 0x70605040); | ||
344 | gr_def(ctx, 0x401ad8, 0xb8a89888); | ||
345 | gr_def(ctx, 0x401adc, 0xf8e8d8c8); | ||
346 | cp_ctx(ctx, 0x401b10, dev_priv->chipset == 0x40 ? 2 : 1); | ||
347 | gr_def(ctx, 0x401b10, 0x40100000); | ||
348 | cp_ctx(ctx, 0x401b18, dev_priv->chipset == 0x40 ? 6 : 5); | ||
349 | gr_def(ctx, 0x401b28, dev_priv->chipset == 0x40 ? | ||
350 | 0x00000004 : 0x00000000); | ||
351 | cp_ctx(ctx, 0x401b30, 25); | ||
352 | gr_def(ctx, 0x401b34, 0x0000ffff); | ||
353 | gr_def(ctx, 0x401b68, 0x435185d6); | ||
354 | gr_def(ctx, 0x401b6c, 0x2155b699); | ||
355 | gr_def(ctx, 0x401b70, 0xfedcba98); | ||
356 | gr_def(ctx, 0x401b74, 0x00000098); | ||
357 | gr_def(ctx, 0x401b84, 0xffffffff); | ||
358 | gr_def(ctx, 0x401b88, 0x00ff7000); | ||
359 | gr_def(ctx, 0x401b8c, 0x0000ffff); | ||
360 | if (dev_priv->chipset != 0x44 && dev_priv->chipset != 0x4a && | ||
361 | dev_priv->chipset != 0x4e) | ||
362 | cp_ctx(ctx, 0x401b94, 1); | ||
363 | cp_ctx(ctx, 0x401b98, 8); | ||
364 | gr_def(ctx, 0x401b9c, 0x00ff0000); | ||
365 | cp_ctx(ctx, 0x401bc0, 9); | ||
366 | gr_def(ctx, 0x401be0, 0x00ffff00); | ||
367 | cp_ctx(ctx, 0x401c00, 192); | ||
368 | for (i = 0; i < 16; i++) { /* fragment texture units */ | ||
369 | gr_def(ctx, 0x401c40 + (i * 4), 0x00018488); | ||
370 | gr_def(ctx, 0x401c80 + (i * 4), 0x00028202); | ||
371 | gr_def(ctx, 0x401d00 + (i * 4), 0x0000aae4); | ||
372 | gr_def(ctx, 0x401d40 + (i * 4), 0x01012000); | ||
373 | gr_def(ctx, 0x401d80 + (i * 4), 0x00080008); | ||
374 | gr_def(ctx, 0x401e00 + (i * 4), 0x00100008); | ||
375 | } | ||
376 | for (i = 0; i < 4; i++) { /* vertex texture units */ | ||
377 | gr_def(ctx, 0x401e90 + (i * 4), 0x0001bc80); | ||
378 | gr_def(ctx, 0x401ea0 + (i * 4), 0x00000202); | ||
379 | gr_def(ctx, 0x401ec0 + (i * 4), 0x00000008); | ||
380 | gr_def(ctx, 0x401ee0 + (i * 4), 0x00080008); | ||
381 | } | ||
382 | cp_ctx(ctx, 0x400f5c, 3); | ||
383 | gr_def(ctx, 0x400f5c, 0x00000002); | ||
384 | cp_ctx(ctx, 0x400f84, 1); | ||
385 | } | ||
386 | |||
387 | static void | ||
388 | nv40_graph_construct_state3d_2(struct nouveau_grctx *ctx) | ||
389 | { | ||
390 | struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; | ||
391 | int i; | ||
392 | |||
393 | cp_ctx(ctx, 0x402000, 1); | ||
394 | cp_ctx(ctx, 0x402404, dev_priv->chipset == 0x40 ? 1 : 2); | ||
395 | switch (dev_priv->chipset) { | ||
396 | case 0x40: | ||
397 | gr_def(ctx, 0x402404, 0x00000001); | ||
398 | break; | ||
399 | case 0x4c: | ||
400 | case 0x4e: | ||
401 | case 0x67: | ||
402 | gr_def(ctx, 0x402404, 0x00000020); | ||
403 | break; | ||
404 | case 0x46: | ||
405 | case 0x49: | ||
406 | case 0x4b: | ||
407 | gr_def(ctx, 0x402404, 0x00000421); | ||
408 | break; | ||
409 | default: | ||
410 | gr_def(ctx, 0x402404, 0x00000021); | ||
411 | } | ||
412 | if (dev_priv->chipset != 0x40) | ||
413 | gr_def(ctx, 0x402408, 0x030c30c3); | ||
414 | switch (dev_priv->chipset) { | ||
415 | case 0x44: | ||
416 | case 0x46: | ||
417 | case 0x4a: | ||
418 | case 0x4c: | ||
419 | case 0x4e: | ||
420 | case 0x67: | ||
421 | cp_ctx(ctx, 0x402440, 1); | ||
422 | gr_def(ctx, 0x402440, 0x00011001); | ||
423 | break; | ||
424 | default: | ||
425 | break; | ||
426 | } | ||
427 | cp_ctx(ctx, 0x402480, dev_priv->chipset == 0x40 ? 8 : 9); | ||
428 | gr_def(ctx, 0x402488, 0x3e020200); | ||
429 | gr_def(ctx, 0x40248c, 0x00ffffff); | ||
430 | switch (dev_priv->chipset) { | ||
431 | case 0x40: | ||
432 | gr_def(ctx, 0x402490, 0x60103f00); | ||
433 | break; | ||
434 | case 0x47: | ||
435 | gr_def(ctx, 0x402490, 0x40103f00); | ||
436 | break; | ||
437 | case 0x41: | ||
438 | case 0x42: | ||
439 | case 0x49: | ||
440 | case 0x4b: | ||
441 | gr_def(ctx, 0x402490, 0x20103f00); | ||
442 | break; | ||
443 | default: | ||
444 | gr_def(ctx, 0x402490, 0x0c103f00); | ||
445 | break; | ||
446 | } | ||
447 | gr_def(ctx, 0x40249c, dev_priv->chipset <= 0x43 ? | ||
448 | 0x00020000 : 0x00040000); | ||
449 | cp_ctx(ctx, 0x402500, 31); | ||
450 | gr_def(ctx, 0x402530, 0x00008100); | ||
451 | if (dev_priv->chipset == 0x40) | ||
452 | cp_ctx(ctx, 0x40257c, 6); | ||
453 | cp_ctx(ctx, 0x402594, 16); | ||
454 | cp_ctx(ctx, 0x402800, 17); | ||
455 | gr_def(ctx, 0x402800, 0x00000001); | ||
456 | switch (dev_priv->chipset) { | ||
457 | case 0x47: | ||
458 | case 0x49: | ||
459 | case 0x4b: | ||
460 | cp_ctx(ctx, 0x402864, 1); | ||
461 | gr_def(ctx, 0x402864, 0x00001001); | ||
462 | cp_ctx(ctx, 0x402870, 3); | ||
463 | gr_def(ctx, 0x402878, 0x00000003); | ||
464 | if (dev_priv->chipset != 0x47) { /* belong at end!! */ | ||
465 | cp_ctx(ctx, 0x402900, 1); | ||
466 | cp_ctx(ctx, 0x402940, 1); | ||
467 | cp_ctx(ctx, 0x402980, 1); | ||
468 | cp_ctx(ctx, 0x4029c0, 1); | ||
469 | cp_ctx(ctx, 0x402a00, 1); | ||
470 | cp_ctx(ctx, 0x402a40, 1); | ||
471 | cp_ctx(ctx, 0x402a80, 1); | ||
472 | cp_ctx(ctx, 0x402ac0, 1); | ||
473 | } | ||
474 | break; | ||
475 | case 0x40: | ||
476 | cp_ctx(ctx, 0x402844, 1); | ||
477 | gr_def(ctx, 0x402844, 0x00000001); | ||
478 | cp_ctx(ctx, 0x402850, 1); | ||
479 | break; | ||
480 | default: | ||
481 | cp_ctx(ctx, 0x402844, 1); | ||
482 | gr_def(ctx, 0x402844, 0x00001001); | ||
483 | cp_ctx(ctx, 0x402850, 2); | ||
484 | gr_def(ctx, 0x402854, 0x00000003); | ||
485 | break; | ||
486 | } | ||
487 | |||
488 | cp_ctx(ctx, 0x402c00, 4); | ||
489 | gr_def(ctx, 0x402c00, dev_priv->chipset == 0x40 ? | ||
490 | 0x80800001 : 0x00888001); | ||
491 | switch (dev_priv->chipset) { | ||
492 | case 0x47: | ||
493 | case 0x49: | ||
494 | case 0x4b: | ||
495 | cp_ctx(ctx, 0x402c20, 40); | ||
496 | for (i = 0; i < 32; i++) | ||
497 | gr_def(ctx, 0x402c40 + (i * 4), 0xffffffff); | ||
498 | cp_ctx(ctx, 0x4030b8, 13); | ||
499 | gr_def(ctx, 0x4030dc, 0x00000005); | ||
500 | gr_def(ctx, 0x4030e8, 0x0000ffff); | ||
501 | break; | ||
502 | default: | ||
503 | cp_ctx(ctx, 0x402c10, 4); | ||
504 | if (dev_priv->chipset == 0x40) | ||
505 | cp_ctx(ctx, 0x402c20, 36); | ||
506 | else | ||
507 | if (dev_priv->chipset <= 0x42) | ||
508 | cp_ctx(ctx, 0x402c20, 24); | ||
509 | else | ||
510 | if (dev_priv->chipset <= 0x4a) | ||
511 | cp_ctx(ctx, 0x402c20, 16); | ||
512 | else | ||
513 | cp_ctx(ctx, 0x402c20, 8); | ||
514 | cp_ctx(ctx, 0x402cb0, dev_priv->chipset == 0x40 ? 12 : 13); | ||
515 | gr_def(ctx, 0x402cd4, 0x00000005); | ||
516 | if (dev_priv->chipset != 0x40) | ||
517 | gr_def(ctx, 0x402ce0, 0x0000ffff); | ||
518 | break; | ||
519 | } | ||
520 | |||
521 | cp_ctx(ctx, 0x403400, dev_priv->chipset == 0x40 ? 4 : 3); | ||
522 | cp_ctx(ctx, 0x403410, dev_priv->chipset == 0x40 ? 4 : 3); | ||
523 | cp_ctx(ctx, 0x403420, nv40_graph_vs_count(ctx->dev)); | ||
524 | for (i = 0; i < nv40_graph_vs_count(ctx->dev); i++) | ||
525 | gr_def(ctx, 0x403420 + (i * 4), 0x00005555); | ||
526 | |||
527 | if (dev_priv->chipset != 0x40) { | ||
528 | cp_ctx(ctx, 0x403600, 1); | ||
529 | gr_def(ctx, 0x403600, 0x00000001); | ||
530 | } | ||
531 | cp_ctx(ctx, 0x403800, 1); | ||
532 | |||
533 | cp_ctx(ctx, 0x403c18, 1); | ||
534 | gr_def(ctx, 0x403c18, 0x00000001); | ||
535 | switch (dev_priv->chipset) { | ||
536 | case 0x46: | ||
537 | case 0x47: | ||
538 | case 0x49: | ||
539 | case 0x4b: | ||
540 | cp_ctx(ctx, 0x405018, 1); | ||
541 | gr_def(ctx, 0x405018, 0x08e00001); | ||
542 | cp_ctx(ctx, 0x405c24, 1); | ||
543 | gr_def(ctx, 0x405c24, 0x000e3000); | ||
544 | break; | ||
545 | } | ||
546 | if (dev_priv->chipset != 0x4e) | ||
547 | cp_ctx(ctx, 0x405800, 11); | ||
548 | cp_ctx(ctx, 0x407000, 1); | ||
549 | } | ||
550 | |||
551 | static void | ||
552 | nv40_graph_construct_state3d_3(struct nouveau_grctx *ctx) | ||
553 | { | ||
554 | int len = nv40_graph_4097(ctx->dev) ? 0x0684 : 0x0084; | ||
555 | |||
556 | cp_out (ctx, 0x300000); | ||
557 | cp_lsr (ctx, len - 4); | ||
558 | cp_bra (ctx, SWAP_DIRECTION, SAVE, cp_swap_state3d_3_is_save); | ||
559 | cp_lsr (ctx, len); | ||
560 | cp_name(ctx, cp_swap_state3d_3_is_save); | ||
561 | cp_out (ctx, 0x800001); | ||
562 | |||
563 | ctx->ctxvals_pos += len; | ||
564 | } | ||
565 | |||
566 | static void | ||
567 | nv40_graph_construct_shader(struct nouveau_grctx *ctx) | ||
568 | { | ||
569 | struct drm_device *dev = ctx->dev; | ||
570 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
571 | struct nouveau_gpuobj *obj = ctx->data; | ||
572 | int vs, vs_nr, vs_len, vs_nr_b0, vs_nr_b1, b0_offset, b1_offset; | ||
573 | int offset, i; | ||
574 | |||
575 | vs_nr = nv40_graph_vs_count(ctx->dev); | ||
576 | vs_nr_b0 = 363; | ||
577 | vs_nr_b1 = dev_priv->chipset == 0x40 ? 128 : 64; | ||
578 | if (dev_priv->chipset == 0x40) { | ||
579 | b0_offset = 0x2200/4; /* 33a0 */ | ||
580 | b1_offset = 0x55a0/4; /* 1500 */ | ||
581 | vs_len = 0x6aa0/4; | ||
582 | } else | ||
583 | if (dev_priv->chipset == 0x41 || dev_priv->chipset == 0x42) { | ||
584 | b0_offset = 0x2200/4; /* 2200 */ | ||
585 | b1_offset = 0x4400/4; /* 0b00 */ | ||
586 | vs_len = 0x4f00/4; | ||
587 | } else { | ||
588 | b0_offset = 0x1d40/4; /* 2200 */ | ||
589 | b1_offset = 0x3f40/4; /* 0b00 : 0a40 */ | ||
590 | vs_len = nv40_graph_4097(dev) ? 0x4a40/4 : 0x4980/4; | ||
591 | } | ||
592 | |||
593 | cp_lsr(ctx, vs_len * vs_nr + 0x300/4); | ||
594 | cp_out(ctx, nv40_graph_4097(dev) ? 0x800041 : 0x800029); | ||
595 | |||
596 | offset = ctx->ctxvals_pos; | ||
597 | ctx->ctxvals_pos += (0x0300/4 + (vs_nr * vs_len)); | ||
598 | |||
599 | if (ctx->mode != NOUVEAU_GRCTX_VALS) | ||
600 | return; | ||
601 | |||
602 | offset += 0x0280/4; | ||
603 | for (i = 0; i < 16; i++, offset += 2) | ||
604 | nv_wo32(dev, obj, offset, 0x3f800000); | ||
605 | |||
606 | for (vs = 0; vs < vs_nr; vs++, offset += vs_len) { | ||
607 | for (i = 0; i < vs_nr_b0 * 6; i += 6) | ||
608 | nv_wo32(dev, obj, offset + b0_offset + i, 0x00000001); | ||
609 | for (i = 0; i < vs_nr_b1 * 4; i += 4) | ||
610 | nv_wo32(dev, obj, offset + b1_offset + i, 0x3f800000); | ||
611 | } | ||
612 | } | ||
613 | |||
614 | void | ||
615 | nv40_grctx_init(struct nouveau_grctx *ctx) | ||
616 | { | ||
617 | /* decide whether we're loading/unloading the context */ | ||
618 | cp_bra (ctx, AUTO_SAVE, PENDING, cp_setup_save); | ||
619 | cp_bra (ctx, USER_SAVE, PENDING, cp_setup_save); | ||
620 | |||
621 | cp_name(ctx, cp_check_load); | ||
622 | cp_bra (ctx, AUTO_LOAD, PENDING, cp_setup_auto_load); | ||
623 | cp_bra (ctx, USER_LOAD, PENDING, cp_setup_load); | ||
624 | cp_bra (ctx, ALWAYS, TRUE, cp_exit); | ||
625 | |||
626 | /* setup for context load */ | ||
627 | cp_name(ctx, cp_setup_auto_load); | ||
628 | cp_wait(ctx, STATUS, IDLE); | ||
629 | cp_out (ctx, CP_NEXT_TO_SWAP); | ||
630 | cp_name(ctx, cp_setup_load); | ||
631 | cp_wait(ctx, STATUS, IDLE); | ||
632 | cp_set (ctx, SWAP_DIRECTION, LOAD); | ||
633 | cp_out (ctx, 0x00910880); /* ?? */ | ||
634 | cp_out (ctx, 0x00901ffe); /* ?? */ | ||
635 | cp_out (ctx, 0x01940000); /* ?? */ | ||
636 | cp_lsr (ctx, 0x20); | ||
637 | cp_out (ctx, 0x0060000b); /* ?? */ | ||
638 | cp_wait(ctx, UNK57, CLEAR); | ||
639 | cp_out (ctx, 0x0060000c); /* ?? */ | ||
640 | cp_bra (ctx, ALWAYS, TRUE, cp_swap_state); | ||
641 | |||
642 | /* setup for context save */ | ||
643 | cp_name(ctx, cp_setup_save); | ||
644 | cp_set (ctx, SWAP_DIRECTION, SAVE); | ||
645 | |||
646 | /* general PGRAPH state */ | ||
647 | cp_name(ctx, cp_swap_state); | ||
648 | cp_pos (ctx, 0x00020/4); | ||
649 | nv40_graph_construct_general(ctx); | ||
650 | cp_wait(ctx, STATUS, IDLE); | ||
651 | |||
652 | /* 3D state, block 1 */ | ||
653 | cp_bra (ctx, UNK54, CLEAR, cp_prepare_exit); | ||
654 | nv40_graph_construct_state3d(ctx); | ||
655 | cp_wait(ctx, STATUS, IDLE); | ||
656 | |||
657 | /* 3D state, block 2 */ | ||
658 | nv40_graph_construct_state3d_2(ctx); | ||
659 | |||
660 | /* Some other block of "random" state */ | ||
661 | nv40_graph_construct_state3d_3(ctx); | ||
662 | |||
663 | /* Per-vertex shader state */ | ||
664 | cp_pos (ctx, ctx->ctxvals_pos); | ||
665 | nv40_graph_construct_shader(ctx); | ||
666 | |||
667 | /* pre-exit state updates */ | ||
668 | cp_name(ctx, cp_prepare_exit); | ||
669 | cp_bra (ctx, SWAP_DIRECTION, SAVE, cp_check_load); | ||
670 | cp_bra (ctx, USER_SAVE, PENDING, cp_exit); | ||
671 | cp_out (ctx, CP_NEXT_TO_CURRENT); | ||
672 | |||
673 | cp_name(ctx, cp_exit); | ||
674 | cp_set (ctx, USER_SAVE, NOT_PENDING); | ||
675 | cp_set (ctx, USER_LOAD, NOT_PENDING); | ||
676 | cp_out (ctx, CP_END); | ||
677 | } | ||
678 | |||
diff --git a/drivers/gpu/drm/nouveau/nv50_graph.c b/drivers/gpu/drm/nouveau/nv50_graph.c index 177d8229336f..ca79f32be44c 100644 --- a/drivers/gpu/drm/nouveau/nv50_graph.c +++ b/drivers/gpu/drm/nouveau/nv50_graph.c | |||
@@ -107,9 +107,13 @@ nv50_graph_init_regs(struct drm_device *dev) | |||
107 | static int | 107 | static int |
108 | nv50_graph_init_ctxctl(struct drm_device *dev) | 108 | nv50_graph_init_ctxctl(struct drm_device *dev) |
109 | { | 109 | { |
110 | struct drm_nouveau_private *dev_priv = dev->dev_private; | ||
111 | |||
110 | NV_DEBUG(dev, "\n"); | 112 | NV_DEBUG(dev, "\n"); |
111 | 113 | ||
112 | nv40_grctx_init(dev); | 114 | nouveau_grctx_prog_load(dev); |
115 | if (!dev_priv->engine.graph.ctxprog) | ||
116 | dev_priv->engine.graph.accel_blocked = true; | ||
113 | 117 | ||
114 | nv_wr32(dev, 0x400320, 4); | 118 | nv_wr32(dev, 0x400320, 4); |
115 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0); | 119 | nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0); |
@@ -140,7 +144,7 @@ void | |||
140 | nv50_graph_takedown(struct drm_device *dev) | 144 | nv50_graph_takedown(struct drm_device *dev) |
141 | { | 145 | { |
142 | NV_DEBUG(dev, "\n"); | 146 | NV_DEBUG(dev, "\n"); |
143 | nv40_grctx_fini(dev); | 147 | nouveau_grctx_fini(dev); |
144 | } | 148 | } |
145 | 149 | ||
146 | void | 150 | void |
@@ -207,7 +211,7 @@ nv50_graph_create_context(struct nouveau_channel *chan) | |||
207 | dev_priv->engine.instmem.finish_access(dev); | 211 | dev_priv->engine.instmem.finish_access(dev); |
208 | 212 | ||
209 | dev_priv->engine.instmem.prepare_access(dev, true); | 213 | dev_priv->engine.instmem.prepare_access(dev, true); |
210 | nv40_grctx_vals_load(dev, ctx); | 214 | nouveau_grctx_vals_load(dev, ctx); |
211 | nv_wo32(dev, ctx, 0x00000/4, chan->ramin->instance >> 12); | 215 | nv_wo32(dev, ctx, 0x00000/4, chan->ramin->instance >> 12); |
212 | if ((dev_priv->chipset & 0xf0) == 0xa0) | 216 | if ((dev_priv->chipset & 0xf0) == 0xa0) |
213 | nv_wo32(dev, ctx, 0x00004/4, 0x00000000); | 217 | nv_wo32(dev, ctx, 0x00004/4, 0x00000000); |