Rev 6938 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6938 | Rev 7146 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright 2008 Advanced Micro Devices, Inc. |
2 | * Copyright 2008 Advanced Micro Devices, Inc. |
3 | * |
3 | * |
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
5 | * copy of this software and associated documentation files (the "Software"), |
5 | * copy of this software and associated documentation files (the "Software"), |
6 | * to deal in the Software without restriction, including without limitation |
6 | * to deal in the Software without restriction, including without limitation |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
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 |
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: |
9 | * Software is furnished to do so, subject to the following conditions: |
10 | * |
10 | * |
11 | * The above copyright notice and this permission notice shall be included in |
11 | * The above copyright notice and this permission notice shall be included in |
12 | * all copies or substantial portions of the Software. |
12 | * all copies or substantial portions of the Software. |
13 | * |
13 | * |
14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
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, |
15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
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 |
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, |
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 |
19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
20 | * OTHER DEALINGS IN THE SOFTWARE. |
20 | * OTHER DEALINGS IN THE SOFTWARE. |
21 | * |
21 | * |
22 | * Author: Stanislaw Skowronek |
22 | * Author: Stanislaw Skowronek |
23 | */ |
23 | */ |
24 | 24 | ||
25 | #include |
25 | #include |
26 | #include |
26 | #include |
27 | #include |
27 | #include |
28 | #include |
28 | #include |
29 | 29 | ||
30 | #define ATOM_DEBUG |
30 | #define ATOM_DEBUG |
31 | 31 | ||
32 | #include "atom.h" |
32 | #include "atom.h" |
33 | #include "atom-names.h" |
33 | #include "atom-names.h" |
34 | #include "atom-bits.h" |
34 | #include "atom-bits.h" |
35 | #include "radeon.h" |
35 | #include "radeon.h" |
36 | 36 | ||
37 | #define ATOM_COND_ABOVE 0 |
37 | #define ATOM_COND_ABOVE 0 |
38 | #define ATOM_COND_ABOVEOREQUAL 1 |
38 | #define ATOM_COND_ABOVEOREQUAL 1 |
39 | #define ATOM_COND_ALWAYS 2 |
39 | #define ATOM_COND_ALWAYS 2 |
40 | #define ATOM_COND_BELOW 3 |
40 | #define ATOM_COND_BELOW 3 |
41 | #define ATOM_COND_BELOWOREQUAL 4 |
41 | #define ATOM_COND_BELOWOREQUAL 4 |
42 | #define ATOM_COND_EQUAL 5 |
42 | #define ATOM_COND_EQUAL 5 |
43 | #define ATOM_COND_NOTEQUAL 6 |
43 | #define ATOM_COND_NOTEQUAL 6 |
44 | 44 | ||
45 | #define ATOM_PORT_ATI 0 |
45 | #define ATOM_PORT_ATI 0 |
46 | #define ATOM_PORT_PCI 1 |
46 | #define ATOM_PORT_PCI 1 |
47 | #define ATOM_PORT_SYSIO 2 |
47 | #define ATOM_PORT_SYSIO 2 |
48 | 48 | ||
49 | #define ATOM_UNIT_MICROSEC 0 |
49 | #define ATOM_UNIT_MICROSEC 0 |
50 | #define ATOM_UNIT_MILLISEC 1 |
50 | #define ATOM_UNIT_MILLISEC 1 |
51 | 51 | ||
52 | #define PLL_INDEX 2 |
52 | #define PLL_INDEX 2 |
53 | #define PLL_DATA 3 |
53 | #define PLL_DATA 3 |
54 | 54 | ||
55 | typedef struct { |
55 | typedef struct { |
56 | struct atom_context *ctx; |
56 | struct atom_context *ctx; |
57 | uint32_t *ps, *ws; |
57 | uint32_t *ps, *ws; |
58 | int ps_shift; |
58 | int ps_shift; |
59 | uint16_t start; |
59 | uint16_t start; |
60 | unsigned last_jump; |
60 | unsigned last_jump; |
61 | unsigned long last_jump_jiffies; |
61 | unsigned long last_jump_jiffies; |
62 | bool abort; |
62 | bool abort; |
63 | } atom_exec_context; |
63 | } atom_exec_context; |
64 | 64 | ||
65 | int atom_debug = 0; |
65 | int atom_debug = 0; |
66 | static int atom_execute_table_locked(struct atom_context *ctx, int index, uint32_t * params); |
66 | static int atom_execute_table_locked(struct atom_context *ctx, int index, uint32_t * params); |
67 | int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params); |
67 | int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params); |
68 | 68 | ||
69 | static uint32_t atom_arg_mask[8] = |
69 | static uint32_t atom_arg_mask[8] = { |
70 | { 0xFFFFFFFF, 0xFFFF, 0xFFFF00, 0xFFFF0000, 0xFF, 0xFF00, 0xFF0000, |
70 | 0xFFFFFFFF, 0x0000FFFF, 0x00FFFF00, 0xFFFF0000, |
- | 71 | 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000 |
|
71 | 0xFF000000 }; |
72 | }; |
72 | static int atom_arg_shift[8] = { 0, 0, 8, 16, 0, 8, 16, 24 }; |
73 | static int atom_arg_shift[8] = { 0, 0, 8, 16, 0, 8, 16, 24 }; |
73 | 74 | ||
74 | static int atom_dst_to_src[8][4] = { |
75 | static int atom_dst_to_src[8][4] = { |
75 | /* translate destination alignment field to the source alignment encoding */ |
76 | /* translate destination alignment field to the source alignment encoding */ |
76 | {0, 0, 0, 0}, |
77 | {0, 0, 0, 0}, |
77 | {1, 2, 3, 0}, |
78 | {1, 2, 3, 0}, |
78 | {1, 2, 3, 0}, |
79 | {1, 2, 3, 0}, |
79 | {1, 2, 3, 0}, |
80 | {1, 2, 3, 0}, |
80 | {4, 5, 6, 7}, |
81 | {4, 5, 6, 7}, |
81 | {4, 5, 6, 7}, |
82 | {4, 5, 6, 7}, |
82 | {4, 5, 6, 7}, |
83 | {4, 5, 6, 7}, |
83 | {4, 5, 6, 7}, |
84 | {4, 5, 6, 7}, |
84 | }; |
85 | }; |
85 | static int atom_def_dst[8] = { 0, 0, 1, 2, 0, 1, 2, 3 }; |
86 | static int atom_def_dst[8] = { 0, 0, 1, 2, 0, 1, 2, 3 }; |
86 | 87 | ||
87 | static int debug_depth = 0; |
88 | static int debug_depth = 0; |
88 | #ifdef ATOM_DEBUG |
89 | #ifdef ATOM_DEBUG |
89 | static void debug_print_spaces(int n) |
90 | static void debug_print_spaces(int n) |
90 | { |
91 | { |
91 | while (n--) |
92 | while (n--) |
92 | printk(" "); |
93 | printk(" "); |
93 | } |
94 | } |
94 | 95 | ||
95 | #define DEBUG(...) do if (atom_debug) { printk(KERN_DEBUG __VA_ARGS__); } while (0) |
96 | #define DEBUG(...) do if (atom_debug) { printk(KERN_DEBUG __VA_ARGS__); } while (0) |
96 | #define SDEBUG(...) do if (atom_debug) { printk(KERN_DEBUG); debug_print_spaces(debug_depth); printk(__VA_ARGS__); } while (0) |
97 | #define SDEBUG(...) do if (atom_debug) { printk(KERN_DEBUG); debug_print_spaces(debug_depth); printk(__VA_ARGS__); } while (0) |
97 | #else |
98 | #else |
98 | #define DEBUG(...) do { } while (0) |
99 | #define DEBUG(...) do { } while (0) |
99 | #define SDEBUG(...) do { } while (0) |
100 | #define SDEBUG(...) do { } while (0) |
100 | #endif |
101 | #endif |
101 | 102 | ||
102 | static uint32_t atom_iio_execute(struct atom_context *ctx, int base, |
103 | static uint32_t atom_iio_execute(struct atom_context *ctx, int base, |
103 | uint32_t index, uint32_t data) |
104 | uint32_t index, uint32_t data) |
104 | { |
105 | { |
105 | struct radeon_device *rdev = ctx->card->dev->dev_private; |
106 | struct radeon_device *rdev = ctx->card->dev->dev_private; |
106 | uint32_t temp = 0xCDCDCDCD; |
107 | uint32_t temp = 0xCDCDCDCD; |
107 | 108 | ||
108 | while (1) |
109 | while (1) |
109 | switch (CU8(base)) { |
110 | switch (CU8(base)) { |
110 | case ATOM_IIO_NOP: |
111 | case ATOM_IIO_NOP: |
111 | base++; |
112 | base++; |
112 | break; |
113 | break; |
113 | case ATOM_IIO_READ: |
114 | case ATOM_IIO_READ: |
114 | temp = ctx->card->ioreg_read(ctx->card, CU16(base + 1)); |
115 | temp = ctx->card->ioreg_read(ctx->card, CU16(base + 1)); |
115 | base += 3; |
116 | base += 3; |
116 | break; |
117 | break; |
117 | case ATOM_IIO_WRITE: |
118 | case ATOM_IIO_WRITE: |
118 | if (rdev->family == CHIP_RV515) |
119 | if (rdev->family == CHIP_RV515) |
119 | (void)ctx->card->ioreg_read(ctx->card, CU16(base + 1)); |
120 | (void)ctx->card->ioreg_read(ctx->card, CU16(base + 1)); |
120 | ctx->card->ioreg_write(ctx->card, CU16(base + 1), temp); |
121 | ctx->card->ioreg_write(ctx->card, CU16(base + 1), temp); |
121 | base += 3; |
122 | base += 3; |
122 | break; |
123 | break; |
123 | case ATOM_IIO_CLEAR: |
124 | case ATOM_IIO_CLEAR: |
124 | temp &= |
125 | temp &= |
125 | ~((0xFFFFFFFF >> (32 - CU8(base + 1))) << |
126 | ~((0xFFFFFFFF >> (32 - CU8(base + 1))) << |
126 | CU8(base + 2)); |
127 | CU8(base + 2)); |
127 | base += 3; |
128 | base += 3; |
128 | break; |
129 | break; |
129 | case ATOM_IIO_SET: |
130 | case ATOM_IIO_SET: |
130 | temp |= |
131 | temp |= |
131 | (0xFFFFFFFF >> (32 - CU8(base + 1))) << CU8(base + |
132 | (0xFFFFFFFF >> (32 - CU8(base + 1))) << CU8(base + |
132 | 2); |
133 | 2); |
133 | base += 3; |
134 | base += 3; |
134 | break; |
135 | break; |
135 | case ATOM_IIO_MOVE_INDEX: |
136 | case ATOM_IIO_MOVE_INDEX: |
136 | temp &= |
137 | temp &= |
137 | ~((0xFFFFFFFF >> (32 - CU8(base + 1))) << |
138 | ~((0xFFFFFFFF >> (32 - CU8(base + 1))) << |
138 | CU8(base + 3)); |
139 | CU8(base + 3)); |
139 | temp |= |
140 | temp |= |
140 | ((index >> CU8(base + 2)) & |
141 | ((index >> CU8(base + 2)) & |
141 | (0xFFFFFFFF >> (32 - CU8(base + 1)))) << CU8(base + |
142 | (0xFFFFFFFF >> (32 - CU8(base + 1)))) << CU8(base + |
142 | 3); |
143 | 3); |
143 | base += 4; |
144 | base += 4; |
144 | break; |
145 | break; |
145 | case ATOM_IIO_MOVE_DATA: |
146 | case ATOM_IIO_MOVE_DATA: |
146 | temp &= |
147 | temp &= |
147 | ~((0xFFFFFFFF >> (32 - CU8(base + 1))) << |
148 | ~((0xFFFFFFFF >> (32 - CU8(base + 1))) << |
148 | CU8(base + 3)); |
149 | CU8(base + 3)); |
149 | temp |= |
150 | temp |= |
150 | ((data >> CU8(base + 2)) & |
151 | ((data >> CU8(base + 2)) & |
151 | (0xFFFFFFFF >> (32 - CU8(base + 1)))) << CU8(base + |
152 | (0xFFFFFFFF >> (32 - CU8(base + 1)))) << CU8(base + |
152 | 3); |
153 | 3); |
153 | base += 4; |
154 | base += 4; |
154 | break; |
155 | break; |
155 | case ATOM_IIO_MOVE_ATTR: |
156 | case ATOM_IIO_MOVE_ATTR: |
156 | temp &= |
157 | temp &= |
157 | ~((0xFFFFFFFF >> (32 - CU8(base + 1))) << |
158 | ~((0xFFFFFFFF >> (32 - CU8(base + 1))) << |
158 | CU8(base + 3)); |
159 | CU8(base + 3)); |
159 | temp |= |
160 | temp |= |
160 | ((ctx-> |
161 | ((ctx-> |
161 | io_attr >> CU8(base + 2)) & (0xFFFFFFFF >> (32 - |
162 | io_attr >> CU8(base + 2)) & (0xFFFFFFFF >> (32 - |
162 | CU8 |
163 | CU8 |
163 | (base |
164 | (base |
164 | + |
165 | + |
165 | 1)))) |
166 | 1)))) |
166 | << CU8(base + 3); |
167 | << CU8(base + 3); |
167 | base += 4; |
168 | base += 4; |
168 | break; |
169 | break; |
169 | case ATOM_IIO_END: |
170 | case ATOM_IIO_END: |
170 | return temp; |
171 | return temp; |
171 | default: |
172 | default: |
172 | printk(KERN_INFO "Unknown IIO opcode.\n"); |
173 | printk(KERN_INFO "Unknown IIO opcode.\n"); |
173 | return 0; |
174 | return 0; |
174 | } |
175 | } |
175 | } |
176 | } |
176 | 177 | ||
177 | static uint32_t atom_get_src_int(atom_exec_context *ctx, uint8_t attr, |
178 | static uint32_t atom_get_src_int(atom_exec_context *ctx, uint8_t attr, |
178 | int *ptr, uint32_t *saved, int print) |
179 | int *ptr, uint32_t *saved, int print) |
179 | { |
180 | { |
180 | uint32_t idx, val = 0xCDCDCDCD, align, arg; |
181 | uint32_t idx, val = 0xCDCDCDCD, align, arg; |
181 | struct atom_context *gctx = ctx->ctx; |
182 | struct atom_context *gctx = ctx->ctx; |
182 | arg = attr & 7; |
183 | arg = attr & 7; |
183 | align = (attr >> 3) & 7; |
184 | align = (attr >> 3) & 7; |
184 | switch (arg) { |
185 | switch (arg) { |
185 | case ATOM_ARG_REG: |
186 | case ATOM_ARG_REG: |
186 | idx = U16(*ptr); |
187 | idx = U16(*ptr); |
187 | (*ptr) += 2; |
188 | (*ptr) += 2; |
188 | if (print) |
189 | if (print) |
189 | DEBUG("REG[0x%04X]", idx); |
190 | DEBUG("REG[0x%04X]", idx); |
190 | idx += gctx->reg_block; |
191 | idx += gctx->reg_block; |
191 | switch (gctx->io_mode) { |
192 | switch (gctx->io_mode) { |
192 | case ATOM_IO_MM: |
193 | case ATOM_IO_MM: |
193 | val = gctx->card->reg_read(gctx->card, idx); |
194 | val = gctx->card->reg_read(gctx->card, idx); |
194 | break; |
195 | break; |
195 | case ATOM_IO_PCI: |
196 | case ATOM_IO_PCI: |
196 | printk(KERN_INFO |
197 | printk(KERN_INFO |
197 | "PCI registers are not implemented.\n"); |
198 | "PCI registers are not implemented.\n"); |
198 | return 0; |
199 | return 0; |
199 | case ATOM_IO_SYSIO: |
200 | case ATOM_IO_SYSIO: |
200 | printk(KERN_INFO |
201 | printk(KERN_INFO |
201 | "SYSIO registers are not implemented.\n"); |
202 | "SYSIO registers are not implemented.\n"); |
202 | return 0; |
203 | return 0; |
203 | default: |
204 | default: |
204 | if (!(gctx->io_mode & 0x80)) { |
205 | if (!(gctx->io_mode & 0x80)) { |
205 | printk(KERN_INFO "Bad IO mode.\n"); |
206 | printk(KERN_INFO "Bad IO mode.\n"); |
206 | return 0; |
207 | return 0; |
207 | } |
208 | } |
208 | if (!gctx->iio[gctx->io_mode & 0x7F]) { |
209 | if (!gctx->iio[gctx->io_mode & 0x7F]) { |
209 | printk(KERN_INFO |
210 | printk(KERN_INFO |
210 | "Undefined indirect IO read method %d.\n", |
211 | "Undefined indirect IO read method %d.\n", |
211 | gctx->io_mode & 0x7F); |
212 | gctx->io_mode & 0x7F); |
212 | return 0; |
213 | return 0; |
213 | } |
214 | } |
214 | val = |
215 | val = |
215 | atom_iio_execute(gctx, |
216 | atom_iio_execute(gctx, |
216 | gctx->iio[gctx->io_mode & 0x7F], |
217 | gctx->iio[gctx->io_mode & 0x7F], |
217 | idx, 0); |
218 | idx, 0); |
218 | } |
219 | } |
219 | break; |
220 | break; |
220 | case ATOM_ARG_PS: |
221 | case ATOM_ARG_PS: |
221 | idx = U8(*ptr); |
222 | idx = U8(*ptr); |
222 | (*ptr)++; |
223 | (*ptr)++; |
223 | /* get_unaligned_le32 avoids unaligned accesses from atombios |
224 | /* get_unaligned_le32 avoids unaligned accesses from atombios |
224 | * tables, noticed on a DEC Alpha. */ |
225 | * tables, noticed on a DEC Alpha. */ |
225 | val = get_unaligned_le32((u32 *)&ctx->ps[idx]); |
226 | val = get_unaligned_le32((u32 *)&ctx->ps[idx]); |
226 | if (print) |
227 | if (print) |
227 | DEBUG("PS[0x%02X,0x%04X]", idx, val); |
228 | DEBUG("PS[0x%02X,0x%04X]", idx, val); |
228 | break; |
229 | break; |
229 | case ATOM_ARG_WS: |
230 | case ATOM_ARG_WS: |
230 | idx = U8(*ptr); |
231 | idx = U8(*ptr); |
231 | (*ptr)++; |
232 | (*ptr)++; |
232 | if (print) |
233 | if (print) |
233 | DEBUG("WS[0x%02X]", idx); |
234 | DEBUG("WS[0x%02X]", idx); |
234 | switch (idx) { |
235 | switch (idx) { |
235 | case ATOM_WS_QUOTIENT: |
236 | case ATOM_WS_QUOTIENT: |
236 | val = gctx->divmul[0]; |
237 | val = gctx->divmul[0]; |
237 | break; |
238 | break; |
238 | case ATOM_WS_REMAINDER: |
239 | case ATOM_WS_REMAINDER: |
239 | val = gctx->divmul[1]; |
240 | val = gctx->divmul[1]; |
240 | break; |
241 | break; |
241 | case ATOM_WS_DATAPTR: |
242 | case ATOM_WS_DATAPTR: |
242 | val = gctx->data_block; |
243 | val = gctx->data_block; |
243 | break; |
244 | break; |
244 | case ATOM_WS_SHIFT: |
245 | case ATOM_WS_SHIFT: |
245 | val = gctx->shift; |
246 | val = gctx->shift; |
246 | break; |
247 | break; |
247 | case ATOM_WS_OR_MASK: |
248 | case ATOM_WS_OR_MASK: |
248 | val = 1 << gctx->shift; |
249 | val = 1 << gctx->shift; |
249 | break; |
250 | break; |
250 | case ATOM_WS_AND_MASK: |
251 | case ATOM_WS_AND_MASK: |
251 | val = ~(1 << gctx->shift); |
252 | val = ~(1 << gctx->shift); |
252 | break; |
253 | break; |
253 | case ATOM_WS_FB_WINDOW: |
254 | case ATOM_WS_FB_WINDOW: |
254 | val = gctx->fb_base; |
255 | val = gctx->fb_base; |
255 | break; |
256 | break; |
256 | case ATOM_WS_ATTRIBUTES: |
257 | case ATOM_WS_ATTRIBUTES: |
257 | val = gctx->io_attr; |
258 | val = gctx->io_attr; |
258 | break; |
259 | break; |
259 | case ATOM_WS_REGPTR: |
260 | case ATOM_WS_REGPTR: |
260 | val = gctx->reg_block; |
261 | val = gctx->reg_block; |
261 | break; |
262 | break; |
262 | default: |
263 | default: |
263 | val = ctx->ws[idx]; |
264 | val = ctx->ws[idx]; |
264 | } |
265 | } |
265 | break; |
266 | break; |
266 | case ATOM_ARG_ID: |
267 | case ATOM_ARG_ID: |
267 | idx = U16(*ptr); |
268 | idx = U16(*ptr); |
268 | (*ptr) += 2; |
269 | (*ptr) += 2; |
269 | if (print) { |
270 | if (print) { |
270 | if (gctx->data_block) |
271 | if (gctx->data_block) |
271 | DEBUG("ID[0x%04X+%04X]", idx, gctx->data_block); |
272 | DEBUG("ID[0x%04X+%04X]", idx, gctx->data_block); |
272 | else |
273 | else |
273 | DEBUG("ID[0x%04X]", idx); |
274 | DEBUG("ID[0x%04X]", idx); |
274 | } |
275 | } |
275 | val = U32(idx + gctx->data_block); |
276 | val = U32(idx + gctx->data_block); |
276 | break; |
277 | break; |
277 | case ATOM_ARG_FB: |
278 | case ATOM_ARG_FB: |
278 | idx = U8(*ptr); |
279 | idx = U8(*ptr); |
279 | (*ptr)++; |
280 | (*ptr)++; |
280 | if ((gctx->fb_base + (idx * 4)) > gctx->scratch_size_bytes) { |
281 | if ((gctx->fb_base + (idx * 4)) > gctx->scratch_size_bytes) { |
281 | DRM_ERROR("ATOM: fb read beyond scratch region: %d vs. %d\n", |
282 | DRM_ERROR("ATOM: fb read beyond scratch region: %d vs. %d\n", |
282 | gctx->fb_base + (idx * 4), gctx->scratch_size_bytes); |
283 | gctx->fb_base + (idx * 4), gctx->scratch_size_bytes); |
283 | val = 0; |
284 | val = 0; |
284 | } else |
285 | } else |
285 | val = gctx->scratch[(gctx->fb_base / 4) + idx]; |
286 | val = gctx->scratch[(gctx->fb_base / 4) + idx]; |
286 | if (print) |
287 | if (print) |
287 | DEBUG("FB[0x%02X]", idx); |
288 | DEBUG("FB[0x%02X]", idx); |
288 | break; |
289 | break; |
289 | case ATOM_ARG_IMM: |
290 | case ATOM_ARG_IMM: |
290 | switch (align) { |
291 | switch (align) { |
291 | case ATOM_SRC_DWORD: |
292 | case ATOM_SRC_DWORD: |
292 | val = U32(*ptr); |
293 | val = U32(*ptr); |
293 | (*ptr) += 4; |
294 | (*ptr) += 4; |
294 | if (print) |
295 | if (print) |
295 | DEBUG("IMM 0x%08X\n", val); |
296 | DEBUG("IMM 0x%08X\n", val); |
296 | return val; |
297 | return val; |
297 | case ATOM_SRC_WORD0: |
298 | case ATOM_SRC_WORD0: |
298 | case ATOM_SRC_WORD8: |
299 | case ATOM_SRC_WORD8: |
299 | case ATOM_SRC_WORD16: |
300 | case ATOM_SRC_WORD16: |
300 | val = U16(*ptr); |
301 | val = U16(*ptr); |
301 | (*ptr) += 2; |
302 | (*ptr) += 2; |
302 | if (print) |
303 | if (print) |
303 | DEBUG("IMM 0x%04X\n", val); |
304 | DEBUG("IMM 0x%04X\n", val); |
304 | return val; |
305 | return val; |
305 | case ATOM_SRC_BYTE0: |
306 | case ATOM_SRC_BYTE0: |
306 | case ATOM_SRC_BYTE8: |
307 | case ATOM_SRC_BYTE8: |
307 | case ATOM_SRC_BYTE16: |
308 | case ATOM_SRC_BYTE16: |
308 | case ATOM_SRC_BYTE24: |
309 | case ATOM_SRC_BYTE24: |
309 | val = U8(*ptr); |
310 | val = U8(*ptr); |
310 | (*ptr)++; |
311 | (*ptr)++; |
311 | if (print) |
312 | if (print) |
312 | DEBUG("IMM 0x%02X\n", val); |
313 | DEBUG("IMM 0x%02X\n", val); |
313 | return val; |
314 | return val; |
314 | } |
315 | } |
315 | return 0; |
316 | return 0; |
316 | case ATOM_ARG_PLL: |
317 | case ATOM_ARG_PLL: |
317 | idx = U8(*ptr); |
318 | idx = U8(*ptr); |
318 | (*ptr)++; |
319 | (*ptr)++; |
319 | if (print) |
320 | if (print) |
320 | DEBUG("PLL[0x%02X]", idx); |
321 | DEBUG("PLL[0x%02X]", idx); |
321 | val = gctx->card->pll_read(gctx->card, idx); |
322 | val = gctx->card->pll_read(gctx->card, idx); |
322 | break; |
323 | break; |
323 | case ATOM_ARG_MC: |
324 | case ATOM_ARG_MC: |
324 | idx = U8(*ptr); |
325 | idx = U8(*ptr); |
325 | (*ptr)++; |
326 | (*ptr)++; |
326 | if (print) |
327 | if (print) |
327 | DEBUG("MC[0x%02X]", idx); |
328 | DEBUG("MC[0x%02X]", idx); |
328 | val = gctx->card->mc_read(gctx->card, idx); |
329 | val = gctx->card->mc_read(gctx->card, idx); |
329 | break; |
330 | break; |
330 | } |
331 | } |
331 | if (saved) |
332 | if (saved) |
332 | *saved = val; |
333 | *saved = val; |
333 | val &= atom_arg_mask[align]; |
334 | val &= atom_arg_mask[align]; |
334 | val >>= atom_arg_shift[align]; |
335 | val >>= atom_arg_shift[align]; |
335 | if (print) |
336 | if (print) |
336 | switch (align) { |
337 | switch (align) { |
337 | case ATOM_SRC_DWORD: |
338 | case ATOM_SRC_DWORD: |
338 | DEBUG(".[31:0] -> 0x%08X\n", val); |
339 | DEBUG(".[31:0] -> 0x%08X\n", val); |
339 | break; |
340 | break; |
340 | case ATOM_SRC_WORD0: |
341 | case ATOM_SRC_WORD0: |
341 | DEBUG(".[15:0] -> 0x%04X\n", val); |
342 | DEBUG(".[15:0] -> 0x%04X\n", val); |
342 | break; |
343 | break; |
343 | case ATOM_SRC_WORD8: |
344 | case ATOM_SRC_WORD8: |
344 | DEBUG(".[23:8] -> 0x%04X\n", val); |
345 | DEBUG(".[23:8] -> 0x%04X\n", val); |
345 | break; |
346 | break; |
346 | case ATOM_SRC_WORD16: |
347 | case ATOM_SRC_WORD16: |
347 | DEBUG(".[31:16] -> 0x%04X\n", val); |
348 | DEBUG(".[31:16] -> 0x%04X\n", val); |
348 | break; |
349 | break; |
349 | case ATOM_SRC_BYTE0: |
350 | case ATOM_SRC_BYTE0: |
350 | DEBUG(".[7:0] -> 0x%02X\n", val); |
351 | DEBUG(".[7:0] -> 0x%02X\n", val); |
351 | break; |
352 | break; |
352 | case ATOM_SRC_BYTE8: |
353 | case ATOM_SRC_BYTE8: |
353 | DEBUG(".[15:8] -> 0x%02X\n", val); |
354 | DEBUG(".[15:8] -> 0x%02X\n", val); |
354 | break; |
355 | break; |
355 | case ATOM_SRC_BYTE16: |
356 | case ATOM_SRC_BYTE16: |
356 | DEBUG(".[23:16] -> 0x%02X\n", val); |
357 | DEBUG(".[23:16] -> 0x%02X\n", val); |
357 | break; |
358 | break; |
358 | case ATOM_SRC_BYTE24: |
359 | case ATOM_SRC_BYTE24: |
359 | DEBUG(".[31:24] -> 0x%02X\n", val); |
360 | DEBUG(".[31:24] -> 0x%02X\n", val); |
360 | break; |
361 | break; |
361 | } |
362 | } |
362 | return val; |
363 | return val; |
363 | } |
364 | } |
364 | 365 | ||
365 | static void atom_skip_src_int(atom_exec_context *ctx, uint8_t attr, int *ptr) |
366 | static void atom_skip_src_int(atom_exec_context *ctx, uint8_t attr, int *ptr) |
366 | { |
367 | { |
367 | uint32_t align = (attr >> 3) & 7, arg = attr & 7; |
368 | uint32_t align = (attr >> 3) & 7, arg = attr & 7; |
368 | switch (arg) { |
369 | switch (arg) { |
369 | case ATOM_ARG_REG: |
370 | case ATOM_ARG_REG: |
370 | case ATOM_ARG_ID: |
371 | case ATOM_ARG_ID: |
371 | (*ptr) += 2; |
372 | (*ptr) += 2; |
372 | break; |
373 | break; |
373 | case ATOM_ARG_PLL: |
374 | case ATOM_ARG_PLL: |
374 | case ATOM_ARG_MC: |
375 | case ATOM_ARG_MC: |
375 | case ATOM_ARG_PS: |
376 | case ATOM_ARG_PS: |
376 | case ATOM_ARG_WS: |
377 | case ATOM_ARG_WS: |
377 | case ATOM_ARG_FB: |
378 | case ATOM_ARG_FB: |
378 | (*ptr)++; |
379 | (*ptr)++; |
379 | break; |
380 | break; |
380 | case ATOM_ARG_IMM: |
381 | case ATOM_ARG_IMM: |
381 | switch (align) { |
382 | switch (align) { |
382 | case ATOM_SRC_DWORD: |
383 | case ATOM_SRC_DWORD: |
383 | (*ptr) += 4; |
384 | (*ptr) += 4; |
384 | return; |
385 | return; |
385 | case ATOM_SRC_WORD0: |
386 | case ATOM_SRC_WORD0: |
386 | case ATOM_SRC_WORD8: |
387 | case ATOM_SRC_WORD8: |
387 | case ATOM_SRC_WORD16: |
388 | case ATOM_SRC_WORD16: |
388 | (*ptr) += 2; |
389 | (*ptr) += 2; |
389 | return; |
390 | return; |
390 | case ATOM_SRC_BYTE0: |
391 | case ATOM_SRC_BYTE0: |
391 | case ATOM_SRC_BYTE8: |
392 | case ATOM_SRC_BYTE8: |
392 | case ATOM_SRC_BYTE16: |
393 | case ATOM_SRC_BYTE16: |
393 | case ATOM_SRC_BYTE24: |
394 | case ATOM_SRC_BYTE24: |
394 | (*ptr)++; |
395 | (*ptr)++; |
395 | return; |
396 | return; |
396 | } |
397 | } |
397 | return; |
398 | return; |
398 | } |
399 | } |
399 | } |
400 | } |
400 | 401 | ||
401 | static uint32_t atom_get_src(atom_exec_context *ctx, uint8_t attr, int *ptr) |
402 | static uint32_t atom_get_src(atom_exec_context *ctx, uint8_t attr, int *ptr) |
402 | { |
403 | { |
403 | return atom_get_src_int(ctx, attr, ptr, NULL, 1); |
404 | return atom_get_src_int(ctx, attr, ptr, NULL, 1); |
404 | } |
405 | } |
405 | 406 | ||
406 | static uint32_t atom_get_src_direct(atom_exec_context *ctx, uint8_t align, int *ptr) |
407 | static uint32_t atom_get_src_direct(atom_exec_context *ctx, uint8_t align, int *ptr) |
407 | { |
408 | { |
408 | uint32_t val = 0xCDCDCDCD; |
409 | uint32_t val = 0xCDCDCDCD; |
409 | 410 | ||
410 | switch (align) { |
411 | switch (align) { |
411 | case ATOM_SRC_DWORD: |
412 | case ATOM_SRC_DWORD: |
412 | val = U32(*ptr); |
413 | val = U32(*ptr); |
413 | (*ptr) += 4; |
414 | (*ptr) += 4; |
414 | break; |
415 | break; |
415 | case ATOM_SRC_WORD0: |
416 | case ATOM_SRC_WORD0: |
416 | case ATOM_SRC_WORD8: |
417 | case ATOM_SRC_WORD8: |
417 | case ATOM_SRC_WORD16: |
418 | case ATOM_SRC_WORD16: |
418 | val = U16(*ptr); |
419 | val = U16(*ptr); |
419 | (*ptr) += 2; |
420 | (*ptr) += 2; |
420 | break; |
421 | break; |
421 | case ATOM_SRC_BYTE0: |
422 | case ATOM_SRC_BYTE0: |
422 | case ATOM_SRC_BYTE8: |
423 | case ATOM_SRC_BYTE8: |
423 | case ATOM_SRC_BYTE16: |
424 | case ATOM_SRC_BYTE16: |
424 | case ATOM_SRC_BYTE24: |
425 | case ATOM_SRC_BYTE24: |
425 | val = U8(*ptr); |
426 | val = U8(*ptr); |
426 | (*ptr)++; |
427 | (*ptr)++; |
427 | break; |
428 | break; |
428 | } |
429 | } |
429 | return val; |
430 | return val; |
430 | } |
431 | } |
431 | 432 | ||
432 | static uint32_t atom_get_dst(atom_exec_context *ctx, int arg, uint8_t attr, |
433 | static uint32_t atom_get_dst(atom_exec_context *ctx, int arg, uint8_t attr, |
433 | int *ptr, uint32_t *saved, int print) |
434 | int *ptr, uint32_t *saved, int print) |
434 | { |
435 | { |
435 | return atom_get_src_int(ctx, |
436 | return atom_get_src_int(ctx, |
436 | arg | atom_dst_to_src[(attr >> 3) & |
437 | arg | atom_dst_to_src[(attr >> 3) & |
437 | 7][(attr >> 6) & 3] << 3, |
438 | 7][(attr >> 6) & 3] << 3, |
438 | ptr, saved, print); |
439 | ptr, saved, print); |
439 | } |
440 | } |
440 | 441 | ||
441 | static void atom_skip_dst(atom_exec_context *ctx, int arg, uint8_t attr, int *ptr) |
442 | static void atom_skip_dst(atom_exec_context *ctx, int arg, uint8_t attr, int *ptr) |
442 | { |
443 | { |
443 | atom_skip_src_int(ctx, |
444 | atom_skip_src_int(ctx, |
444 | arg | atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) & |
445 | arg | atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) & |
445 | 3] << 3, ptr); |
446 | 3] << 3, ptr); |
446 | } |
447 | } |
447 | 448 | ||
448 | static void atom_put_dst(atom_exec_context *ctx, int arg, uint8_t attr, |
449 | static void atom_put_dst(atom_exec_context *ctx, int arg, uint8_t attr, |
449 | int *ptr, uint32_t val, uint32_t saved) |
450 | int *ptr, uint32_t val, uint32_t saved) |
450 | { |
451 | { |
451 | uint32_t align = |
452 | uint32_t align = |
452 | atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) & 3], old_val = |
453 | atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) & 3], old_val = |
453 | val, idx; |
454 | val, idx; |
454 | struct atom_context *gctx = ctx->ctx; |
455 | struct atom_context *gctx = ctx->ctx; |
455 | old_val &= atom_arg_mask[align] >> atom_arg_shift[align]; |
456 | old_val &= atom_arg_mask[align] >> atom_arg_shift[align]; |
456 | val <<= atom_arg_shift[align]; |
457 | val <<= atom_arg_shift[align]; |
457 | val &= atom_arg_mask[align]; |
458 | val &= atom_arg_mask[align]; |
458 | saved &= ~atom_arg_mask[align]; |
459 | saved &= ~atom_arg_mask[align]; |
459 | val |= saved; |
460 | val |= saved; |
460 | switch (arg) { |
461 | switch (arg) { |
461 | case ATOM_ARG_REG: |
462 | case ATOM_ARG_REG: |
462 | idx = U16(*ptr); |
463 | idx = U16(*ptr); |
463 | (*ptr) += 2; |
464 | (*ptr) += 2; |
464 | DEBUG("REG[0x%04X]", idx); |
465 | DEBUG("REG[0x%04X]", idx); |
465 | idx += gctx->reg_block; |
466 | idx += gctx->reg_block; |
466 | switch (gctx->io_mode) { |
467 | switch (gctx->io_mode) { |
467 | case ATOM_IO_MM: |
468 | case ATOM_IO_MM: |
468 | if (idx == 0) |
469 | if (idx == 0) |
469 | gctx->card->reg_write(gctx->card, idx, |
470 | gctx->card->reg_write(gctx->card, idx, |
470 | val << 2); |
471 | val << 2); |
471 | else |
472 | else |
472 | gctx->card->reg_write(gctx->card, idx, val); |
473 | gctx->card->reg_write(gctx->card, idx, val); |
473 | break; |
474 | break; |
474 | case ATOM_IO_PCI: |
475 | case ATOM_IO_PCI: |
475 | printk(KERN_INFO |
476 | printk(KERN_INFO |
476 | "PCI registers are not implemented.\n"); |
477 | "PCI registers are not implemented.\n"); |
477 | return; |
478 | return; |
478 | case ATOM_IO_SYSIO: |
479 | case ATOM_IO_SYSIO: |
479 | printk(KERN_INFO |
480 | printk(KERN_INFO |
480 | "SYSIO registers are not implemented.\n"); |
481 | "SYSIO registers are not implemented.\n"); |
481 | return; |
482 | return; |
482 | default: |
483 | default: |
483 | if (!(gctx->io_mode & 0x80)) { |
484 | if (!(gctx->io_mode & 0x80)) { |
484 | printk(KERN_INFO "Bad IO mode.\n"); |
485 | printk(KERN_INFO "Bad IO mode.\n"); |
485 | return; |
486 | return; |
486 | } |
487 | } |
487 | if (!gctx->iio[gctx->io_mode & 0xFF]) { |
488 | if (!gctx->iio[gctx->io_mode & 0xFF]) { |
488 | printk(KERN_INFO |
489 | printk(KERN_INFO |
489 | "Undefined indirect IO write method %d.\n", |
490 | "Undefined indirect IO write method %d.\n", |
490 | gctx->io_mode & 0x7F); |
491 | gctx->io_mode & 0x7F); |
491 | return; |
492 | return; |
492 | } |
493 | } |
493 | atom_iio_execute(gctx, gctx->iio[gctx->io_mode & 0xFF], |
494 | atom_iio_execute(gctx, gctx->iio[gctx->io_mode & 0xFF], |
494 | idx, val); |
495 | idx, val); |
495 | } |
496 | } |
496 | break; |
497 | break; |
497 | case ATOM_ARG_PS: |
498 | case ATOM_ARG_PS: |
498 | idx = U8(*ptr); |
499 | idx = U8(*ptr); |
499 | (*ptr)++; |
500 | (*ptr)++; |
500 | DEBUG("PS[0x%02X]", idx); |
501 | DEBUG("PS[0x%02X]", idx); |
501 | ctx->ps[idx] = cpu_to_le32(val); |
502 | ctx->ps[idx] = cpu_to_le32(val); |
502 | break; |
503 | break; |
503 | case ATOM_ARG_WS: |
504 | case ATOM_ARG_WS: |
504 | idx = U8(*ptr); |
505 | idx = U8(*ptr); |
505 | (*ptr)++; |
506 | (*ptr)++; |
506 | DEBUG("WS[0x%02X]", idx); |
507 | DEBUG("WS[0x%02X]", idx); |
507 | switch (idx) { |
508 | switch (idx) { |
508 | case ATOM_WS_QUOTIENT: |
509 | case ATOM_WS_QUOTIENT: |
509 | gctx->divmul[0] = val; |
510 | gctx->divmul[0] = val; |
510 | break; |
511 | break; |
511 | case ATOM_WS_REMAINDER: |
512 | case ATOM_WS_REMAINDER: |
512 | gctx->divmul[1] = val; |
513 | gctx->divmul[1] = val; |
513 | break; |
514 | break; |
514 | case ATOM_WS_DATAPTR: |
515 | case ATOM_WS_DATAPTR: |
515 | gctx->data_block = val; |
516 | gctx->data_block = val; |
516 | break; |
517 | break; |
517 | case ATOM_WS_SHIFT: |
518 | case ATOM_WS_SHIFT: |
518 | gctx->shift = val; |
519 | gctx->shift = val; |
519 | break; |
520 | break; |
520 | case ATOM_WS_OR_MASK: |
521 | case ATOM_WS_OR_MASK: |
521 | case ATOM_WS_AND_MASK: |
522 | case ATOM_WS_AND_MASK: |
522 | break; |
523 | break; |
523 | case ATOM_WS_FB_WINDOW: |
524 | case ATOM_WS_FB_WINDOW: |
524 | gctx->fb_base = val; |
525 | gctx->fb_base = val; |
525 | break; |
526 | break; |
526 | case ATOM_WS_ATTRIBUTES: |
527 | case ATOM_WS_ATTRIBUTES: |
527 | gctx->io_attr = val; |
528 | gctx->io_attr = val; |
528 | break; |
529 | break; |
529 | case ATOM_WS_REGPTR: |
530 | case ATOM_WS_REGPTR: |
530 | gctx->reg_block = val; |
531 | gctx->reg_block = val; |
531 | break; |
532 | break; |
532 | default: |
533 | default: |
533 | ctx->ws[idx] = val; |
534 | ctx->ws[idx] = val; |
534 | } |
535 | } |
535 | break; |
536 | break; |
536 | case ATOM_ARG_FB: |
537 | case ATOM_ARG_FB: |
537 | idx = U8(*ptr); |
538 | idx = U8(*ptr); |
538 | (*ptr)++; |
539 | (*ptr)++; |
539 | if ((gctx->fb_base + (idx * 4)) > gctx->scratch_size_bytes) { |
540 | if ((gctx->fb_base + (idx * 4)) > gctx->scratch_size_bytes) { |
540 | DRM_ERROR("ATOM: fb write beyond scratch region: %d vs. %d\n", |
541 | DRM_ERROR("ATOM: fb write beyond scratch region: %d vs. %d\n", |
541 | gctx->fb_base + (idx * 4), gctx->scratch_size_bytes); |
542 | gctx->fb_base + (idx * 4), gctx->scratch_size_bytes); |
542 | } else |
543 | } else |
543 | gctx->scratch[(gctx->fb_base / 4) + idx] = val; |
544 | gctx->scratch[(gctx->fb_base / 4) + idx] = val; |
544 | DEBUG("FB[0x%02X]", idx); |
545 | DEBUG("FB[0x%02X]", idx); |
545 | break; |
546 | break; |
546 | case ATOM_ARG_PLL: |
547 | case ATOM_ARG_PLL: |
547 | idx = U8(*ptr); |
548 | idx = U8(*ptr); |
548 | (*ptr)++; |
549 | (*ptr)++; |
549 | DEBUG("PLL[0x%02X]", idx); |
550 | DEBUG("PLL[0x%02X]", idx); |
550 | gctx->card->pll_write(gctx->card, idx, val); |
551 | gctx->card->pll_write(gctx->card, idx, val); |
551 | break; |
552 | break; |
552 | case ATOM_ARG_MC: |
553 | case ATOM_ARG_MC: |
553 | idx = U8(*ptr); |
554 | idx = U8(*ptr); |
554 | (*ptr)++; |
555 | (*ptr)++; |
555 | DEBUG("MC[0x%02X]", idx); |
556 | DEBUG("MC[0x%02X]", idx); |
556 | gctx->card->mc_write(gctx->card, idx, val); |
557 | gctx->card->mc_write(gctx->card, idx, val); |
557 | return; |
558 | return; |
558 | } |
559 | } |
559 | switch (align) { |
560 | switch (align) { |
560 | case ATOM_SRC_DWORD: |
561 | case ATOM_SRC_DWORD: |
561 | DEBUG(".[31:0] <- 0x%08X\n", old_val); |
562 | DEBUG(".[31:0] <- 0x%08X\n", old_val); |
562 | break; |
563 | break; |
563 | case ATOM_SRC_WORD0: |
564 | case ATOM_SRC_WORD0: |
564 | DEBUG(".[15:0] <- 0x%04X\n", old_val); |
565 | DEBUG(".[15:0] <- 0x%04X\n", old_val); |
565 | break; |
566 | break; |
566 | case ATOM_SRC_WORD8: |
567 | case ATOM_SRC_WORD8: |
567 | DEBUG(".[23:8] <- 0x%04X\n", old_val); |
568 | DEBUG(".[23:8] <- 0x%04X\n", old_val); |
568 | break; |
569 | break; |
569 | case ATOM_SRC_WORD16: |
570 | case ATOM_SRC_WORD16: |
570 | DEBUG(".[31:16] <- 0x%04X\n", old_val); |
571 | DEBUG(".[31:16] <- 0x%04X\n", old_val); |
571 | break; |
572 | break; |
572 | case ATOM_SRC_BYTE0: |
573 | case ATOM_SRC_BYTE0: |
573 | DEBUG(".[7:0] <- 0x%02X\n", old_val); |
574 | DEBUG(".[7:0] <- 0x%02X\n", old_val); |
574 | break; |
575 | break; |
575 | case ATOM_SRC_BYTE8: |
576 | case ATOM_SRC_BYTE8: |
576 | DEBUG(".[15:8] <- 0x%02X\n", old_val); |
577 | DEBUG(".[15:8] <- 0x%02X\n", old_val); |
577 | break; |
578 | break; |
578 | case ATOM_SRC_BYTE16: |
579 | case ATOM_SRC_BYTE16: |
579 | DEBUG(".[23:16] <- 0x%02X\n", old_val); |
580 | DEBUG(".[23:16] <- 0x%02X\n", old_val); |
580 | break; |
581 | break; |
581 | case ATOM_SRC_BYTE24: |
582 | case ATOM_SRC_BYTE24: |
582 | DEBUG(".[31:24] <- 0x%02X\n", old_val); |
583 | DEBUG(".[31:24] <- 0x%02X\n", old_val); |
583 | break; |
584 | break; |
584 | } |
585 | } |
585 | } |
586 | } |
586 | 587 | ||
587 | static void atom_op_add(atom_exec_context *ctx, int *ptr, int arg) |
588 | static void atom_op_add(atom_exec_context *ctx, int *ptr, int arg) |
588 | { |
589 | { |
589 | uint8_t attr = U8((*ptr)++); |
590 | uint8_t attr = U8((*ptr)++); |
590 | uint32_t dst, src, saved; |
591 | uint32_t dst, src, saved; |
591 | int dptr = *ptr; |
592 | int dptr = *ptr; |
592 | SDEBUG(" dst: "); |
593 | SDEBUG(" dst: "); |
593 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
594 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
594 | SDEBUG(" src: "); |
595 | SDEBUG(" src: "); |
595 | src = atom_get_src(ctx, attr, ptr); |
596 | src = atom_get_src(ctx, attr, ptr); |
596 | dst += src; |
597 | dst += src; |
597 | SDEBUG(" dst: "); |
598 | SDEBUG(" dst: "); |
598 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
599 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
599 | } |
600 | } |
600 | 601 | ||
601 | static void atom_op_and(atom_exec_context *ctx, int *ptr, int arg) |
602 | static void atom_op_and(atom_exec_context *ctx, int *ptr, int arg) |
602 | { |
603 | { |
603 | uint8_t attr = U8((*ptr)++); |
604 | uint8_t attr = U8((*ptr)++); |
604 | uint32_t dst, src, saved; |
605 | uint32_t dst, src, saved; |
605 | int dptr = *ptr; |
606 | int dptr = *ptr; |
606 | SDEBUG(" dst: "); |
607 | SDEBUG(" dst: "); |
607 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
608 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
608 | SDEBUG(" src: "); |
609 | SDEBUG(" src: "); |
609 | src = atom_get_src(ctx, attr, ptr); |
610 | src = atom_get_src(ctx, attr, ptr); |
610 | dst &= src; |
611 | dst &= src; |
611 | SDEBUG(" dst: "); |
612 | SDEBUG(" dst: "); |
612 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
613 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
613 | } |
614 | } |
614 | 615 | ||
615 | static void atom_op_beep(atom_exec_context *ctx, int *ptr, int arg) |
616 | static void atom_op_beep(atom_exec_context *ctx, int *ptr, int arg) |
616 | { |
617 | { |
617 | printk("ATOM BIOS beeped!\n"); |
618 | printk("ATOM BIOS beeped!\n"); |
618 | } |
619 | } |
619 | 620 | ||
620 | static void atom_op_calltable(atom_exec_context *ctx, int *ptr, int arg) |
621 | static void atom_op_calltable(atom_exec_context *ctx, int *ptr, int arg) |
621 | { |
622 | { |
622 | int idx = U8((*ptr)++); |
623 | int idx = U8((*ptr)++); |
623 | int r = 0; |
624 | int r = 0; |
624 | 625 | ||
625 | if (idx < ATOM_TABLE_NAMES_CNT) |
626 | if (idx < ATOM_TABLE_NAMES_CNT) |
626 | SDEBUG(" table: %d (%s)\n", idx, atom_table_names[idx]); |
627 | SDEBUG(" table: %d (%s)\n", idx, atom_table_names[idx]); |
627 | else |
628 | else |
628 | SDEBUG(" table: %d\n", idx); |
629 | SDEBUG(" table: %d\n", idx); |
629 | if (U16(ctx->ctx->cmd_table + 4 + 2 * idx)) |
630 | if (U16(ctx->ctx->cmd_table + 4 + 2 * idx)) |
630 | r = atom_execute_table_locked(ctx->ctx, idx, ctx->ps + ctx->ps_shift); |
631 | r = atom_execute_table_locked(ctx->ctx, idx, ctx->ps + ctx->ps_shift); |
631 | if (r) { |
632 | if (r) { |
632 | ctx->abort = true; |
633 | ctx->abort = true; |
633 | } |
634 | } |
634 | } |
635 | } |
635 | 636 | ||
636 | static void atom_op_clear(atom_exec_context *ctx, int *ptr, int arg) |
637 | static void atom_op_clear(atom_exec_context *ctx, int *ptr, int arg) |
637 | { |
638 | { |
638 | uint8_t attr = U8((*ptr)++); |
639 | uint8_t attr = U8((*ptr)++); |
639 | uint32_t saved; |
640 | uint32_t saved; |
640 | int dptr = *ptr; |
641 | int dptr = *ptr; |
641 | attr &= 0x38; |
642 | attr &= 0x38; |
642 | attr |= atom_def_dst[attr >> 3] << 6; |
643 | attr |= atom_def_dst[attr >> 3] << 6; |
643 | atom_get_dst(ctx, arg, attr, ptr, &saved, 0); |
644 | atom_get_dst(ctx, arg, attr, ptr, &saved, 0); |
644 | SDEBUG(" dst: "); |
645 | SDEBUG(" dst: "); |
645 | atom_put_dst(ctx, arg, attr, &dptr, 0, saved); |
646 | atom_put_dst(ctx, arg, attr, &dptr, 0, saved); |
646 | } |
647 | } |
647 | 648 | ||
648 | static void atom_op_compare(atom_exec_context *ctx, int *ptr, int arg) |
649 | static void atom_op_compare(atom_exec_context *ctx, int *ptr, int arg) |
649 | { |
650 | { |
650 | uint8_t attr = U8((*ptr)++); |
651 | uint8_t attr = U8((*ptr)++); |
651 | uint32_t dst, src; |
652 | uint32_t dst, src; |
652 | SDEBUG(" src1: "); |
653 | SDEBUG(" src1: "); |
653 | dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); |
654 | dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); |
654 | SDEBUG(" src2: "); |
655 | SDEBUG(" src2: "); |
655 | src = atom_get_src(ctx, attr, ptr); |
656 | src = atom_get_src(ctx, attr, ptr); |
656 | ctx->ctx->cs_equal = (dst == src); |
657 | ctx->ctx->cs_equal = (dst == src); |
657 | ctx->ctx->cs_above = (dst > src); |
658 | ctx->ctx->cs_above = (dst > src); |
658 | SDEBUG(" result: %s %s\n", ctx->ctx->cs_equal ? "EQ" : "NE", |
659 | SDEBUG(" result: %s %s\n", ctx->ctx->cs_equal ? "EQ" : "NE", |
659 | ctx->ctx->cs_above ? "GT" : "LE"); |
660 | ctx->ctx->cs_above ? "GT" : "LE"); |
660 | } |
661 | } |
661 | 662 | ||
662 | static void atom_op_delay(atom_exec_context *ctx, int *ptr, int arg) |
663 | static void atom_op_delay(atom_exec_context *ctx, int *ptr, int arg) |
663 | { |
664 | { |
664 | unsigned count = U8((*ptr)++); |
665 | unsigned count = U8((*ptr)++); |
665 | SDEBUG(" count: %d\n", count); |
666 | SDEBUG(" count: %d\n", count); |
666 | if (arg == ATOM_UNIT_MICROSEC) |
667 | if (arg == ATOM_UNIT_MICROSEC) |
667 | udelay(count); |
668 | udelay(count); |
668 | else if (!drm_can_sleep()) |
669 | else if (!drm_can_sleep()) |
669 | mdelay(count); |
670 | mdelay(count); |
670 | else |
671 | else |
671 | msleep(count); |
672 | msleep(count); |
672 | } |
673 | } |
673 | 674 | ||
674 | static void atom_op_div(atom_exec_context *ctx, int *ptr, int arg) |
675 | static void atom_op_div(atom_exec_context *ctx, int *ptr, int arg) |
675 | { |
676 | { |
676 | uint8_t attr = U8((*ptr)++); |
677 | uint8_t attr = U8((*ptr)++); |
677 | uint32_t dst, src; |
678 | uint32_t dst, src; |
678 | SDEBUG(" src1: "); |
679 | SDEBUG(" src1: "); |
679 | dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); |
680 | dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); |
680 | SDEBUG(" src2: "); |
681 | SDEBUG(" src2: "); |
681 | src = atom_get_src(ctx, attr, ptr); |
682 | src = atom_get_src(ctx, attr, ptr); |
682 | if (src != 0) { |
683 | if (src != 0) { |
683 | ctx->ctx->divmul[0] = dst / src; |
684 | ctx->ctx->divmul[0] = dst / src; |
684 | ctx->ctx->divmul[1] = dst % src; |
685 | ctx->ctx->divmul[1] = dst % src; |
685 | } else { |
686 | } else { |
686 | ctx->ctx->divmul[0] = 0; |
687 | ctx->ctx->divmul[0] = 0; |
687 | ctx->ctx->divmul[1] = 0; |
688 | ctx->ctx->divmul[1] = 0; |
688 | } |
689 | } |
689 | } |
690 | } |
690 | 691 | ||
691 | static void atom_op_eot(atom_exec_context *ctx, int *ptr, int arg) |
692 | static void atom_op_eot(atom_exec_context *ctx, int *ptr, int arg) |
692 | { |
693 | { |
693 | /* functionally, a nop */ |
694 | /* functionally, a nop */ |
694 | } |
695 | } |
695 | 696 | ||
696 | static void atom_op_jump(atom_exec_context *ctx, int *ptr, int arg) |
697 | static void atom_op_jump(atom_exec_context *ctx, int *ptr, int arg) |
697 | { |
698 | { |
698 | int execute = 0, target = U16(*ptr); |
699 | int execute = 0, target = U16(*ptr); |
699 | unsigned long cjiffies; |
700 | unsigned long cjiffies; |
700 | 701 | ||
701 | (*ptr) += 2; |
702 | (*ptr) += 2; |
702 | switch (arg) { |
703 | switch (arg) { |
703 | case ATOM_COND_ABOVE: |
704 | case ATOM_COND_ABOVE: |
704 | execute = ctx->ctx->cs_above; |
705 | execute = ctx->ctx->cs_above; |
705 | break; |
706 | break; |
706 | case ATOM_COND_ABOVEOREQUAL: |
707 | case ATOM_COND_ABOVEOREQUAL: |
707 | execute = ctx->ctx->cs_above || ctx->ctx->cs_equal; |
708 | execute = ctx->ctx->cs_above || ctx->ctx->cs_equal; |
708 | break; |
709 | break; |
709 | case ATOM_COND_ALWAYS: |
710 | case ATOM_COND_ALWAYS: |
710 | execute = 1; |
711 | execute = 1; |
711 | break; |
712 | break; |
712 | case ATOM_COND_BELOW: |
713 | case ATOM_COND_BELOW: |
713 | execute = !(ctx->ctx->cs_above || ctx->ctx->cs_equal); |
714 | execute = !(ctx->ctx->cs_above || ctx->ctx->cs_equal); |
714 | break; |
715 | break; |
715 | case ATOM_COND_BELOWOREQUAL: |
716 | case ATOM_COND_BELOWOREQUAL: |
716 | execute = !ctx->ctx->cs_above; |
717 | execute = !ctx->ctx->cs_above; |
717 | break; |
718 | break; |
718 | case ATOM_COND_EQUAL: |
719 | case ATOM_COND_EQUAL: |
719 | execute = ctx->ctx->cs_equal; |
720 | execute = ctx->ctx->cs_equal; |
720 | break; |
721 | break; |
721 | case ATOM_COND_NOTEQUAL: |
722 | case ATOM_COND_NOTEQUAL: |
722 | execute = !ctx->ctx->cs_equal; |
723 | execute = !ctx->ctx->cs_equal; |
723 | break; |
724 | break; |
724 | } |
725 | } |
725 | if (arg != ATOM_COND_ALWAYS) |
726 | if (arg != ATOM_COND_ALWAYS) |
726 | SDEBUG(" taken: %s\n", execute ? "yes" : "no"); |
727 | SDEBUG(" taken: %s\n", execute ? "yes" : "no"); |
727 | SDEBUG(" target: 0x%04X\n", target); |
728 | SDEBUG(" target: 0x%04X\n", target); |
728 | if (execute) { |
729 | if (execute) { |
729 | if (ctx->last_jump == (ctx->start + target)) { |
730 | if (ctx->last_jump == (ctx->start + target)) { |
730 | cjiffies = jiffies; |
731 | cjiffies = jiffies; |
731 | if (time_after(cjiffies, ctx->last_jump_jiffies)) { |
732 | if (time_after(cjiffies, ctx->last_jump_jiffies)) { |
732 | cjiffies -= ctx->last_jump_jiffies; |
733 | cjiffies -= ctx->last_jump_jiffies; |
733 | if ((jiffies_to_msecs(cjiffies) > 5000)) { |
734 | if ((jiffies_to_msecs(cjiffies) > 5000)) { |
734 | DRM_ERROR("atombios stuck in loop for more than 5secs aborting\n"); |
735 | DRM_ERROR("atombios stuck in loop for more than 5secs aborting\n"); |
735 | ctx->abort = true; |
736 | ctx->abort = true; |
736 | } |
737 | } |
737 | } else { |
738 | } else { |
738 | /* jiffies wrap around we will just wait a little longer */ |
739 | /* jiffies wrap around we will just wait a little longer */ |
739 | ctx->last_jump_jiffies = jiffies; |
740 | ctx->last_jump_jiffies = jiffies; |
740 | } |
741 | } |
741 | } else { |
742 | } else { |
742 | ctx->last_jump = ctx->start + target; |
743 | ctx->last_jump = ctx->start + target; |
743 | ctx->last_jump_jiffies = jiffies; |
744 | ctx->last_jump_jiffies = jiffies; |
744 | } |
745 | } |
745 | *ptr = ctx->start + target; |
746 | *ptr = ctx->start + target; |
746 | } |
747 | } |
747 | } |
748 | } |
748 | 749 | ||
749 | static void atom_op_mask(atom_exec_context *ctx, int *ptr, int arg) |
750 | static void atom_op_mask(atom_exec_context *ctx, int *ptr, int arg) |
750 | { |
751 | { |
751 | uint8_t attr = U8((*ptr)++); |
752 | uint8_t attr = U8((*ptr)++); |
752 | uint32_t dst, mask, src, saved; |
753 | uint32_t dst, mask, src, saved; |
753 | int dptr = *ptr; |
754 | int dptr = *ptr; |
754 | SDEBUG(" dst: "); |
755 | SDEBUG(" dst: "); |
755 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
756 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
756 | mask = atom_get_src_direct(ctx, ((attr >> 3) & 7), ptr); |
757 | mask = atom_get_src_direct(ctx, ((attr >> 3) & 7), ptr); |
757 | SDEBUG(" mask: 0x%08x", mask); |
758 | SDEBUG(" mask: 0x%08x", mask); |
758 | SDEBUG(" src: "); |
759 | SDEBUG(" src: "); |
759 | src = atom_get_src(ctx, attr, ptr); |
760 | src = atom_get_src(ctx, attr, ptr); |
760 | dst &= mask; |
761 | dst &= mask; |
761 | dst |= src; |
762 | dst |= src; |
762 | SDEBUG(" dst: "); |
763 | SDEBUG(" dst: "); |
763 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
764 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
764 | } |
765 | } |
765 | 766 | ||
766 | static void atom_op_move(atom_exec_context *ctx, int *ptr, int arg) |
767 | static void atom_op_move(atom_exec_context *ctx, int *ptr, int arg) |
767 | { |
768 | { |
768 | uint8_t attr = U8((*ptr)++); |
769 | uint8_t attr = U8((*ptr)++); |
769 | uint32_t src, saved; |
770 | uint32_t src, saved; |
770 | int dptr = *ptr; |
771 | int dptr = *ptr; |
771 | if (((attr >> 3) & 7) != ATOM_SRC_DWORD) |
772 | if (((attr >> 3) & 7) != ATOM_SRC_DWORD) |
772 | atom_get_dst(ctx, arg, attr, ptr, &saved, 0); |
773 | atom_get_dst(ctx, arg, attr, ptr, &saved, 0); |
773 | else { |
774 | else { |
774 | atom_skip_dst(ctx, arg, attr, ptr); |
775 | atom_skip_dst(ctx, arg, attr, ptr); |
775 | saved = 0xCDCDCDCD; |
776 | saved = 0xCDCDCDCD; |
776 | } |
777 | } |
777 | SDEBUG(" src: "); |
778 | SDEBUG(" src: "); |
778 | src = atom_get_src(ctx, attr, ptr); |
779 | src = atom_get_src(ctx, attr, ptr); |
779 | SDEBUG(" dst: "); |
780 | SDEBUG(" dst: "); |
780 | atom_put_dst(ctx, arg, attr, &dptr, src, saved); |
781 | atom_put_dst(ctx, arg, attr, &dptr, src, saved); |
781 | } |
782 | } |
782 | 783 | ||
783 | static void atom_op_mul(atom_exec_context *ctx, int *ptr, int arg) |
784 | static void atom_op_mul(atom_exec_context *ctx, int *ptr, int arg) |
784 | { |
785 | { |
785 | uint8_t attr = U8((*ptr)++); |
786 | uint8_t attr = U8((*ptr)++); |
786 | uint32_t dst, src; |
787 | uint32_t dst, src; |
787 | SDEBUG(" src1: "); |
788 | SDEBUG(" src1: "); |
788 | dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); |
789 | dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); |
789 | SDEBUG(" src2: "); |
790 | SDEBUG(" src2: "); |
790 | src = atom_get_src(ctx, attr, ptr); |
791 | src = atom_get_src(ctx, attr, ptr); |
791 | ctx->ctx->divmul[0] = dst * src; |
792 | ctx->ctx->divmul[0] = dst * src; |
792 | } |
793 | } |
793 | 794 | ||
794 | static void atom_op_nop(atom_exec_context *ctx, int *ptr, int arg) |
795 | static void atom_op_nop(atom_exec_context *ctx, int *ptr, int arg) |
795 | { |
796 | { |
796 | /* nothing */ |
797 | /* nothing */ |
797 | } |
798 | } |
798 | 799 | ||
799 | static void atom_op_or(atom_exec_context *ctx, int *ptr, int arg) |
800 | static void atom_op_or(atom_exec_context *ctx, int *ptr, int arg) |
800 | { |
801 | { |
801 | uint8_t attr = U8((*ptr)++); |
802 | uint8_t attr = U8((*ptr)++); |
802 | uint32_t dst, src, saved; |
803 | uint32_t dst, src, saved; |
803 | int dptr = *ptr; |
804 | int dptr = *ptr; |
804 | SDEBUG(" dst: "); |
805 | SDEBUG(" dst: "); |
805 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
806 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
806 | SDEBUG(" src: "); |
807 | SDEBUG(" src: "); |
807 | src = atom_get_src(ctx, attr, ptr); |
808 | src = atom_get_src(ctx, attr, ptr); |
808 | dst |= src; |
809 | dst |= src; |
809 | SDEBUG(" dst: "); |
810 | SDEBUG(" dst: "); |
810 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
811 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
811 | } |
812 | } |
812 | 813 | ||
813 | static void atom_op_postcard(atom_exec_context *ctx, int *ptr, int arg) |
814 | static void atom_op_postcard(atom_exec_context *ctx, int *ptr, int arg) |
814 | { |
815 | { |
815 | uint8_t val = U8((*ptr)++); |
816 | uint8_t val = U8((*ptr)++); |
816 | SDEBUG("POST card output: 0x%02X\n", val); |
817 | SDEBUG("POST card output: 0x%02X\n", val); |
817 | } |
818 | } |
818 | 819 | ||
819 | static void atom_op_repeat(atom_exec_context *ctx, int *ptr, int arg) |
820 | static void atom_op_repeat(atom_exec_context *ctx, int *ptr, int arg) |
820 | { |
821 | { |
821 | printk(KERN_INFO "unimplemented!\n"); |
822 | printk(KERN_INFO "unimplemented!\n"); |
822 | } |
823 | } |
823 | 824 | ||
824 | static void atom_op_restorereg(atom_exec_context *ctx, int *ptr, int arg) |
825 | static void atom_op_restorereg(atom_exec_context *ctx, int *ptr, int arg) |
825 | { |
826 | { |
826 | printk(KERN_INFO "unimplemented!\n"); |
827 | printk(KERN_INFO "unimplemented!\n"); |
827 | } |
828 | } |
828 | 829 | ||
829 | static void atom_op_savereg(atom_exec_context *ctx, int *ptr, int arg) |
830 | static void atom_op_savereg(atom_exec_context *ctx, int *ptr, int arg) |
830 | { |
831 | { |
831 | printk(KERN_INFO "unimplemented!\n"); |
832 | printk(KERN_INFO "unimplemented!\n"); |
832 | } |
833 | } |
833 | 834 | ||
834 | static void atom_op_setdatablock(atom_exec_context *ctx, int *ptr, int arg) |
835 | static void atom_op_setdatablock(atom_exec_context *ctx, int *ptr, int arg) |
835 | { |
836 | { |
836 | int idx = U8(*ptr); |
837 | int idx = U8(*ptr); |
837 | (*ptr)++; |
838 | (*ptr)++; |
838 | SDEBUG(" block: %d\n", idx); |
839 | SDEBUG(" block: %d\n", idx); |
839 | if (!idx) |
840 | if (!idx) |
840 | ctx->ctx->data_block = 0; |
841 | ctx->ctx->data_block = 0; |
841 | else if (idx == 255) |
842 | else if (idx == 255) |
842 | ctx->ctx->data_block = ctx->start; |
843 | ctx->ctx->data_block = ctx->start; |
843 | else |
844 | else |
844 | ctx->ctx->data_block = U16(ctx->ctx->data_table + 4 + 2 * idx); |
845 | ctx->ctx->data_block = U16(ctx->ctx->data_table + 4 + 2 * idx); |
845 | SDEBUG(" base: 0x%04X\n", ctx->ctx->data_block); |
846 | SDEBUG(" base: 0x%04X\n", ctx->ctx->data_block); |
846 | } |
847 | } |
847 | 848 | ||
848 | static void atom_op_setfbbase(atom_exec_context *ctx, int *ptr, int arg) |
849 | static void atom_op_setfbbase(atom_exec_context *ctx, int *ptr, int arg) |
849 | { |
850 | { |
850 | uint8_t attr = U8((*ptr)++); |
851 | uint8_t attr = U8((*ptr)++); |
851 | SDEBUG(" fb_base: "); |
852 | SDEBUG(" fb_base: "); |
852 | ctx->ctx->fb_base = atom_get_src(ctx, attr, ptr); |
853 | ctx->ctx->fb_base = atom_get_src(ctx, attr, ptr); |
853 | } |
854 | } |
854 | 855 | ||
855 | static void atom_op_setport(atom_exec_context *ctx, int *ptr, int arg) |
856 | static void atom_op_setport(atom_exec_context *ctx, int *ptr, int arg) |
856 | { |
857 | { |
857 | int port; |
858 | int port; |
858 | switch (arg) { |
859 | switch (arg) { |
859 | case ATOM_PORT_ATI: |
860 | case ATOM_PORT_ATI: |
860 | port = U16(*ptr); |
861 | port = U16(*ptr); |
861 | if (port < ATOM_IO_NAMES_CNT) |
862 | if (port < ATOM_IO_NAMES_CNT) |
862 | SDEBUG(" port: %d (%s)\n", port, atom_io_names[port]); |
863 | SDEBUG(" port: %d (%s)\n", port, atom_io_names[port]); |
863 | else |
864 | else |
864 | SDEBUG(" port: %d\n", port); |
865 | SDEBUG(" port: %d\n", port); |
865 | if (!port) |
866 | if (!port) |
866 | ctx->ctx->io_mode = ATOM_IO_MM; |
867 | ctx->ctx->io_mode = ATOM_IO_MM; |
867 | else |
868 | else |
868 | ctx->ctx->io_mode = ATOM_IO_IIO | port; |
869 | ctx->ctx->io_mode = ATOM_IO_IIO | port; |
869 | (*ptr) += 2; |
870 | (*ptr) += 2; |
870 | break; |
871 | break; |
871 | case ATOM_PORT_PCI: |
872 | case ATOM_PORT_PCI: |
872 | ctx->ctx->io_mode = ATOM_IO_PCI; |
873 | ctx->ctx->io_mode = ATOM_IO_PCI; |
873 | (*ptr)++; |
874 | (*ptr)++; |
874 | break; |
875 | break; |
875 | case ATOM_PORT_SYSIO: |
876 | case ATOM_PORT_SYSIO: |
876 | ctx->ctx->io_mode = ATOM_IO_SYSIO; |
877 | ctx->ctx->io_mode = ATOM_IO_SYSIO; |
877 | (*ptr)++; |
878 | (*ptr)++; |
878 | break; |
879 | break; |
879 | } |
880 | } |
880 | } |
881 | } |
881 | 882 | ||
882 | static void atom_op_setregblock(atom_exec_context *ctx, int *ptr, int arg) |
883 | static void atom_op_setregblock(atom_exec_context *ctx, int *ptr, int arg) |
883 | { |
884 | { |
884 | ctx->ctx->reg_block = U16(*ptr); |
885 | ctx->ctx->reg_block = U16(*ptr); |
885 | (*ptr) += 2; |
886 | (*ptr) += 2; |
886 | SDEBUG(" base: 0x%04X\n", ctx->ctx->reg_block); |
887 | SDEBUG(" base: 0x%04X\n", ctx->ctx->reg_block); |
887 | } |
888 | } |
888 | 889 | ||
889 | static void atom_op_shift_left(atom_exec_context *ctx, int *ptr, int arg) |
890 | static void atom_op_shift_left(atom_exec_context *ctx, int *ptr, int arg) |
890 | { |
891 | { |
891 | uint8_t attr = U8((*ptr)++), shift; |
892 | uint8_t attr = U8((*ptr)++), shift; |
892 | uint32_t saved, dst; |
893 | uint32_t saved, dst; |
893 | int dptr = *ptr; |
894 | int dptr = *ptr; |
894 | attr &= 0x38; |
895 | attr &= 0x38; |
895 | attr |= atom_def_dst[attr >> 3] << 6; |
896 | attr |= atom_def_dst[attr >> 3] << 6; |
896 | SDEBUG(" dst: "); |
897 | SDEBUG(" dst: "); |
897 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
898 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
898 | shift = atom_get_src_direct(ctx, ATOM_SRC_BYTE0, ptr); |
899 | shift = atom_get_src_direct(ctx, ATOM_SRC_BYTE0, ptr); |
899 | SDEBUG(" shift: %d\n", shift); |
900 | SDEBUG(" shift: %d\n", shift); |
900 | dst <<= shift; |
901 | dst <<= shift; |
901 | SDEBUG(" dst: "); |
902 | SDEBUG(" dst: "); |
902 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
903 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
903 | } |
904 | } |
904 | 905 | ||
905 | static void atom_op_shift_right(atom_exec_context *ctx, int *ptr, int arg) |
906 | static void atom_op_shift_right(atom_exec_context *ctx, int *ptr, int arg) |
906 | { |
907 | { |
907 | uint8_t attr = U8((*ptr)++), shift; |
908 | uint8_t attr = U8((*ptr)++), shift; |
908 | uint32_t saved, dst; |
909 | uint32_t saved, dst; |
909 | int dptr = *ptr; |
910 | int dptr = *ptr; |
910 | attr &= 0x38; |
911 | attr &= 0x38; |
911 | attr |= atom_def_dst[attr >> 3] << 6; |
912 | attr |= atom_def_dst[attr >> 3] << 6; |
912 | SDEBUG(" dst: "); |
913 | SDEBUG(" dst: "); |
913 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
914 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
914 | shift = atom_get_src_direct(ctx, ATOM_SRC_BYTE0, ptr); |
915 | shift = atom_get_src_direct(ctx, ATOM_SRC_BYTE0, ptr); |
915 | SDEBUG(" shift: %d\n", shift); |
916 | SDEBUG(" shift: %d\n", shift); |
916 | dst >>= shift; |
917 | dst >>= shift; |
917 | SDEBUG(" dst: "); |
918 | SDEBUG(" dst: "); |
918 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
919 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
919 | } |
920 | } |
920 | 921 | ||
921 | static void atom_op_shl(atom_exec_context *ctx, int *ptr, int arg) |
922 | static void atom_op_shl(atom_exec_context *ctx, int *ptr, int arg) |
922 | { |
923 | { |
923 | uint8_t attr = U8((*ptr)++), shift; |
924 | uint8_t attr = U8((*ptr)++), shift; |
924 | uint32_t saved, dst; |
925 | uint32_t saved, dst; |
925 | int dptr = *ptr; |
926 | int dptr = *ptr; |
926 | uint32_t dst_align = atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) & 3]; |
927 | uint32_t dst_align = atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) & 3]; |
927 | SDEBUG(" dst: "); |
928 | SDEBUG(" dst: "); |
928 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
929 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
929 | /* op needs to full dst value */ |
930 | /* op needs to full dst value */ |
930 | dst = saved; |
931 | dst = saved; |
931 | shift = atom_get_src(ctx, attr, ptr); |
932 | shift = atom_get_src(ctx, attr, ptr); |
932 | SDEBUG(" shift: %d\n", shift); |
933 | SDEBUG(" shift: %d\n", shift); |
933 | dst <<= shift; |
934 | dst <<= shift; |
934 | dst &= atom_arg_mask[dst_align]; |
935 | dst &= atom_arg_mask[dst_align]; |
935 | dst >>= atom_arg_shift[dst_align]; |
936 | dst >>= atom_arg_shift[dst_align]; |
936 | SDEBUG(" dst: "); |
937 | SDEBUG(" dst: "); |
937 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
938 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
938 | } |
939 | } |
939 | 940 | ||
940 | static void atom_op_shr(atom_exec_context *ctx, int *ptr, int arg) |
941 | static void atom_op_shr(atom_exec_context *ctx, int *ptr, int arg) |
941 | { |
942 | { |
942 | uint8_t attr = U8((*ptr)++), shift; |
943 | uint8_t attr = U8((*ptr)++), shift; |
943 | uint32_t saved, dst; |
944 | uint32_t saved, dst; |
944 | int dptr = *ptr; |
945 | int dptr = *ptr; |
945 | uint32_t dst_align = atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) & 3]; |
946 | uint32_t dst_align = atom_dst_to_src[(attr >> 3) & 7][(attr >> 6) & 3]; |
946 | SDEBUG(" dst: "); |
947 | SDEBUG(" dst: "); |
947 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
948 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
948 | /* op needs to full dst value */ |
949 | /* op needs to full dst value */ |
949 | dst = saved; |
950 | dst = saved; |
950 | shift = atom_get_src(ctx, attr, ptr); |
951 | shift = atom_get_src(ctx, attr, ptr); |
951 | SDEBUG(" shift: %d\n", shift); |
952 | SDEBUG(" shift: %d\n", shift); |
952 | dst >>= shift; |
953 | dst >>= shift; |
953 | dst &= atom_arg_mask[dst_align]; |
954 | dst &= atom_arg_mask[dst_align]; |
954 | dst >>= atom_arg_shift[dst_align]; |
955 | dst >>= atom_arg_shift[dst_align]; |
955 | SDEBUG(" dst: "); |
956 | SDEBUG(" dst: "); |
956 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
957 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
957 | } |
958 | } |
958 | 959 | ||
959 | static void atom_op_sub(atom_exec_context *ctx, int *ptr, int arg) |
960 | static void atom_op_sub(atom_exec_context *ctx, int *ptr, int arg) |
960 | { |
961 | { |
961 | uint8_t attr = U8((*ptr)++); |
962 | uint8_t attr = U8((*ptr)++); |
962 | uint32_t dst, src, saved; |
963 | uint32_t dst, src, saved; |
963 | int dptr = *ptr; |
964 | int dptr = *ptr; |
964 | SDEBUG(" dst: "); |
965 | SDEBUG(" dst: "); |
965 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
966 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
966 | SDEBUG(" src: "); |
967 | SDEBUG(" src: "); |
967 | src = atom_get_src(ctx, attr, ptr); |
968 | src = atom_get_src(ctx, attr, ptr); |
968 | dst -= src; |
969 | dst -= src; |
969 | SDEBUG(" dst: "); |
970 | SDEBUG(" dst: "); |
970 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
971 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
971 | } |
972 | } |
972 | 973 | ||
973 | static void atom_op_switch(atom_exec_context *ctx, int *ptr, int arg) |
974 | static void atom_op_switch(atom_exec_context *ctx, int *ptr, int arg) |
974 | { |
975 | { |
975 | uint8_t attr = U8((*ptr)++); |
976 | uint8_t attr = U8((*ptr)++); |
976 | uint32_t src, val, target; |
977 | uint32_t src, val, target; |
977 | SDEBUG(" switch: "); |
978 | SDEBUG(" switch: "); |
978 | src = atom_get_src(ctx, attr, ptr); |
979 | src = atom_get_src(ctx, attr, ptr); |
979 | while (U16(*ptr) != ATOM_CASE_END) |
980 | while (U16(*ptr) != ATOM_CASE_END) |
980 | if (U8(*ptr) == ATOM_CASE_MAGIC) { |
981 | if (U8(*ptr) == ATOM_CASE_MAGIC) { |
981 | (*ptr)++; |
982 | (*ptr)++; |
982 | SDEBUG(" case: "); |
983 | SDEBUG(" case: "); |
983 | val = |
984 | val = |
984 | atom_get_src(ctx, (attr & 0x38) | ATOM_ARG_IMM, |
985 | atom_get_src(ctx, (attr & 0x38) | ATOM_ARG_IMM, |
985 | ptr); |
986 | ptr); |
986 | target = U16(*ptr); |
987 | target = U16(*ptr); |
987 | if (val == src) { |
988 | if (val == src) { |
988 | SDEBUG(" target: %04X\n", target); |
989 | SDEBUG(" target: %04X\n", target); |
989 | *ptr = ctx->start + target; |
990 | *ptr = ctx->start + target; |
990 | return; |
991 | return; |
991 | } |
992 | } |
992 | (*ptr) += 2; |
993 | (*ptr) += 2; |
993 | } else { |
994 | } else { |
994 | printk(KERN_INFO "Bad case.\n"); |
995 | printk(KERN_INFO "Bad case.\n"); |
995 | return; |
996 | return; |
996 | } |
997 | } |
997 | (*ptr) += 2; |
998 | (*ptr) += 2; |
998 | } |
999 | } |
999 | 1000 | ||
1000 | static void atom_op_test(atom_exec_context *ctx, int *ptr, int arg) |
1001 | static void atom_op_test(atom_exec_context *ctx, int *ptr, int arg) |
1001 | { |
1002 | { |
1002 | uint8_t attr = U8((*ptr)++); |
1003 | uint8_t attr = U8((*ptr)++); |
1003 | uint32_t dst, src; |
1004 | uint32_t dst, src; |
1004 | SDEBUG(" src1: "); |
1005 | SDEBUG(" src1: "); |
1005 | dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); |
1006 | dst = atom_get_dst(ctx, arg, attr, ptr, NULL, 1); |
1006 | SDEBUG(" src2: "); |
1007 | SDEBUG(" src2: "); |
1007 | src = atom_get_src(ctx, attr, ptr); |
1008 | src = atom_get_src(ctx, attr, ptr); |
1008 | ctx->ctx->cs_equal = ((dst & src) == 0); |
1009 | ctx->ctx->cs_equal = ((dst & src) == 0); |
1009 | SDEBUG(" result: %s\n", ctx->ctx->cs_equal ? "EQ" : "NE"); |
1010 | SDEBUG(" result: %s\n", ctx->ctx->cs_equal ? "EQ" : "NE"); |
1010 | } |
1011 | } |
1011 | 1012 | ||
1012 | static void atom_op_xor(atom_exec_context *ctx, int *ptr, int arg) |
1013 | static void atom_op_xor(atom_exec_context *ctx, int *ptr, int arg) |
1013 | { |
1014 | { |
1014 | uint8_t attr = U8((*ptr)++); |
1015 | uint8_t attr = U8((*ptr)++); |
1015 | uint32_t dst, src, saved; |
1016 | uint32_t dst, src, saved; |
1016 | int dptr = *ptr; |
1017 | int dptr = *ptr; |
1017 | SDEBUG(" dst: "); |
1018 | SDEBUG(" dst: "); |
1018 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
1019 | dst = atom_get_dst(ctx, arg, attr, ptr, &saved, 1); |
1019 | SDEBUG(" src: "); |
1020 | SDEBUG(" src: "); |
1020 | src = atom_get_src(ctx, attr, ptr); |
1021 | src = atom_get_src(ctx, attr, ptr); |
1021 | dst ^= src; |
1022 | dst ^= src; |
1022 | SDEBUG(" dst: "); |
1023 | SDEBUG(" dst: "); |
1023 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
1024 | atom_put_dst(ctx, arg, attr, &dptr, dst, saved); |
1024 | } |
1025 | } |
1025 | 1026 | ||
1026 | static void atom_op_debug(atom_exec_context *ctx, int *ptr, int arg) |
1027 | static void atom_op_debug(atom_exec_context *ctx, int *ptr, int arg) |
1027 | { |
1028 | { |
1028 | printk(KERN_INFO "unimplemented!\n"); |
1029 | printk(KERN_INFO "unimplemented!\n"); |
1029 | } |
1030 | } |
1030 | 1031 | ||
1031 | static struct { |
1032 | static struct { |
1032 | void (*func) (atom_exec_context *, int *, int); |
1033 | void (*func) (atom_exec_context *, int *, int); |
1033 | int arg; |
1034 | int arg; |
1034 | } opcode_table[ATOM_OP_CNT] = { |
1035 | } opcode_table[ATOM_OP_CNT] = { |
1035 | { |
1036 | { |
1036 | NULL, 0}, { |
1037 | NULL, 0}, { |
1037 | atom_op_move, ATOM_ARG_REG}, { |
1038 | atom_op_move, ATOM_ARG_REG}, { |
1038 | atom_op_move, ATOM_ARG_PS}, { |
1039 | atom_op_move, ATOM_ARG_PS}, { |
1039 | atom_op_move, ATOM_ARG_WS}, { |
1040 | atom_op_move, ATOM_ARG_WS}, { |
1040 | atom_op_move, ATOM_ARG_FB}, { |
1041 | atom_op_move, ATOM_ARG_FB}, { |
1041 | atom_op_move, ATOM_ARG_PLL}, { |
1042 | atom_op_move, ATOM_ARG_PLL}, { |
1042 | atom_op_move, ATOM_ARG_MC}, { |
1043 | atom_op_move, ATOM_ARG_MC}, { |
1043 | atom_op_and, ATOM_ARG_REG}, { |
1044 | atom_op_and, ATOM_ARG_REG}, { |
1044 | atom_op_and, ATOM_ARG_PS}, { |
1045 | atom_op_and, ATOM_ARG_PS}, { |
1045 | atom_op_and, ATOM_ARG_WS}, { |
1046 | atom_op_and, ATOM_ARG_WS}, { |
1046 | atom_op_and, ATOM_ARG_FB}, { |
1047 | atom_op_and, ATOM_ARG_FB}, { |
1047 | atom_op_and, ATOM_ARG_PLL}, { |
1048 | atom_op_and, ATOM_ARG_PLL}, { |
1048 | atom_op_and, ATOM_ARG_MC}, { |
1049 | atom_op_and, ATOM_ARG_MC}, { |
1049 | atom_op_or, ATOM_ARG_REG}, { |
1050 | atom_op_or, ATOM_ARG_REG}, { |
1050 | atom_op_or, ATOM_ARG_PS}, { |
1051 | atom_op_or, ATOM_ARG_PS}, { |
1051 | atom_op_or, ATOM_ARG_WS}, { |
1052 | atom_op_or, ATOM_ARG_WS}, { |
1052 | atom_op_or, ATOM_ARG_FB}, { |
1053 | atom_op_or, ATOM_ARG_FB}, { |
1053 | atom_op_or, ATOM_ARG_PLL}, { |
1054 | atom_op_or, ATOM_ARG_PLL}, { |
1054 | atom_op_or, ATOM_ARG_MC}, { |
1055 | atom_op_or, ATOM_ARG_MC}, { |
1055 | atom_op_shift_left, ATOM_ARG_REG}, { |
1056 | atom_op_shift_left, ATOM_ARG_REG}, { |
1056 | atom_op_shift_left, ATOM_ARG_PS}, { |
1057 | atom_op_shift_left, ATOM_ARG_PS}, { |
1057 | atom_op_shift_left, ATOM_ARG_WS}, { |
1058 | atom_op_shift_left, ATOM_ARG_WS}, { |
1058 | atom_op_shift_left, ATOM_ARG_FB}, { |
1059 | atom_op_shift_left, ATOM_ARG_FB}, { |
1059 | atom_op_shift_left, ATOM_ARG_PLL}, { |
1060 | atom_op_shift_left, ATOM_ARG_PLL}, { |
1060 | atom_op_shift_left, ATOM_ARG_MC}, { |
1061 | atom_op_shift_left, ATOM_ARG_MC}, { |
1061 | atom_op_shift_right, ATOM_ARG_REG}, { |
1062 | atom_op_shift_right, ATOM_ARG_REG}, { |
1062 | atom_op_shift_right, ATOM_ARG_PS}, { |
1063 | atom_op_shift_right, ATOM_ARG_PS}, { |
1063 | atom_op_shift_right, ATOM_ARG_WS}, { |
1064 | atom_op_shift_right, ATOM_ARG_WS}, { |
1064 | atom_op_shift_right, ATOM_ARG_FB}, { |
1065 | atom_op_shift_right, ATOM_ARG_FB}, { |
1065 | atom_op_shift_right, ATOM_ARG_PLL}, { |
1066 | atom_op_shift_right, ATOM_ARG_PLL}, { |
1066 | atom_op_shift_right, ATOM_ARG_MC}, { |
1067 | atom_op_shift_right, ATOM_ARG_MC}, { |
1067 | atom_op_mul, ATOM_ARG_REG}, { |
1068 | atom_op_mul, ATOM_ARG_REG}, { |
1068 | atom_op_mul, ATOM_ARG_PS}, { |
1069 | atom_op_mul, ATOM_ARG_PS}, { |
1069 | atom_op_mul, ATOM_ARG_WS}, { |
1070 | atom_op_mul, ATOM_ARG_WS}, { |
1070 | atom_op_mul, ATOM_ARG_FB}, { |
1071 | atom_op_mul, ATOM_ARG_FB}, { |
1071 | atom_op_mul, ATOM_ARG_PLL}, { |
1072 | atom_op_mul, ATOM_ARG_PLL}, { |
1072 | atom_op_mul, ATOM_ARG_MC}, { |
1073 | atom_op_mul, ATOM_ARG_MC}, { |
1073 | atom_op_div, ATOM_ARG_REG}, { |
1074 | atom_op_div, ATOM_ARG_REG}, { |
1074 | atom_op_div, ATOM_ARG_PS}, { |
1075 | atom_op_div, ATOM_ARG_PS}, { |
1075 | atom_op_div, ATOM_ARG_WS}, { |
1076 | atom_op_div, ATOM_ARG_WS}, { |
1076 | atom_op_div, ATOM_ARG_FB}, { |
1077 | atom_op_div, ATOM_ARG_FB}, { |
1077 | atom_op_div, ATOM_ARG_PLL}, { |
1078 | atom_op_div, ATOM_ARG_PLL}, { |
1078 | atom_op_div, ATOM_ARG_MC}, { |
1079 | atom_op_div, ATOM_ARG_MC}, { |
1079 | atom_op_add, ATOM_ARG_REG}, { |
1080 | atom_op_add, ATOM_ARG_REG}, { |
1080 | atom_op_add, ATOM_ARG_PS}, { |
1081 | atom_op_add, ATOM_ARG_PS}, { |
1081 | atom_op_add, ATOM_ARG_WS}, { |
1082 | atom_op_add, ATOM_ARG_WS}, { |
1082 | atom_op_add, ATOM_ARG_FB}, { |
1083 | atom_op_add, ATOM_ARG_FB}, { |
1083 | atom_op_add, ATOM_ARG_PLL}, { |
1084 | atom_op_add, ATOM_ARG_PLL}, { |
1084 | atom_op_add, ATOM_ARG_MC}, { |
1085 | atom_op_add, ATOM_ARG_MC}, { |
1085 | atom_op_sub, ATOM_ARG_REG}, { |
1086 | atom_op_sub, ATOM_ARG_REG}, { |
1086 | atom_op_sub, ATOM_ARG_PS}, { |
1087 | atom_op_sub, ATOM_ARG_PS}, { |
1087 | atom_op_sub, ATOM_ARG_WS}, { |
1088 | atom_op_sub, ATOM_ARG_WS}, { |
1088 | atom_op_sub, ATOM_ARG_FB}, { |
1089 | atom_op_sub, ATOM_ARG_FB}, { |
1089 | atom_op_sub, ATOM_ARG_PLL}, { |
1090 | atom_op_sub, ATOM_ARG_PLL}, { |
1090 | atom_op_sub, ATOM_ARG_MC}, { |
1091 | atom_op_sub, ATOM_ARG_MC}, { |
1091 | atom_op_setport, ATOM_PORT_ATI}, { |
1092 | atom_op_setport, ATOM_PORT_ATI}, { |
1092 | atom_op_setport, ATOM_PORT_PCI}, { |
1093 | atom_op_setport, ATOM_PORT_PCI}, { |
1093 | atom_op_setport, ATOM_PORT_SYSIO}, { |
1094 | atom_op_setport, ATOM_PORT_SYSIO}, { |
1094 | atom_op_setregblock, 0}, { |
1095 | atom_op_setregblock, 0}, { |
1095 | atom_op_setfbbase, 0}, { |
1096 | atom_op_setfbbase, 0}, { |
1096 | atom_op_compare, ATOM_ARG_REG}, { |
1097 | atom_op_compare, ATOM_ARG_REG}, { |
1097 | atom_op_compare, ATOM_ARG_PS}, { |
1098 | atom_op_compare, ATOM_ARG_PS}, { |
1098 | atom_op_compare, ATOM_ARG_WS}, { |
1099 | atom_op_compare, ATOM_ARG_WS}, { |
1099 | atom_op_compare, ATOM_ARG_FB}, { |
1100 | atom_op_compare, ATOM_ARG_FB}, { |
1100 | atom_op_compare, ATOM_ARG_PLL}, { |
1101 | atom_op_compare, ATOM_ARG_PLL}, { |
1101 | atom_op_compare, ATOM_ARG_MC}, { |
1102 | atom_op_compare, ATOM_ARG_MC}, { |
1102 | atom_op_switch, 0}, { |
1103 | atom_op_switch, 0}, { |
1103 | atom_op_jump, ATOM_COND_ALWAYS}, { |
1104 | atom_op_jump, ATOM_COND_ALWAYS}, { |
1104 | atom_op_jump, ATOM_COND_EQUAL}, { |
1105 | atom_op_jump, ATOM_COND_EQUAL}, { |
1105 | atom_op_jump, ATOM_COND_BELOW}, { |
1106 | atom_op_jump, ATOM_COND_BELOW}, { |
1106 | atom_op_jump, ATOM_COND_ABOVE}, { |
1107 | atom_op_jump, ATOM_COND_ABOVE}, { |
1107 | atom_op_jump, ATOM_COND_BELOWOREQUAL}, { |
1108 | atom_op_jump, ATOM_COND_BELOWOREQUAL}, { |
1108 | atom_op_jump, ATOM_COND_ABOVEOREQUAL}, { |
1109 | atom_op_jump, ATOM_COND_ABOVEOREQUAL}, { |
1109 | atom_op_jump, ATOM_COND_NOTEQUAL}, { |
1110 | atom_op_jump, ATOM_COND_NOTEQUAL}, { |
1110 | atom_op_test, ATOM_ARG_REG}, { |
1111 | atom_op_test, ATOM_ARG_REG}, { |
1111 | atom_op_test, ATOM_ARG_PS}, { |
1112 | atom_op_test, ATOM_ARG_PS}, { |
1112 | atom_op_test, ATOM_ARG_WS}, { |
1113 | atom_op_test, ATOM_ARG_WS}, { |
1113 | atom_op_test, ATOM_ARG_FB}, { |
1114 | atom_op_test, ATOM_ARG_FB}, { |
1114 | atom_op_test, ATOM_ARG_PLL}, { |
1115 | atom_op_test, ATOM_ARG_PLL}, { |
1115 | atom_op_test, ATOM_ARG_MC}, { |
1116 | atom_op_test, ATOM_ARG_MC}, { |
1116 | atom_op_delay, ATOM_UNIT_MILLISEC}, { |
1117 | atom_op_delay, ATOM_UNIT_MILLISEC}, { |
1117 | atom_op_delay, ATOM_UNIT_MICROSEC}, { |
1118 | atom_op_delay, ATOM_UNIT_MICROSEC}, { |
1118 | atom_op_calltable, 0}, { |
1119 | atom_op_calltable, 0}, { |
1119 | atom_op_repeat, 0}, { |
1120 | atom_op_repeat, 0}, { |
1120 | atom_op_clear, ATOM_ARG_REG}, { |
1121 | atom_op_clear, ATOM_ARG_REG}, { |
1121 | atom_op_clear, ATOM_ARG_PS}, { |
1122 | atom_op_clear, ATOM_ARG_PS}, { |
1122 | atom_op_clear, ATOM_ARG_WS}, { |
1123 | atom_op_clear, ATOM_ARG_WS}, { |
1123 | atom_op_clear, ATOM_ARG_FB}, { |
1124 | atom_op_clear, ATOM_ARG_FB}, { |
1124 | atom_op_clear, ATOM_ARG_PLL}, { |
1125 | atom_op_clear, ATOM_ARG_PLL}, { |
1125 | atom_op_clear, ATOM_ARG_MC}, { |
1126 | atom_op_clear, ATOM_ARG_MC}, { |
1126 | atom_op_nop, 0}, { |
1127 | atom_op_nop, 0}, { |
1127 | atom_op_eot, 0}, { |
1128 | atom_op_eot, 0}, { |
1128 | atom_op_mask, ATOM_ARG_REG}, { |
1129 | atom_op_mask, ATOM_ARG_REG}, { |
1129 | atom_op_mask, ATOM_ARG_PS}, { |
1130 | atom_op_mask, ATOM_ARG_PS}, { |
1130 | atom_op_mask, ATOM_ARG_WS}, { |
1131 | atom_op_mask, ATOM_ARG_WS}, { |
1131 | atom_op_mask, ATOM_ARG_FB}, { |
1132 | atom_op_mask, ATOM_ARG_FB}, { |
1132 | atom_op_mask, ATOM_ARG_PLL}, { |
1133 | atom_op_mask, ATOM_ARG_PLL}, { |
1133 | atom_op_mask, ATOM_ARG_MC}, { |
1134 | atom_op_mask, ATOM_ARG_MC}, { |
1134 | atom_op_postcard, 0}, { |
1135 | atom_op_postcard, 0}, { |
1135 | atom_op_beep, 0}, { |
1136 | atom_op_beep, 0}, { |
1136 | atom_op_savereg, 0}, { |
1137 | atom_op_savereg, 0}, { |
1137 | atom_op_restorereg, 0}, { |
1138 | atom_op_restorereg, 0}, { |
1138 | atom_op_setdatablock, 0}, { |
1139 | atom_op_setdatablock, 0}, { |
1139 | atom_op_xor, ATOM_ARG_REG}, { |
1140 | atom_op_xor, ATOM_ARG_REG}, { |
1140 | atom_op_xor, ATOM_ARG_PS}, { |
1141 | atom_op_xor, ATOM_ARG_PS}, { |
1141 | atom_op_xor, ATOM_ARG_WS}, { |
1142 | atom_op_xor, ATOM_ARG_WS}, { |
1142 | atom_op_xor, ATOM_ARG_FB}, { |
1143 | atom_op_xor, ATOM_ARG_FB}, { |
1143 | atom_op_xor, ATOM_ARG_PLL}, { |
1144 | atom_op_xor, ATOM_ARG_PLL}, { |
1144 | atom_op_xor, ATOM_ARG_MC}, { |
1145 | atom_op_xor, ATOM_ARG_MC}, { |
1145 | atom_op_shl, ATOM_ARG_REG}, { |
1146 | atom_op_shl, ATOM_ARG_REG}, { |
1146 | atom_op_shl, ATOM_ARG_PS}, { |
1147 | atom_op_shl, ATOM_ARG_PS}, { |
1147 | atom_op_shl, ATOM_ARG_WS}, { |
1148 | atom_op_shl, ATOM_ARG_WS}, { |
1148 | atom_op_shl, ATOM_ARG_FB}, { |
1149 | atom_op_shl, ATOM_ARG_FB}, { |
1149 | atom_op_shl, ATOM_ARG_PLL}, { |
1150 | atom_op_shl, ATOM_ARG_PLL}, { |
1150 | atom_op_shl, ATOM_ARG_MC}, { |
1151 | atom_op_shl, ATOM_ARG_MC}, { |
1151 | atom_op_shr, ATOM_ARG_REG}, { |
1152 | atom_op_shr, ATOM_ARG_REG}, { |
1152 | atom_op_shr, ATOM_ARG_PS}, { |
1153 | atom_op_shr, ATOM_ARG_PS}, { |
1153 | atom_op_shr, ATOM_ARG_WS}, { |
1154 | atom_op_shr, ATOM_ARG_WS}, { |
1154 | atom_op_shr, ATOM_ARG_FB}, { |
1155 | atom_op_shr, ATOM_ARG_FB}, { |
1155 | atom_op_shr, ATOM_ARG_PLL}, { |
1156 | atom_op_shr, ATOM_ARG_PLL}, { |
1156 | atom_op_shr, ATOM_ARG_MC}, { |
1157 | atom_op_shr, ATOM_ARG_MC}, { |
1157 | atom_op_debug, 0},}; |
1158 | atom_op_debug, 0},}; |
1158 | 1159 | ||
1159 | static int atom_execute_table_locked(struct atom_context *ctx, int index, uint32_t * params) |
1160 | static int atom_execute_table_locked(struct atom_context *ctx, int index, uint32_t * params) |
1160 | { |
1161 | { |
1161 | int base = CU16(ctx->cmd_table + 4 + 2 * index); |
1162 | int base = CU16(ctx->cmd_table + 4 + 2 * index); |
1162 | int len, ws, ps, ptr; |
1163 | int len, ws, ps, ptr; |
1163 | unsigned char op; |
1164 | unsigned char op; |
1164 | atom_exec_context ectx; |
1165 | atom_exec_context ectx; |
1165 | int ret = 0; |
1166 | int ret = 0; |
1166 | 1167 | ||
1167 | if (!base) |
1168 | if (!base) |
1168 | return -EINVAL; |
1169 | return -EINVAL; |
1169 | 1170 | ||
1170 | len = CU16(base + ATOM_CT_SIZE_PTR); |
1171 | len = CU16(base + ATOM_CT_SIZE_PTR); |
1171 | ws = CU8(base + ATOM_CT_WS_PTR); |
1172 | ws = CU8(base + ATOM_CT_WS_PTR); |
1172 | ps = CU8(base + ATOM_CT_PS_PTR) & ATOM_CT_PS_MASK; |
1173 | ps = CU8(base + ATOM_CT_PS_PTR) & ATOM_CT_PS_MASK; |
1173 | ptr = base + ATOM_CT_CODE_PTR; |
1174 | ptr = base + ATOM_CT_CODE_PTR; |
1174 | 1175 | ||
1175 | SDEBUG(">> execute %04X (len %d, WS %d, PS %d)\n", base, len, ws, ps); |
1176 | SDEBUG(">> execute %04X (len %d, WS %d, PS %d)\n", base, len, ws, ps); |
1176 | 1177 | ||
1177 | ectx.ctx = ctx; |
1178 | ectx.ctx = ctx; |
1178 | ectx.ps_shift = ps / 4; |
1179 | ectx.ps_shift = ps / 4; |
1179 | ectx.start = base; |
1180 | ectx.start = base; |
1180 | ectx.ps = params; |
1181 | ectx.ps = params; |
1181 | ectx.abort = false; |
1182 | ectx.abort = false; |
1182 | ectx.last_jump = 0; |
1183 | ectx.last_jump = 0; |
1183 | if (ws) |
1184 | if (ws) |
1184 | ectx.ws = kzalloc(4 * ws, GFP_KERNEL); |
1185 | ectx.ws = kzalloc(4 * ws, GFP_KERNEL); |
1185 | else |
1186 | else |
1186 | ectx.ws = NULL; |
1187 | ectx.ws = NULL; |
1187 | 1188 | ||
1188 | debug_depth++; |
1189 | debug_depth++; |
1189 | while (1) { |
1190 | while (1) { |
1190 | op = CU8(ptr++); |
1191 | op = CU8(ptr++); |
1191 | if (op < ATOM_OP_NAMES_CNT) |
1192 | if (op < ATOM_OP_NAMES_CNT) |
1192 | SDEBUG("%s @ 0x%04X\n", atom_op_names[op], ptr - 1); |
1193 | SDEBUG("%s @ 0x%04X\n", atom_op_names[op], ptr - 1); |
1193 | else |
1194 | else |
1194 | SDEBUG("[%d] @ 0x%04X\n", op, ptr - 1); |
1195 | SDEBUG("[%d] @ 0x%04X\n", op, ptr - 1); |
1195 | if (ectx.abort) { |
1196 | if (ectx.abort) { |
1196 | DRM_ERROR("atombios stuck executing %04X (len %d, WS %d, PS %d) @ 0x%04X\n", |
1197 | DRM_ERROR("atombios stuck executing %04X (len %d, WS %d, PS %d) @ 0x%04X\n", |
1197 | base, len, ws, ps, ptr - 1); |
1198 | base, len, ws, ps, ptr - 1); |
1198 | ret = -EINVAL; |
1199 | ret = -EINVAL; |
1199 | goto free; |
1200 | goto free; |
1200 | } |
1201 | } |
1201 | 1202 | ||
1202 | if (op < ATOM_OP_CNT && op > 0) |
1203 | if (op < ATOM_OP_CNT && op > 0) |
1203 | opcode_table[op].func(&ectx, &ptr, |
1204 | opcode_table[op].func(&ectx, &ptr, |
1204 | opcode_table[op].arg); |
1205 | opcode_table[op].arg); |
1205 | else |
1206 | else |
1206 | break; |
1207 | break; |
1207 | 1208 | ||
1208 | if (op == ATOM_OP_EOT) |
1209 | if (op == ATOM_OP_EOT) |
1209 | break; |
1210 | break; |
1210 | } |
1211 | } |
1211 | debug_depth--; |
1212 | debug_depth--; |
1212 | SDEBUG("<<\n"); |
1213 | SDEBUG("<<\n"); |
1213 | 1214 | ||
1214 | free: |
1215 | free: |
1215 | if (ws) |
1216 | if (ws) |
1216 | kfree(ectx.ws); |
1217 | kfree(ectx.ws); |
1217 | return ret; |
1218 | return ret; |
1218 | } |
1219 | } |
1219 | 1220 | ||
1220 | int atom_execute_table_scratch_unlocked(struct atom_context *ctx, int index, uint32_t * params) |
1221 | int atom_execute_table_scratch_unlocked(struct atom_context *ctx, int index, uint32_t * params) |
1221 | { |
1222 | { |
1222 | int r; |
1223 | int r; |
1223 | 1224 | ||
1224 | mutex_lock(&ctx->mutex); |
1225 | mutex_lock(&ctx->mutex); |
1225 | /* reset data block */ |
1226 | /* reset data block */ |
1226 | ctx->data_block = 0; |
1227 | ctx->data_block = 0; |
1227 | /* reset reg block */ |
1228 | /* reset reg block */ |
1228 | ctx->reg_block = 0; |
1229 | ctx->reg_block = 0; |
1229 | /* reset fb window */ |
1230 | /* reset fb window */ |
1230 | ctx->fb_base = 0; |
1231 | ctx->fb_base = 0; |
1231 | /* reset io mode */ |
1232 | /* reset io mode */ |
1232 | ctx->io_mode = ATOM_IO_MM; |
1233 | ctx->io_mode = ATOM_IO_MM; |
1233 | /* reset divmul */ |
1234 | /* reset divmul */ |
1234 | ctx->divmul[0] = 0; |
1235 | ctx->divmul[0] = 0; |
1235 | ctx->divmul[1] = 0; |
1236 | ctx->divmul[1] = 0; |
1236 | r = atom_execute_table_locked(ctx, index, params); |
1237 | r = atom_execute_table_locked(ctx, index, params); |
1237 | mutex_unlock(&ctx->mutex); |
1238 | mutex_unlock(&ctx->mutex); |
1238 | return r; |
1239 | return r; |
1239 | } |
1240 | } |
1240 | 1241 | ||
1241 | int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params) |
1242 | int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params) |
1242 | { |
1243 | { |
1243 | int r; |
1244 | int r; |
1244 | mutex_lock(&ctx->scratch_mutex); |
1245 | mutex_lock(&ctx->scratch_mutex); |
1245 | r = atom_execute_table_scratch_unlocked(ctx, index, params); |
1246 | r = atom_execute_table_scratch_unlocked(ctx, index, params); |
1246 | mutex_unlock(&ctx->scratch_mutex); |
1247 | mutex_unlock(&ctx->scratch_mutex); |
1247 | return r; |
1248 | return r; |
1248 | } |
1249 | } |
1249 | 1250 | ||
1250 | static int atom_iio_len[] = { 1, 2, 3, 3, 3, 3, 4, 4, 4, 3 }; |
1251 | static int atom_iio_len[] = { 1, 2, 3, 3, 3, 3, 4, 4, 4, 3 }; |
1251 | 1252 | ||
1252 | static void atom_index_iio(struct atom_context *ctx, int base) |
1253 | static void atom_index_iio(struct atom_context *ctx, int base) |
1253 | { |
1254 | { |
1254 | ctx->iio = kzalloc(2 * 256, GFP_KERNEL); |
1255 | ctx->iio = kzalloc(2 * 256, GFP_KERNEL); |
1255 | if (!ctx->iio) |
1256 | if (!ctx->iio) |
1256 | return; |
1257 | return; |
1257 | while (CU8(base) == ATOM_IIO_START) { |
1258 | while (CU8(base) == ATOM_IIO_START) { |
1258 | ctx->iio[CU8(base + 1)] = base + 2; |
1259 | ctx->iio[CU8(base + 1)] = base + 2; |
1259 | base += 2; |
1260 | base += 2; |
1260 | while (CU8(base) != ATOM_IIO_END) |
1261 | while (CU8(base) != ATOM_IIO_END) |
1261 | base += atom_iio_len[CU8(base)]; |
1262 | base += atom_iio_len[CU8(base)]; |
1262 | base += 3; |
1263 | base += 3; |
1263 | } |
1264 | } |
1264 | } |
1265 | } |
1265 | 1266 | ||
1266 | struct atom_context *atom_parse(struct card_info *card, void *bios) |
1267 | struct atom_context *atom_parse(struct card_info *card, void *bios) |
1267 | { |
1268 | { |
1268 | int base; |
1269 | int base; |
1269 | struct atom_context *ctx = |
1270 | struct atom_context *ctx = |
1270 | kzalloc(sizeof(struct atom_context), GFP_KERNEL); |
1271 | kzalloc(sizeof(struct atom_context), GFP_KERNEL); |
1271 | char *str; |
1272 | char *str; |
1272 | char name[512]; |
1273 | char name[512]; |
1273 | int i; |
1274 | int i; |
1274 | 1275 | ||
1275 | if (!ctx) |
1276 | if (!ctx) |
1276 | return NULL; |
1277 | return NULL; |
1277 | 1278 | ||
1278 | ctx->card = card; |
1279 | ctx->card = card; |
1279 | ctx->bios = bios; |
1280 | ctx->bios = bios; |
1280 | 1281 | ||
1281 | if (CU16(0) != ATOM_BIOS_MAGIC) { |
1282 | if (CU16(0) != ATOM_BIOS_MAGIC) { |
1282 | printk(KERN_INFO "Invalid BIOS magic.\n"); |
1283 | printk(KERN_INFO "Invalid BIOS magic.\n"); |
1283 | kfree(ctx); |
1284 | kfree(ctx); |
1284 | return NULL; |
1285 | return NULL; |
1285 | } |
1286 | } |
1286 | if (strncmp |
1287 | if (strncmp |
1287 | (CSTR(ATOM_ATI_MAGIC_PTR), ATOM_ATI_MAGIC, |
1288 | (CSTR(ATOM_ATI_MAGIC_PTR), ATOM_ATI_MAGIC, |
1288 | strlen(ATOM_ATI_MAGIC))) { |
1289 | strlen(ATOM_ATI_MAGIC))) { |
1289 | printk(KERN_INFO "Invalid ATI magic.\n"); |
1290 | printk(KERN_INFO "Invalid ATI magic.\n"); |
1290 | kfree(ctx); |
1291 | kfree(ctx); |
1291 | return NULL; |
1292 | return NULL; |
1292 | } |
1293 | } |
1293 | 1294 | ||
1294 | base = CU16(ATOM_ROM_TABLE_PTR); |
1295 | base = CU16(ATOM_ROM_TABLE_PTR); |
1295 | if (strncmp |
1296 | if (strncmp |
1296 | (CSTR(base + ATOM_ROM_MAGIC_PTR), ATOM_ROM_MAGIC, |
1297 | (CSTR(base + ATOM_ROM_MAGIC_PTR), ATOM_ROM_MAGIC, |
1297 | strlen(ATOM_ROM_MAGIC))) { |
1298 | strlen(ATOM_ROM_MAGIC))) { |
1298 | printk(KERN_INFO "Invalid ATOM magic.\n"); |
1299 | printk(KERN_INFO "Invalid ATOM magic.\n"); |
1299 | kfree(ctx); |
1300 | kfree(ctx); |
1300 | return NULL; |
1301 | return NULL; |
1301 | } |
1302 | } |
1302 | 1303 | ||
1303 | ctx->cmd_table = CU16(base + ATOM_ROM_CMD_PTR); |
1304 | ctx->cmd_table = CU16(base + ATOM_ROM_CMD_PTR); |
1304 | ctx->data_table = CU16(base + ATOM_ROM_DATA_PTR); |
1305 | ctx->data_table = CU16(base + ATOM_ROM_DATA_PTR); |
1305 | atom_index_iio(ctx, CU16(ctx->data_table + ATOM_DATA_IIO_PTR) + 4); |
1306 | atom_index_iio(ctx, CU16(ctx->data_table + ATOM_DATA_IIO_PTR) + 4); |
1306 | if (!ctx->iio) { |
1307 | if (!ctx->iio) { |
1307 | atom_destroy(ctx); |
1308 | atom_destroy(ctx); |
1308 | return NULL; |
1309 | return NULL; |
1309 | } |
1310 | } |
1310 | 1311 | ||
1311 | str = CSTR(CU16(base + ATOM_ROM_MSG_PTR)); |
1312 | str = CSTR(CU16(base + ATOM_ROM_MSG_PTR)); |
1312 | while (*str && ((*str == '\n') || (*str == '\r'))) |
1313 | while (*str && ((*str == '\n') || (*str == '\r'))) |
1313 | str++; |
1314 | str++; |
1314 | /* name string isn't always 0 terminated */ |
1315 | /* name string isn't always 0 terminated */ |
1315 | for (i = 0; i < 511; i++) { |
1316 | for (i = 0; i < 511; i++) { |
1316 | name[i] = str[i]; |
1317 | name[i] = str[i]; |
1317 | if (name[i] < '.' || name[i] > 'z') { |
1318 | if (name[i] < '.' || name[i] > 'z') { |
1318 | name[i] = 0; |
1319 | name[i] = 0; |
1319 | break; |
1320 | break; |
1320 | } |
1321 | } |
1321 | } |
1322 | } |
1322 | printk(KERN_INFO "ATOM BIOS: %s\n", name); |
1323 | printk(KERN_INFO "ATOM BIOS: %s\n", name); |
1323 | 1324 | ||
1324 | return ctx; |
1325 | return ctx; |
1325 | } |
1326 | } |
1326 | 1327 | ||
1327 | int atom_asic_init(struct atom_context *ctx) |
1328 | int atom_asic_init(struct atom_context *ctx) |
1328 | { |
1329 | { |
1329 | struct radeon_device *rdev = ctx->card->dev->dev_private; |
1330 | struct radeon_device *rdev = ctx->card->dev->dev_private; |
1330 | int hwi = CU16(ctx->data_table + ATOM_DATA_FWI_PTR); |
1331 | int hwi = CU16(ctx->data_table + ATOM_DATA_FWI_PTR); |
1331 | uint32_t ps[16]; |
1332 | uint32_t ps[16]; |
1332 | int ret; |
1333 | int ret; |
1333 | 1334 | ||
1334 | memset(ps, 0, 64); |
1335 | memset(ps, 0, 64); |
1335 | 1336 | ||
1336 | ps[0] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFSCLK_PTR)); |
1337 | ps[0] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFSCLK_PTR)); |
1337 | ps[1] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFMCLK_PTR)); |
1338 | ps[1] = cpu_to_le32(CU32(hwi + ATOM_FWI_DEFMCLK_PTR)); |
1338 | if (!ps[0] || !ps[1]) |
1339 | if (!ps[0] || !ps[1]) |
1339 | return 1; |
1340 | return 1; |
1340 | 1341 | ||
1341 | if (!CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_INIT)) |
1342 | if (!CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_INIT)) |
1342 | return 1; |
1343 | return 1; |
1343 | ret = atom_execute_table(ctx, ATOM_CMD_INIT, ps); |
1344 | ret = atom_execute_table(ctx, ATOM_CMD_INIT, ps); |
1344 | if (ret) |
1345 | if (ret) |
1345 | return ret; |
1346 | return ret; |
1346 | 1347 | ||
1347 | memset(ps, 0, 64); |
1348 | memset(ps, 0, 64); |
1348 | 1349 | ||
1349 | if (rdev->family < CHIP_R600) { |
1350 | if (rdev->family < CHIP_R600) { |
1350 | if (CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_SPDFANCNTL)) |
1351 | if (CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_SPDFANCNTL)) |
1351 | atom_execute_table(ctx, ATOM_CMD_SPDFANCNTL, ps); |
1352 | atom_execute_table(ctx, ATOM_CMD_SPDFANCNTL, ps); |
1352 | } |
1353 | } |
1353 | return ret; |
1354 | return ret; |
1354 | } |
1355 | } |
1355 | 1356 | ||
1356 | void atom_destroy(struct atom_context *ctx) |
1357 | void atom_destroy(struct atom_context *ctx) |
1357 | { |
1358 | { |
1358 | kfree(ctx->iio); |
1359 | kfree(ctx->iio); |
1359 | kfree(ctx); |
1360 | kfree(ctx); |
1360 | } |
1361 | } |
1361 | 1362 | ||
1362 | bool atom_parse_data_header(struct atom_context *ctx, int index, |
1363 | bool atom_parse_data_header(struct atom_context *ctx, int index, |
1363 | uint16_t * size, uint8_t * frev, uint8_t * crev, |
1364 | uint16_t * size, uint8_t * frev, uint8_t * crev, |
1364 | uint16_t * data_start) |
1365 | uint16_t * data_start) |
1365 | { |
1366 | { |
1366 | int offset = index * 2 + 4; |
1367 | int offset = index * 2 + 4; |
1367 | int idx = CU16(ctx->data_table + offset); |
1368 | int idx = CU16(ctx->data_table + offset); |
1368 | u16 *mdt = (u16 *)(ctx->bios + ctx->data_table + 4); |
1369 | u16 *mdt = (u16 *)(ctx->bios + ctx->data_table + 4); |
1369 | 1370 | ||
1370 | if (!mdt[index]) |
1371 | if (!mdt[index]) |
1371 | return false; |
1372 | return false; |
1372 | 1373 | ||
1373 | if (size) |
1374 | if (size) |
1374 | *size = CU16(idx); |
1375 | *size = CU16(idx); |
1375 | if (frev) |
1376 | if (frev) |
1376 | *frev = CU8(idx + 2); |
1377 | *frev = CU8(idx + 2); |
1377 | if (crev) |
1378 | if (crev) |
1378 | *crev = CU8(idx + 3); |
1379 | *crev = CU8(idx + 3); |
1379 | *data_start = idx; |
1380 | *data_start = idx; |
1380 | return true; |
1381 | return true; |
1381 | } |
1382 | } |
1382 | 1383 | ||
1383 | bool atom_parse_cmd_header(struct atom_context *ctx, int index, uint8_t * frev, |
1384 | bool atom_parse_cmd_header(struct atom_context *ctx, int index, uint8_t * frev, |
1384 | uint8_t * crev) |
1385 | uint8_t * crev) |
1385 | { |
1386 | { |
1386 | int offset = index * 2 + 4; |
1387 | int offset = index * 2 + 4; |
1387 | int idx = CU16(ctx->cmd_table + offset); |
1388 | int idx = CU16(ctx->cmd_table + offset); |
1388 | u16 *mct = (u16 *)(ctx->bios + ctx->cmd_table + 4); |
1389 | u16 *mct = (u16 *)(ctx->bios + ctx->cmd_table + 4); |
1389 | 1390 | ||
1390 | if (!mct[index]) |
1391 | if (!mct[index]) |
1391 | return false; |
1392 | return false; |
1392 | 1393 | ||
1393 | if (frev) |
1394 | if (frev) |
1394 | *frev = CU8(idx + 2); |
1395 | *frev = CU8(idx + 2); |
1395 | if (crev) |
1396 | if (crev) |
1396 | *crev = CU8(idx + 3); |
1397 | *crev = CU8(idx + 3); |
1397 | return true; |
1398 | return true; |
1398 | } |
1399 | } |
1399 | 1400 | ||
1400 | int atom_allocate_fb_scratch(struct atom_context *ctx) |
1401 | int atom_allocate_fb_scratch(struct atom_context *ctx) |
1401 | { |
1402 | { |
1402 | int index = GetIndexIntoMasterTable(DATA, VRAM_UsageByFirmware); |
1403 | int index = GetIndexIntoMasterTable(DATA, VRAM_UsageByFirmware); |
1403 | uint16_t data_offset; |
1404 | uint16_t data_offset; |
1404 | int usage_bytes = 0; |
1405 | int usage_bytes = 0; |
1405 | struct _ATOM_VRAM_USAGE_BY_FIRMWARE *firmware_usage; |
1406 | struct _ATOM_VRAM_USAGE_BY_FIRMWARE *firmware_usage; |
1406 | 1407 | ||
1407 | if (atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset)) { |
1408 | if (atom_parse_data_header(ctx, index, NULL, NULL, NULL, &data_offset)) { |
1408 | firmware_usage = (struct _ATOM_VRAM_USAGE_BY_FIRMWARE *)(ctx->bios + data_offset); |
1409 | firmware_usage = (struct _ATOM_VRAM_USAGE_BY_FIRMWARE *)(ctx->bios + data_offset); |
1409 | 1410 | ||
1410 | DRM_DEBUG("atom firmware requested %08x %dkb\n", |
1411 | DRM_DEBUG("atom firmware requested %08x %dkb\n", |
1411 | le32_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].ulStartAddrUsedByFirmware), |
1412 | le32_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].ulStartAddrUsedByFirmware), |
1412 | le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb)); |
1413 | le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb)); |
1413 | 1414 | ||
1414 | usage_bytes = le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb) * 1024; |
1415 | usage_bytes = le16_to_cpu(firmware_usage->asFirmwareVramReserveInfo[0].usFirmwareUseInKb) * 1024; |
1415 | } |
1416 | } |
1416 | ctx->scratch_size_bytes = 0; |
1417 | ctx->scratch_size_bytes = 0; |
1417 | if (usage_bytes == 0) |
1418 | if (usage_bytes == 0) |
1418 | usage_bytes = 20 * 1024; |
1419 | usage_bytes = 20 * 1024; |
1419 | /* allocate some scratch memory */ |
1420 | /* allocate some scratch memory */ |
1420 | ctx->scratch = kzalloc(usage_bytes, GFP_KERNEL); |
1421 | ctx->scratch = kzalloc(usage_bytes, GFP_KERNEL); |
1421 | if (!ctx->scratch) |
1422 | if (!ctx->scratch) |
1422 | return -ENOMEM; |
1423 | return -ENOMEM; |
1423 | ctx->scratch_size_bytes = usage_bytes; |
1424 | ctx->scratch_size_bytes = usage_bytes; |
1424 | return 0; |
1425 | return 0; |
1425 | }>>>\n"); |
1426 | }>>>\n"); |
1426 | 1427 | ||
1427 | free: |
1428 | free: |
1428 | ><\n"); |
1429 | ><\n"); |
1429 | 1430 | ||
1430 | free: |
1431 | free: |
1431 | >>>=><=>><>=><=>><>>><>>->->->->->->->->><>=><=>><>><>><>><>><> |
1432 | >>>=><=>><>=><=>><>>><>>->->->->->->->->><>=><=>><>><>><>><>><> |
1432 | >< |
1433 | >< |
1433 | >><> |
1434 | >><> |
1434 | >< |
1435 | >< |
1435 | >><> |
1436 | >><> |
1436 | >< |
1437 | >< |
1437 | >><> |
1438 | >><> |
1438 | >< |
1439 | >< |
1439 | > |
1440 | > |