Rev 6661 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6661 | Rev 6938 | ||
---|---|---|---|
1 | #include |
1 | #include |
2 | #include |
2 | #include |
3 | #include |
3 | #include |
4 | #include "radeon_reg.h" |
4 | #include "radeon_reg.h" |
5 | #include "radeon.h" |
5 | #include "radeon.h" |
6 | #include "bitmap.h" |
6 | #include "bitmap.h" |
7 | 7 | ||
8 | #define DRV_NAME "atikms v4.4.30" |
8 | #define DRV_NAME "atikms v4.5.7" |
- | 9 | ||
- | 10 | void __init dmi_scan_machine(void); |
|
- | 11 | int printf ( const char * format, ... ); |
|
9 | 12 | void parse_cmdline(char *cmdline, videomode_t *mode, char *log, int *kms); |
|
10 | void __init dmi_scan_machine(void); |
13 | int kmap_init(); |
11 | 14 | ||
12 | #define KMS_DEV_CLOSE 0 |
15 | #define KMS_DEV_CLOSE 0 |
13 | #define KMS_DEV_INIT 1 |
16 | #define KMS_DEV_INIT 1 |
14 | #define KMS_DEV_READY 2 |
17 | #define KMS_DEV_READY 2 |
15 | 18 | ||
16 | struct drm_device *main_device; |
19 | struct drm_device *main_device; |
17 | struct drm_file *drm_file_handlers[256]; |
20 | struct drm_file *drm_file_handlers[256]; |
18 | int oops_in_progress; |
21 | int oops_in_progress; |
19 | 22 | ||
20 | videomode_t usermode; |
23 | videomode_t usermode; |
21 | 24 | ||
22 | void cpu_detect1(); |
25 | void cpu_detect1(); |
23 | 26 | ||
24 | int _stdcall display_handler(ioctl_t *io); |
27 | int _stdcall display_handler(ioctl_t *io); |
25 | static char log[256]; |
28 | static char log[256]; |
26 | 29 | ||
27 | unsigned long volatile jiffies; |
30 | unsigned long volatile jiffies; |
28 | u64 jiffies_64; |
31 | u64 jiffies_64; |
29 | 32 | ||
30 | struct workqueue_struct *system_wq; |
33 | struct workqueue_struct *system_wq; |
31 | int driver_wq_state; |
34 | int driver_wq_state; |
32 | 35 | ||
33 | int x86_clflush_size; |
36 | int x86_clflush_size; |
34 | 37 | ||
35 | void ati_driver_thread() |
38 | void ati_driver_thread() |
36 | { |
39 | { |
37 | struct radeon_device *rdev = NULL; |
40 | struct radeon_device *rdev = NULL; |
38 | struct workqueue_struct *cwq = NULL; |
41 | struct workqueue_struct *cwq = NULL; |
39 | // static int dpms = 1; |
42 | // static int dpms = 1; |
40 | // static int dpms_lock = 0; |
43 | // static int dpms_lock = 0; |
41 | // oskey_t key; |
44 | // oskey_t key; |
42 | unsigned long irqflags; |
45 | unsigned long irqflags; |
43 | int tmp; |
46 | int tmp; |
44 | 47 | ||
45 | printf("%s\n",__FUNCTION__); |
48 | printf("%s\n",__FUNCTION__); |
46 | 49 | ||
47 | while(driver_wq_state == KMS_DEV_INIT) |
50 | while(driver_wq_state == KMS_DEV_INIT) |
48 | { |
51 | { |
49 | jiffies_64 = GetClockNs() / 10000000; |
52 | jiffies_64 = GetClockNs() / 10000000; |
50 | jiffies = (unsigned long)jiffies_64; |
53 | jiffies = (unsigned long)jiffies_64; |
51 | 54 | ||
52 | delay(1); |
55 | delay(1); |
53 | }; |
56 | }; |
54 | 57 | ||
55 | rdev = main_device->dev_private; |
58 | rdev = main_device->dev_private; |
56 | // cwq = rdev->wq; |
59 | // cwq = rdev->wq; |
57 | 60 | ||
58 | asm volatile("int $0x40":"=a"(tmp):"a"(66),"b"(1),"c"(1)); |
61 | asm volatile("int $0x40":"=a"(tmp):"a"(66),"b"(1),"c"(1)); |
59 | asm volatile("int $0x40":"=a"(tmp):"a"(66),"b"(4),"c"(0x46),"d"(0x330)); |
62 | asm volatile("int $0x40":"=a"(tmp):"a"(66),"b"(4),"c"(0x46),"d"(0x330)); |
60 | asm volatile("int $0x40":"=a"(tmp):"a"(66),"b"(4),"c"(0xC6),"d"(0x330)); |
63 | asm volatile("int $0x40":"=a"(tmp):"a"(66),"b"(4),"c"(0xC6),"d"(0x330)); |
61 | 64 | ||
62 | while(driver_wq_state != KMS_DEV_CLOSE) |
65 | while(driver_wq_state != KMS_DEV_CLOSE) |
63 | { |
66 | { |
64 | jiffies = GetTimerTicks(); |
67 | jiffies = GetTimerTicks(); |
65 | #if 0 |
68 | #if 0 |
66 | key = get_key(); |
69 | key = get_key(); |
67 | 70 | ||
68 | if( (key.val != 1) && (key.state == 0x02)) |
71 | if( (key.val != 1) && (key.state == 0x02)) |
69 | { |
72 | { |
70 | if(key.code == 0x46 && dpms_lock == 0) |
73 | if(key.code == 0x46 && dpms_lock == 0) |
71 | { |
74 | { |
72 | dpms_lock = 1; |
75 | dpms_lock = 1; |
73 | if(dpms == 1) |
76 | if(dpms == 1) |
74 | { |
77 | { |
75 | i915_dpms(main_device, DRM_MODE_DPMS_OFF); |
78 | i915_dpms(main_device, DRM_MODE_DPMS_OFF); |
76 | printf("dpms off\n"); |
79 | printf("dpms off\n"); |
77 | } |
80 | } |
78 | else |
81 | else |
79 | { |
82 | { |
80 | i915_dpms(main_device, DRM_MODE_DPMS_ON); |
83 | i915_dpms(main_device, DRM_MODE_DPMS_ON); |
81 | printf("dpms on\n"); |
84 | printf("dpms on\n"); |
82 | }; |
85 | }; |
83 | dpms ^= 1; |
86 | dpms ^= 1; |
84 | } |
87 | } |
85 | else if(key.code == 0xC6) |
88 | else if(key.code == 0xC6) |
86 | dpms_lock = 0; |
89 | dpms_lock = 0; |
87 | }; |
90 | }; |
88 | spin_lock_irqsave(&cwq->lock, irqflags); |
91 | spin_lock_irqsave(&cwq->lock, irqflags); |
89 | 92 | ||
90 | while (!list_empty(&cwq->worklist)) |
93 | while (!list_empty(&cwq->worklist)) |
91 | { |
94 | { |
92 | struct work_struct *work = list_entry(cwq->worklist.next, |
95 | struct work_struct *work = list_entry(cwq->worklist.next, |
93 | struct work_struct, entry); |
96 | struct work_struct, entry); |
94 | work_func_t f = work->func; |
97 | work_func_t f = work->func; |
95 | list_del_init(cwq->worklist.next); |
98 | list_del_init(cwq->worklist.next); |
96 | 99 | ||
97 | spin_unlock_irqrestore(&cwq->lock, irqflags); |
100 | spin_unlock_irqrestore(&cwq->lock, irqflags); |
98 | f(work); |
101 | f(work); |
99 | spin_lock_irqsave(&cwq->lock, irqflags); |
102 | spin_lock_irqsave(&cwq->lock, irqflags); |
100 | } |
103 | } |
101 | 104 | ||
102 | spin_unlock_irqrestore(&cwq->lock, irqflags); |
105 | spin_unlock_irqrestore(&cwq->lock, irqflags); |
103 | #endif |
106 | #endif |
104 | 107 | ||
105 | delay(1); |
108 | delay(1); |
106 | }; |
109 | }; |
107 | 110 | ||
108 | asm volatile ("int $0x40"::"a"(-1)); |
111 | asm volatile ("int $0x40"::"a"(-1)); |
109 | } |
112 | } |
110 | 113 | ||
111 | u32 __attribute__((externally_visible)) drvEntry(int action, char *cmdline) |
114 | u32 __attribute__((externally_visible)) drvEntry(int action, char *cmdline) |
112 | { |
115 | { |
113 | struct radeon_device *rdev = NULL; |
116 | struct radeon_device *rdev = NULL; |
114 | 117 | ||
115 | const struct pci_device_id *ent; |
118 | const struct pci_device_id *ent; |
116 | 119 | ||
117 | int err = 0; |
120 | int err = 0; |
118 | 121 | ||
119 | if(action != 1) |
122 | if(action != 1) |
120 | { |
123 | { |
121 | driver_wq_state = KMS_DEV_CLOSE; |
124 | driver_wq_state = KMS_DEV_CLOSE; |
122 | return 0; |
125 | return 0; |
123 | }; |
126 | }; |
124 | 127 | ||
125 | if( GetService("DISPLAY") != 0 ) |
128 | if( GetService("DISPLAY") != 0 ) |
126 | return 0; |
129 | return 0; |
127 | 130 | ||
128 | printf("%s cmdline %s\n",DRV_NAME, cmdline); |
131 | printf("%s cmdline %s\n",DRV_NAME, cmdline); |
129 | 132 | ||
130 | if( cmdline && *cmdline ) |
133 | if( cmdline && *cmdline ) |
131 | parse_cmdline(cmdline, &usermode, log, &radeon_modeset); |
134 | parse_cmdline(cmdline, &usermode, log, &radeon_modeset); |
132 | 135 | ||
133 | if( *log && !dbg_open(log)) |
136 | if( *log && !dbg_open(log)) |
134 | { |
137 | { |
135 | printf("Can't open %s\nExit\n", log); |
138 | printf("Can't open %s\nExit\n", log); |
136 | return 0; |
139 | return 0; |
137 | } |
140 | } |
138 | else |
141 | else |
139 | { |
142 | { |
140 | dbgprintf("\nLOG: %s build %s %s\n",DRV_NAME,__DATE__, __TIME__); |
143 | dbgprintf("\nLOG: %s build %s %s\n",DRV_NAME,__DATE__, __TIME__); |
141 | } |
144 | } |
142 | 145 | ||
143 | cpu_detect1(); |
146 | cpu_detect1(); |
144 | 147 | ||
145 | err = enum_pci_devices(); |
148 | err = enum_pci_devices(); |
146 | if( unlikely(err != 0) ) |
149 | if( unlikely(err != 0) ) |
147 | { |
150 | { |
148 | dbgprintf("Device enumeration failed\n"); |
151 | dbgprintf("Device enumeration failed\n"); |
149 | return 0; |
152 | return 0; |
150 | } |
153 | } |
151 | 154 | ||
152 | err = kmap_init(); |
155 | err = kmap_init(); |
153 | if( unlikely(err != 0) ) |
156 | if( unlikely(err != 0) ) |
154 | { |
157 | { |
155 | dbgprintf("kmap initialization failed\n"); |
158 | dbgprintf("kmap initialization failed\n"); |
156 | return 0; |
159 | return 0; |
157 | } |
160 | } |
158 | 161 | ||
159 | dmi_scan_machine(); |
162 | dmi_scan_machine(); |
160 | 163 | ||
161 | 164 | ||
162 | driver_wq_state = KMS_DEV_INIT; |
165 | driver_wq_state = KMS_DEV_INIT; |
163 | CreateKernelThread(ati_driver_thread); |
166 | CreateKernelThread(ati_driver_thread); |
164 | 167 | ||
165 | err = ati_init(); |
168 | err = ati_init(); |
166 | if(unlikely(err!= 0)) |
169 | if(unlikely(err!= 0)) |
167 | { |
170 | { |
168 | driver_wq_state = KMS_DEV_CLOSE; |
171 | driver_wq_state = KMS_DEV_CLOSE; |
169 | dbgprintf("Epic Fail :(\n"); |
172 | dbgprintf("Epic Fail :(\n"); |
170 | return 0; |
173 | return 0; |
171 | }; |
174 | }; |
172 | 175 | ||
173 | driver_wq_state = KMS_DEV_READY; |
176 | driver_wq_state = KMS_DEV_READY; |
174 | 177 | ||
175 | rdev = main_device->dev_private; |
178 | rdev = main_device->dev_private; |
176 | printf("current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev)); |
179 | printf("current engine clock: %u0 kHz\n", radeon_get_engine_clock(rdev)); |
177 | printf("current memory clock: %u0 kHz\n", radeon_get_memory_clock(rdev)); |
180 | printf("current memory clock: %u0 kHz\n", radeon_get_memory_clock(rdev)); |
178 | 181 | ||
179 | err = RegService("DISPLAY", display_handler); |
182 | err = RegService("DISPLAY", display_handler); |
180 | 183 | ||
181 | if( err != 0) |
184 | if( err != 0) |
182 | dbgprintf("DISPLAY service installed\n"); |
185 | dbgprintf("DISPLAY service installed\n"); |
183 | 186 | ||
184 | 187 | ||
185 | return err; |
188 | return err; |
186 | }; |
189 | }; |
187 | 190 | ||
188 | 191 | ||
189 | 192 | ||
190 | #define CURRENT_API 0x0200 /* 2.00 */ |
193 | #define CURRENT_API 0x0200 /* 2.00 */ |
191 | #define COMPATIBLE_API 0x0100 /* 1.00 */ |
194 | #define COMPATIBLE_API 0x0100 /* 1.00 */ |
192 | 195 | ||
193 | #define API_VERSION (COMPATIBLE_API << 16) | CURRENT_API |
196 | #define API_VERSION (COMPATIBLE_API << 16) | CURRENT_API |
194 | 197 | ||
195 | #define SRV_GETVERSION 0 |
198 | #define SRV_GETVERSION 0 |
196 | #define SRV_ENUM_MODES 1 |
199 | #define SRV_ENUM_MODES 1 |
197 | #define SRV_SET_MODE 2 |
200 | #define SRV_SET_MODE 2 |
198 | #define SRV_GET_CAPS 3 |
201 | #define SRV_GET_CAPS 3 |
199 | 202 | ||
200 | #define SRV_CREATE_SURFACE 10 |
203 | #define SRV_CREATE_SURFACE 10 |
201 | #define SRV_DESTROY_SURFACE 11 |
204 | #define SRV_DESTROY_SURFACE 11 |
202 | #define SRV_LOCK_SURFACE 12 |
205 | #define SRV_LOCK_SURFACE 12 |
203 | #define SRV_UNLOCK_SURFACE 13 |
206 | #define SRV_UNLOCK_SURFACE 13 |
204 | #define SRV_RESIZE_SURFACE 14 |
207 | #define SRV_RESIZE_SURFACE 14 |
205 | #define SRV_BLIT_BITMAP 15 |
208 | #define SRV_BLIT_BITMAP 15 |
206 | #define SRV_BLIT_TEXTURE 16 |
209 | #define SRV_BLIT_TEXTURE 16 |
207 | #define SRV_BLIT_VIDEO 17 |
210 | #define SRV_BLIT_VIDEO 17 |
208 | 211 | ||
209 | 212 | ||
210 | 213 | ||
211 | int r600_video_blit(uint64_t src_offset, int x, int y, |
214 | int r600_video_blit(uint64_t src_offset, int x, int y, |
212 | int w, int h, int pitch); |
215 | int w, int h, int pitch); |
213 | 216 | ||
214 | #define check_input(size) \ |
217 | #define check_input(size) \ |
215 | if( unlikely((inp==NULL)||(io->inp_size != (size))) ) \ |
218 | if( unlikely((inp==NULL)||(io->inp_size != (size))) ) \ |
216 | break; |
219 | break; |
217 | 220 | ||
218 | #define check_output(size) \ |
221 | #define check_output(size) \ |
219 | if( unlikely((outp==NULL)||(io->out_size != (size))) ) \ |
222 | if( unlikely((outp==NULL)||(io->out_size != (size))) ) \ |
220 | break; |
223 | break; |
221 | 224 | ||
222 | int _stdcall display_handler(ioctl_t *io) |
225 | int _stdcall display_handler(ioctl_t *io) |
223 | { |
226 | { |
224 | int retval = -1; |
227 | int retval = -1; |
225 | u32 *inp; |
228 | u32 *inp; |
226 | u32 *outp; |
229 | u32 *outp; |
227 | 230 | ||
228 | inp = io->input; |
231 | inp = io->input; |
229 | outp = io->output; |
232 | outp = io->output; |
230 | 233 | ||
231 | switch(io->io_code) |
234 | switch(io->io_code) |
232 | { |
235 | { |
233 | case SRV_GETVERSION: |
236 | case SRV_GETVERSION: |
234 | check_output(4); |
237 | check_output(4); |
235 | *outp = API_VERSION; |
238 | *outp = API_VERSION; |
236 | retval = 0; |
239 | retval = 0; |
237 | break; |
240 | break; |
238 | 241 | ||
239 | case SRV_ENUM_MODES: |
242 | case SRV_ENUM_MODES: |
240 | // dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n", |
243 | // dbgprintf("SRV_ENUM_MODES inp %x inp_size %x out_size %x\n", |
241 | // inp, io->inp_size, io->out_size ); |
244 | // inp, io->inp_size, io->out_size ); |
242 | check_output(4); |
245 | check_output(4); |
243 | if( radeon_modeset) |
246 | if( radeon_modeset) |
244 | retval = get_videomodes((videomode_t*)inp, outp); |
247 | retval = get_videomodes((videomode_t*)inp, outp); |
245 | break; |
248 | break; |
246 | 249 | ||
247 | case SRV_SET_MODE: |
250 | case SRV_SET_MODE: |
248 | // dbgprintf("SRV_SET_MODE inp %x inp_size %x\n", |
251 | // dbgprintf("SRV_SET_MODE inp %x inp_size %x\n", |
249 | // inp, io->inp_size); |
252 | // inp, io->inp_size); |
250 | check_input(sizeof(videomode_t)); |
253 | check_input(sizeof(videomode_t)); |
251 | if( radeon_modeset ) |
254 | if( radeon_modeset ) |
252 | retval = set_user_mode((videomode_t*)inp); |
255 | retval = set_user_mode((videomode_t*)inp); |
253 | break; |
256 | break; |
254 | /* |
257 | /* |
255 | case SRV_GET_CAPS: |
258 | case SRV_GET_CAPS: |
256 | retval = get_driver_caps((hwcaps_t*)inp); |
259 | retval = get_driver_caps((hwcaps_t*)inp); |
257 | break; |
260 | break; |
258 | 261 | ||
259 | case SRV_CREATE_SURFACE: |
262 | case SRV_CREATE_SURFACE: |
260 | // check_input(8); |
263 | // check_input(8); |
261 | retval = create_surface(main_drm_device, (struct io_call_10*)inp); |
264 | retval = create_surface(main_drm_device, (struct io_call_10*)inp); |
262 | break; |
265 | break; |
263 | 266 | ||
264 | case SRV_LOCK_SURFACE: |
267 | case SRV_LOCK_SURFACE: |
265 | retval = lock_surface((struct io_call_12*)inp); |
268 | retval = lock_surface((struct io_call_12*)inp); |
266 | break; |
269 | break; |
267 | 270 | ||
268 | case SRV_BLIT_BITMAP: |
271 | case SRV_BLIT_BITMAP: |
269 | srv_blit_bitmap( inp[0], inp[1], inp[2], |
272 | srv_blit_bitmap( inp[0], inp[1], inp[2], |
270 | inp[3], inp[4], inp[5], inp[6]); |
273 | inp[3], inp[4], inp[5], inp[6]); |
271 | */ |
274 | */ |
272 | }; |
275 | }; |
273 | 276 | ||
274 | return retval; |
277 | return retval; |
275 | } |
278 | } |
276 | 279 | ||
277 | 280 | ||
278 | #define PCI_CLASS_REVISION 0x08 |
281 | #define PCI_CLASS_REVISION 0x08 |
279 | #define PCI_CLASS_DISPLAY_VGA 0x0300 |
282 | #define PCI_CLASS_DISPLAY_VGA 0x0300 |
280 | 283 | ||
281 | int pci_scan_filter(u32 id, u32 busnr, u32 devfn) |
284 | int pci_scan_filter(u32 id, u32 busnr, u32 devfn) |
282 | { |
285 | { |
283 | u16 vendor, device; |
286 | u16 vendor, device; |
284 | u32 class; |
287 | u32 class; |
285 | int ret = 0; |
288 | int ret = 0; |
286 | 289 | ||
287 | vendor = id & 0xffff; |
290 | vendor = id & 0xffff; |
288 | device = (id >> 16) & 0xffff; |
291 | device = (id >> 16) & 0xffff; |
289 | 292 | ||
290 | if(vendor == 0x1002) |
293 | if(vendor == 0x1002) |
291 | { |
294 | { |
292 | class = PciRead32(busnr, devfn, PCI_CLASS_REVISION); |
295 | class = PciRead32(busnr, devfn, PCI_CLASS_REVISION); |
293 | class >>= 24; |
296 | class >>= 24; |
294 | 297 | ||
295 | if( class ==PCI_BASE_CLASS_DISPLAY) |
298 | if( class ==PCI_BASE_CLASS_DISPLAY) |
296 | ret = 1; |
299 | ret = 1; |
297 | } |
300 | } |
298 | return ret; |
301 | return ret; |
299 | } |
302 | } |
300 | 303 | ||
301 | 304 | ||
302 | int seq_printf(struct seq_file *m, const char *f, ...) |
305 | int seq_printf(struct seq_file *m, const char *f, ...) |
303 | { |
306 | { |
304 | // int ret; |
307 | // int ret; |
305 | // va_list args; |
308 | // va_list args; |
306 | 309 | ||
307 | // va_start(args, f); |
310 | // va_start(args, f); |
308 | // ret = seq_vprintf(m, f, args); |
311 | // ret = seq_vprintf(m, f, args); |
309 | // va_end(args); |
312 | // va_end(args); |
310 | 313 | ||
311 | // return ret; |
314 | // return ret; |
312 | return 0; |
315 | return 0; |
313 | } |
316 | }><> |
314 | - | ||
315 | s64 div64_s64(s64 dividend, s64 divisor) |
- | |
316 | { |
- | |
317 | s64 quot, t; |
- | |
318 | - | ||
319 | quot = div64_u64(abs(dividend), abs(divisor)); |
- | |
320 | t = (dividend ^ divisor) >> 63; |
- | |
321 | - | ||
322 | return (quot ^ t) - t; |
- | |
323 | }><> |
- | |
324 | - |