2 * Copyright (C) 2007 Arthur Huillet.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 * Arthur Huillet <arthur.huillet AT free DOT fr>
35 #include "nouveau_drm.h"
36 #include "nouveau_drv.h"
37 #include "nouveau_reg.h"
39 /*TODO: add a "card_type" attribute*/
41 uint32_t oclass
; /* object class for this software method */
42 uint32_t mthd
; /* method number */
43 void (*method_code
)(struct drm_device
*dev
, uint32_t oclass
, uint32_t mthd
); /* pointer to the function that does the work */
44 } nouveau_software_method_t
;
47 /* This function handles the NV04 setcontext software methods.
48 One function for all because they are very similar.*/
49 static void nouveau_NV04_setcontext_sw_method(struct drm_device
*dev
, uint32_t oclass
, uint32_t mthd
) {
50 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
51 uint32_t inst_loc
= NV_READ(NV04_PGRAPH_CTX_SWITCH4
) & 0xFFFF;
52 uint32_t value_to_set
= 0, bit_to_set
= 0;
62 bit_to_set
= 1 << 24; /*PATCH_STATUS_VALID*/
65 bit_to_set
= NV_READ(NV04_PGRAPH_TRAPPED_DATA
) << 15; /*PATCH_CONFIG = NV04_PGRAPH_TRAPPED_DATA*/
73 bit_to_set
= 1 << 13; /*USER_CLIP_ENABLE*/
80 bit_to_set
= 1 << 24; /*PATCH_STATUS_VALID*/
83 bit_to_set
= NV_READ(NV04_PGRAPH_TRAPPED_DATA
) << 15; /*PATCH_CONFIG = NV04_PGRAPH_TRAPPED_DATA*/
90 bit_to_set
= 1 << 12; /*CHROMA_KEY_ENABLE*/
93 bit_to_set
= 1 << 13; /*USER_CLIP_ENABLE*/
100 bit_to_set
= 1 << 24; /*PATCH_STATUS_VALID*/
103 bit_to_set
= NV_READ(NV04_PGRAPH_TRAPPED_DATA
) << 15; /*PATCH_CONFIG = NV04_PGRAPH_TRAPPED_DATA*/
110 bit_to_set
= 1 << 13; /*USER_CLIP_ENABLE*/
117 bit_to_set
= 1 << 24; /*PATCH_STATUS_VALID*/
120 bit_to_set
= NV_READ(NV04_PGRAPH_TRAPPED_DATA
) << 15; /*PATCH_CONFIG = NV04_PGRAPH_TRAPPED_DATA*/
127 bit_to_set
= 1 << 24; /*PATCH_STATUS_VALID*/
130 bit_to_set
= NV_READ(NV04_PGRAPH_TRAPPED_DATA
) << 15; //PATCH_CONFIG
137 value_to_set
= (NV_READ(0x00700000 | inst_loc
<< 4))| bit_to_set
;
140 nouveau_wait_for_idle(dev
);
141 NV_WRITE(0x00700000 | inst_loc
<< 4, value_to_set
);
143 /*DRM_DEBUG("CTX_SWITCH1 value is %#x\n", NV_READ(NV04_PGRAPH_CTX_SWITCH1));*/
144 NV_WRITE(NV04_PGRAPH_CTX_SWITCH1
, value_to_set
);
146 /*DRM_DEBUG("CTX_CACHE1 + xxx value is %#x\n", NV_READ(NV04_PGRAPH_CTX_CACHE1 + (((NV_READ(NV04_PGRAPH_TRAPPED_ADDR) >> 13) & 0x7) << 2)));*/
147 NV_WRITE(NV04_PGRAPH_CTX_CACHE1
+ (((NV_READ(NV04_PGRAPH_TRAPPED_ADDR
) >> 13) & 0x7) << 2), value_to_set
);
150 nouveau_software_method_t nouveau_sw_methods
[] = {
151 /*NV04 context software methods*/
152 { 0x4a, 0x188, nouveau_NV04_setcontext_sw_method
},
153 { 0x4a, 0x18c, nouveau_NV04_setcontext_sw_method
},
154 { 0x4a, 0x198, nouveau_NV04_setcontext_sw_method
},
155 { 0x4a, 0x2fc, nouveau_NV04_setcontext_sw_method
},
156 { 0x5c, 0x184, nouveau_NV04_setcontext_sw_method
},
157 { 0x5c, 0x188, nouveau_NV04_setcontext_sw_method
},
158 { 0x5c, 0x18c, nouveau_NV04_setcontext_sw_method
},
159 { 0x5c, 0x198, nouveau_NV04_setcontext_sw_method
},
160 { 0x5c, 0x2fc, nouveau_NV04_setcontext_sw_method
},
161 { 0x5f, 0x184, nouveau_NV04_setcontext_sw_method
},
162 { 0x5f, 0x188, nouveau_NV04_setcontext_sw_method
},
163 { 0x5f, 0x18c, nouveau_NV04_setcontext_sw_method
},
164 { 0x5f, 0x190, nouveau_NV04_setcontext_sw_method
},
165 { 0x5f, 0x19c, nouveau_NV04_setcontext_sw_method
},
166 { 0x5f, 0x2fc, nouveau_NV04_setcontext_sw_method
},
167 { 0x61, 0x188, nouveau_NV04_setcontext_sw_method
},
168 { 0x61, 0x18c, nouveau_NV04_setcontext_sw_method
},
169 { 0x61, 0x190, nouveau_NV04_setcontext_sw_method
},
170 { 0x61, 0x19c, nouveau_NV04_setcontext_sw_method
},
171 { 0x61, 0x2fc, nouveau_NV04_setcontext_sw_method
},
172 { 0x77, 0x198, nouveau_NV04_setcontext_sw_method
},
173 { 0x77, 0x304, nouveau_NV04_setcontext_sw_method
},
178 int nouveau_sw_method_execute(struct drm_device
*dev
, uint32_t oclass
, uint32_t method
) {
180 while ( nouveau_sw_methods
[ i
] . method_code
!= NULL
)
182 if ( nouveau_sw_methods
[ i
] . oclass
== oclass
&& nouveau_sw_methods
[ i
] . mthd
== method
)
184 nouveau_sw_methods
[ i
] . method_code(dev
, oclass
, method
);