treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / radeon / radeon_bios.c
blobc42f73fad3e3156f73b668b559d0231f9ed15b92
1 /*
2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
24 * Authors: Dave Airlie
25 * Alex Deucher
26 * Jerome Glisse
29 #include <linux/acpi.h>
30 #include <linux/pci.h>
31 #include <linux/slab.h>
33 #include <drm/drm_device.h>
35 #include "atom.h"
36 #include "radeon.h"
37 #include "radeon_reg.h"
40 * BIOS.
43 /* If you boot an IGP board with a discrete card as the primary,
44 * the IGP rom is not accessible via the rom bar as the IGP rom is
45 * part of the system bios. On boot, the system bios puts a
46 * copy of the igp rom at the start of vram if a discrete card is
47 * present.
49 static bool igp_read_bios_from_vram(struct radeon_device *rdev)
51 uint8_t __iomem *bios;
52 resource_size_t vram_base;
53 resource_size_t size = 256 * 1024; /* ??? */
55 if (!(rdev->flags & RADEON_IS_IGP))
56 if (!radeon_card_posted(rdev))
57 return false;
59 rdev->bios = NULL;
60 vram_base = pci_resource_start(rdev->pdev, 0);
61 bios = ioremap(vram_base, size);
62 if (!bios) {
63 return false;
66 if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) {
67 iounmap(bios);
68 return false;
70 rdev->bios = kmalloc(size, GFP_KERNEL);
71 if (rdev->bios == NULL) {
72 iounmap(bios);
73 return false;
75 memcpy_fromio(rdev->bios, bios, size);
76 iounmap(bios);
77 return true;
80 static bool radeon_read_bios(struct radeon_device *rdev)
82 uint8_t __iomem *bios, val1, val2;
83 size_t size;
85 rdev->bios = NULL;
86 /* XXX: some cards may return 0 for rom size? ddx has a workaround */
87 bios = pci_map_rom(rdev->pdev, &size);
88 if (!bios) {
89 return false;
92 val1 = readb(&bios[0]);
93 val2 = readb(&bios[1]);
95 if (size == 0 || val1 != 0x55 || val2 != 0xaa) {
96 pci_unmap_rom(rdev->pdev, bios);
97 return false;
99 rdev->bios = kzalloc(size, GFP_KERNEL);
100 if (rdev->bios == NULL) {
101 pci_unmap_rom(rdev->pdev, bios);
102 return false;
104 memcpy_fromio(rdev->bios, bios, size);
105 pci_unmap_rom(rdev->pdev, bios);
106 return true;
109 static bool radeon_read_platform_bios(struct radeon_device *rdev)
111 uint8_t __iomem *bios;
112 size_t size;
114 rdev->bios = NULL;
116 bios = pci_platform_rom(rdev->pdev, &size);
117 if (!bios) {
118 return false;
121 if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) {
122 return false;
124 rdev->bios = kmemdup(bios, size, GFP_KERNEL);
125 if (rdev->bios == NULL) {
126 return false;
129 return true;
132 #ifdef CONFIG_ACPI
133 /* ATRM is used to get the BIOS on the discrete cards in
134 * dual-gpu systems.
136 /* retrieve the ROM in 4k blocks */
137 #define ATRM_BIOS_PAGE 4096
139 * radeon_atrm_call - fetch a chunk of the vbios
141 * @atrm_handle: acpi ATRM handle
142 * @bios: vbios image pointer
143 * @offset: offset of vbios image data to fetch
144 * @len: length of vbios image data to fetch
146 * Executes ATRM to fetch a chunk of the discrete
147 * vbios image on PX systems (all asics).
148 * Returns the length of the buffer fetched.
150 static int radeon_atrm_call(acpi_handle atrm_handle, uint8_t *bios,
151 int offset, int len)
153 acpi_status status;
154 union acpi_object atrm_arg_elements[2], *obj;
155 struct acpi_object_list atrm_arg;
156 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
158 atrm_arg.count = 2;
159 atrm_arg.pointer = &atrm_arg_elements[0];
161 atrm_arg_elements[0].type = ACPI_TYPE_INTEGER;
162 atrm_arg_elements[0].integer.value = offset;
164 atrm_arg_elements[1].type = ACPI_TYPE_INTEGER;
165 atrm_arg_elements[1].integer.value = len;
167 status = acpi_evaluate_object(atrm_handle, NULL, &atrm_arg, &buffer);
168 if (ACPI_FAILURE(status)) {
169 printk("failed to evaluate ATRM got %s\n", acpi_format_exception(status));
170 return -ENODEV;
173 obj = (union acpi_object *)buffer.pointer;
174 memcpy(bios+offset, obj->buffer.pointer, obj->buffer.length);
175 len = obj->buffer.length;
176 kfree(buffer.pointer);
177 return len;
180 static bool radeon_atrm_get_bios(struct radeon_device *rdev)
182 int ret;
183 int size = 256 * 1024;
184 int i;
185 struct pci_dev *pdev = NULL;
186 acpi_handle dhandle, atrm_handle;
187 acpi_status status;
188 bool found = false;
190 /* ATRM is for the discrete card only */
191 if (rdev->flags & RADEON_IS_IGP)
192 return false;
194 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
195 dhandle = ACPI_HANDLE(&pdev->dev);
196 if (!dhandle)
197 continue;
199 status = acpi_get_handle(dhandle, "ATRM", &atrm_handle);
200 if (!ACPI_FAILURE(status)) {
201 found = true;
202 break;
206 if (!found) {
207 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) {
208 dhandle = ACPI_HANDLE(&pdev->dev);
209 if (!dhandle)
210 continue;
212 status = acpi_get_handle(dhandle, "ATRM", &atrm_handle);
213 if (!ACPI_FAILURE(status)) {
214 found = true;
215 break;
220 if (!found)
221 return false;
223 rdev->bios = kmalloc(size, GFP_KERNEL);
224 if (!rdev->bios) {
225 DRM_ERROR("Unable to allocate bios\n");
226 return false;
229 for (i = 0; i < size / ATRM_BIOS_PAGE; i++) {
230 ret = radeon_atrm_call(atrm_handle,
231 rdev->bios,
232 (i * ATRM_BIOS_PAGE),
233 ATRM_BIOS_PAGE);
234 if (ret < ATRM_BIOS_PAGE)
235 break;
238 if (i == 0 || rdev->bios[0] != 0x55 || rdev->bios[1] != 0xaa) {
239 kfree(rdev->bios);
240 return false;
242 return true;
244 #else
245 static inline bool radeon_atrm_get_bios(struct radeon_device *rdev)
247 return false;
249 #endif
251 static bool ni_read_disabled_bios(struct radeon_device *rdev)
253 u32 bus_cntl;
254 u32 d1vga_control;
255 u32 d2vga_control;
256 u32 vga_render_control;
257 u32 rom_cntl;
258 bool r;
260 bus_cntl = RREG32(R600_BUS_CNTL);
261 d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
262 d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
263 vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
264 rom_cntl = RREG32(R600_ROM_CNTL);
266 /* enable the rom */
267 WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS));
268 if (!ASIC_IS_NODCE(rdev)) {
269 /* Disable VGA mode */
270 WREG32(AVIVO_D1VGA_CONTROL,
271 (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
272 AVIVO_DVGA_CONTROL_TIMING_SELECT)));
273 WREG32(AVIVO_D2VGA_CONTROL,
274 (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
275 AVIVO_DVGA_CONTROL_TIMING_SELECT)));
276 WREG32(AVIVO_VGA_RENDER_CONTROL,
277 (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK));
279 WREG32(R600_ROM_CNTL, rom_cntl | R600_SCK_OVERWRITE);
281 r = radeon_read_bios(rdev);
283 /* restore regs */
284 WREG32(R600_BUS_CNTL, bus_cntl);
285 if (!ASIC_IS_NODCE(rdev)) {
286 WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
287 WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
288 WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
290 WREG32(R600_ROM_CNTL, rom_cntl);
291 return r;
294 static bool r700_read_disabled_bios(struct radeon_device *rdev)
296 uint32_t viph_control;
297 uint32_t bus_cntl;
298 uint32_t d1vga_control;
299 uint32_t d2vga_control;
300 uint32_t vga_render_control;
301 uint32_t rom_cntl;
302 uint32_t cg_spll_func_cntl = 0;
303 uint32_t cg_spll_status;
304 bool r;
306 viph_control = RREG32(RADEON_VIPH_CONTROL);
307 bus_cntl = RREG32(R600_BUS_CNTL);
308 d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
309 d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
310 vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
311 rom_cntl = RREG32(R600_ROM_CNTL);
313 /* disable VIP */
314 WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
315 /* enable the rom */
316 WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS));
317 /* Disable VGA mode */
318 WREG32(AVIVO_D1VGA_CONTROL,
319 (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
320 AVIVO_DVGA_CONTROL_TIMING_SELECT)));
321 WREG32(AVIVO_D2VGA_CONTROL,
322 (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
323 AVIVO_DVGA_CONTROL_TIMING_SELECT)));
324 WREG32(AVIVO_VGA_RENDER_CONTROL,
325 (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK));
327 if (rdev->family == CHIP_RV730) {
328 cg_spll_func_cntl = RREG32(R600_CG_SPLL_FUNC_CNTL);
330 /* enable bypass mode */
331 WREG32(R600_CG_SPLL_FUNC_CNTL, (cg_spll_func_cntl |
332 R600_SPLL_BYPASS_EN));
334 /* wait for SPLL_CHG_STATUS to change to 1 */
335 cg_spll_status = 0;
336 while (!(cg_spll_status & R600_SPLL_CHG_STATUS))
337 cg_spll_status = RREG32(R600_CG_SPLL_STATUS);
339 WREG32(R600_ROM_CNTL, (rom_cntl & ~R600_SCK_OVERWRITE));
340 } else
341 WREG32(R600_ROM_CNTL, (rom_cntl | R600_SCK_OVERWRITE));
343 r = radeon_read_bios(rdev);
345 /* restore regs */
346 if (rdev->family == CHIP_RV730) {
347 WREG32(R600_CG_SPLL_FUNC_CNTL, cg_spll_func_cntl);
349 /* wait for SPLL_CHG_STATUS to change to 1 */
350 cg_spll_status = 0;
351 while (!(cg_spll_status & R600_SPLL_CHG_STATUS))
352 cg_spll_status = RREG32(R600_CG_SPLL_STATUS);
354 WREG32(RADEON_VIPH_CONTROL, viph_control);
355 WREG32(R600_BUS_CNTL, bus_cntl);
356 WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
357 WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
358 WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
359 WREG32(R600_ROM_CNTL, rom_cntl);
360 return r;
363 static bool r600_read_disabled_bios(struct radeon_device *rdev)
365 uint32_t viph_control;
366 uint32_t bus_cntl;
367 uint32_t d1vga_control;
368 uint32_t d2vga_control;
369 uint32_t vga_render_control;
370 uint32_t rom_cntl;
371 uint32_t general_pwrmgt;
372 uint32_t low_vid_lower_gpio_cntl;
373 uint32_t medium_vid_lower_gpio_cntl;
374 uint32_t high_vid_lower_gpio_cntl;
375 uint32_t ctxsw_vid_lower_gpio_cntl;
376 uint32_t lower_gpio_enable;
377 bool r;
379 viph_control = RREG32(RADEON_VIPH_CONTROL);
380 bus_cntl = RREG32(R600_BUS_CNTL);
381 d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
382 d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
383 vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
384 rom_cntl = RREG32(R600_ROM_CNTL);
385 general_pwrmgt = RREG32(R600_GENERAL_PWRMGT);
386 low_vid_lower_gpio_cntl = RREG32(R600_LOW_VID_LOWER_GPIO_CNTL);
387 medium_vid_lower_gpio_cntl = RREG32(R600_MEDIUM_VID_LOWER_GPIO_CNTL);
388 high_vid_lower_gpio_cntl = RREG32(R600_HIGH_VID_LOWER_GPIO_CNTL);
389 ctxsw_vid_lower_gpio_cntl = RREG32(R600_CTXSW_VID_LOWER_GPIO_CNTL);
390 lower_gpio_enable = RREG32(R600_LOWER_GPIO_ENABLE);
392 /* disable VIP */
393 WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
394 /* enable the rom */
395 WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS));
396 /* Disable VGA mode */
397 WREG32(AVIVO_D1VGA_CONTROL,
398 (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
399 AVIVO_DVGA_CONTROL_TIMING_SELECT)));
400 WREG32(AVIVO_D2VGA_CONTROL,
401 (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
402 AVIVO_DVGA_CONTROL_TIMING_SELECT)));
403 WREG32(AVIVO_VGA_RENDER_CONTROL,
404 (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK));
406 WREG32(R600_ROM_CNTL,
407 ((rom_cntl & ~R600_SCK_PRESCALE_CRYSTAL_CLK_MASK) |
408 (1 << R600_SCK_PRESCALE_CRYSTAL_CLK_SHIFT) |
409 R600_SCK_OVERWRITE));
411 WREG32(R600_GENERAL_PWRMGT, (general_pwrmgt & ~R600_OPEN_DRAIN_PADS));
412 WREG32(R600_LOW_VID_LOWER_GPIO_CNTL,
413 (low_vid_lower_gpio_cntl & ~0x400));
414 WREG32(R600_MEDIUM_VID_LOWER_GPIO_CNTL,
415 (medium_vid_lower_gpio_cntl & ~0x400));
416 WREG32(R600_HIGH_VID_LOWER_GPIO_CNTL,
417 (high_vid_lower_gpio_cntl & ~0x400));
418 WREG32(R600_CTXSW_VID_LOWER_GPIO_CNTL,
419 (ctxsw_vid_lower_gpio_cntl & ~0x400));
420 WREG32(R600_LOWER_GPIO_ENABLE, (lower_gpio_enable | 0x400));
422 r = radeon_read_bios(rdev);
424 /* restore regs */
425 WREG32(RADEON_VIPH_CONTROL, viph_control);
426 WREG32(R600_BUS_CNTL, bus_cntl);
427 WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
428 WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
429 WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
430 WREG32(R600_ROM_CNTL, rom_cntl);
431 WREG32(R600_GENERAL_PWRMGT, general_pwrmgt);
432 WREG32(R600_LOW_VID_LOWER_GPIO_CNTL, low_vid_lower_gpio_cntl);
433 WREG32(R600_MEDIUM_VID_LOWER_GPIO_CNTL, medium_vid_lower_gpio_cntl);
434 WREG32(R600_HIGH_VID_LOWER_GPIO_CNTL, high_vid_lower_gpio_cntl);
435 WREG32(R600_CTXSW_VID_LOWER_GPIO_CNTL, ctxsw_vid_lower_gpio_cntl);
436 WREG32(R600_LOWER_GPIO_ENABLE, lower_gpio_enable);
437 return r;
440 static bool avivo_read_disabled_bios(struct radeon_device *rdev)
442 uint32_t seprom_cntl1;
443 uint32_t viph_control;
444 uint32_t bus_cntl;
445 uint32_t d1vga_control;
446 uint32_t d2vga_control;
447 uint32_t vga_render_control;
448 uint32_t gpiopad_a;
449 uint32_t gpiopad_en;
450 uint32_t gpiopad_mask;
451 bool r;
453 seprom_cntl1 = RREG32(RADEON_SEPROM_CNTL1);
454 viph_control = RREG32(RADEON_VIPH_CONTROL);
455 bus_cntl = RREG32(RV370_BUS_CNTL);
456 d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
457 d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
458 vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
459 gpiopad_a = RREG32(RADEON_GPIOPAD_A);
460 gpiopad_en = RREG32(RADEON_GPIOPAD_EN);
461 gpiopad_mask = RREG32(RADEON_GPIOPAD_MASK);
463 WREG32(RADEON_SEPROM_CNTL1,
464 ((seprom_cntl1 & ~RADEON_SCK_PRESCALE_MASK) |
465 (0xc << RADEON_SCK_PRESCALE_SHIFT)));
466 WREG32(RADEON_GPIOPAD_A, 0);
467 WREG32(RADEON_GPIOPAD_EN, 0);
468 WREG32(RADEON_GPIOPAD_MASK, 0);
470 /* disable VIP */
471 WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
473 /* enable the rom */
474 WREG32(RV370_BUS_CNTL, (bus_cntl & ~RV370_BUS_BIOS_DIS_ROM));
476 /* Disable VGA mode */
477 WREG32(AVIVO_D1VGA_CONTROL,
478 (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
479 AVIVO_DVGA_CONTROL_TIMING_SELECT)));
480 WREG32(AVIVO_D2VGA_CONTROL,
481 (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
482 AVIVO_DVGA_CONTROL_TIMING_SELECT)));
483 WREG32(AVIVO_VGA_RENDER_CONTROL,
484 (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK));
486 r = radeon_read_bios(rdev);
488 /* restore regs */
489 WREG32(RADEON_SEPROM_CNTL1, seprom_cntl1);
490 WREG32(RADEON_VIPH_CONTROL, viph_control);
491 WREG32(RV370_BUS_CNTL, bus_cntl);
492 WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
493 WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
494 WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
495 WREG32(RADEON_GPIOPAD_A, gpiopad_a);
496 WREG32(RADEON_GPIOPAD_EN, gpiopad_en);
497 WREG32(RADEON_GPIOPAD_MASK, gpiopad_mask);
498 return r;
501 static bool legacy_read_disabled_bios(struct radeon_device *rdev)
503 uint32_t seprom_cntl1;
504 uint32_t viph_control;
505 uint32_t bus_cntl;
506 uint32_t crtc_gen_cntl;
507 uint32_t crtc2_gen_cntl;
508 uint32_t crtc_ext_cntl;
509 uint32_t fp2_gen_cntl;
510 bool r;
512 seprom_cntl1 = RREG32(RADEON_SEPROM_CNTL1);
513 viph_control = RREG32(RADEON_VIPH_CONTROL);
514 if (rdev->flags & RADEON_IS_PCIE)
515 bus_cntl = RREG32(RV370_BUS_CNTL);
516 else
517 bus_cntl = RREG32(RADEON_BUS_CNTL);
518 crtc_gen_cntl = RREG32(RADEON_CRTC_GEN_CNTL);
519 crtc2_gen_cntl = 0;
520 crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
521 fp2_gen_cntl = 0;
523 if (rdev->ddev->pdev->device == PCI_DEVICE_ID_ATI_RADEON_QY) {
524 fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
527 if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
528 crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
531 WREG32(RADEON_SEPROM_CNTL1,
532 ((seprom_cntl1 & ~RADEON_SCK_PRESCALE_MASK) |
533 (0xc << RADEON_SCK_PRESCALE_SHIFT)));
535 /* disable VIP */
536 WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
538 /* enable the rom */
539 if (rdev->flags & RADEON_IS_PCIE)
540 WREG32(RV370_BUS_CNTL, (bus_cntl & ~RV370_BUS_BIOS_DIS_ROM));
541 else
542 WREG32(RADEON_BUS_CNTL, (bus_cntl & ~RADEON_BUS_BIOS_DIS_ROM));
544 /* Turn off mem requests and CRTC for both controllers */
545 WREG32(RADEON_CRTC_GEN_CNTL,
546 ((crtc_gen_cntl & ~RADEON_CRTC_EN) |
547 (RADEON_CRTC_DISP_REQ_EN_B |
548 RADEON_CRTC_EXT_DISP_EN)));
549 if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
550 WREG32(RADEON_CRTC2_GEN_CNTL,
551 ((crtc2_gen_cntl & ~RADEON_CRTC2_EN) |
552 RADEON_CRTC2_DISP_REQ_EN_B));
554 /* Turn off CRTC */
555 WREG32(RADEON_CRTC_EXT_CNTL,
556 ((crtc_ext_cntl & ~RADEON_CRTC_CRT_ON) |
557 (RADEON_CRTC_SYNC_TRISTAT |
558 RADEON_CRTC_DISPLAY_DIS)));
560 if (rdev->ddev->pdev->device == PCI_DEVICE_ID_ATI_RADEON_QY) {
561 WREG32(RADEON_FP2_GEN_CNTL, (fp2_gen_cntl & ~RADEON_FP2_ON));
564 r = radeon_read_bios(rdev);
566 /* restore regs */
567 WREG32(RADEON_SEPROM_CNTL1, seprom_cntl1);
568 WREG32(RADEON_VIPH_CONTROL, viph_control);
569 if (rdev->flags & RADEON_IS_PCIE)
570 WREG32(RV370_BUS_CNTL, bus_cntl);
571 else
572 WREG32(RADEON_BUS_CNTL, bus_cntl);
573 WREG32(RADEON_CRTC_GEN_CNTL, crtc_gen_cntl);
574 if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
575 WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
577 WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
578 if (rdev->ddev->pdev->device == PCI_DEVICE_ID_ATI_RADEON_QY) {
579 WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
581 return r;
584 static bool radeon_read_disabled_bios(struct radeon_device *rdev)
586 if (rdev->flags & RADEON_IS_IGP)
587 return igp_read_bios_from_vram(rdev);
588 else if (rdev->family >= CHIP_BARTS)
589 return ni_read_disabled_bios(rdev);
590 else if (rdev->family >= CHIP_RV770)
591 return r700_read_disabled_bios(rdev);
592 else if (rdev->family >= CHIP_R600)
593 return r600_read_disabled_bios(rdev);
594 else if (rdev->family >= CHIP_RS600)
595 return avivo_read_disabled_bios(rdev);
596 else
597 return legacy_read_disabled_bios(rdev);
600 #ifdef CONFIG_ACPI
601 static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
603 struct acpi_table_header *hdr;
604 acpi_size tbl_size;
605 UEFI_ACPI_VFCT *vfct;
606 unsigned offset;
608 if (!ACPI_SUCCESS(acpi_get_table("VFCT", 1, &hdr)))
609 return false;
610 tbl_size = hdr->length;
611 if (tbl_size < sizeof(UEFI_ACPI_VFCT)) {
612 DRM_ERROR("ACPI VFCT table present but broken (too short #1)\n");
613 return false;
616 vfct = (UEFI_ACPI_VFCT *)hdr;
617 offset = vfct->VBIOSImageOffset;
619 while (offset < tbl_size) {
620 GOP_VBIOS_CONTENT *vbios = (GOP_VBIOS_CONTENT *)((char *)hdr + offset);
621 VFCT_IMAGE_HEADER *vhdr = &vbios->VbiosHeader;
623 offset += sizeof(VFCT_IMAGE_HEADER);
624 if (offset > tbl_size) {
625 DRM_ERROR("ACPI VFCT image header truncated\n");
626 return false;
629 offset += vhdr->ImageLength;
630 if (offset > tbl_size) {
631 DRM_ERROR("ACPI VFCT image truncated\n");
632 return false;
635 if (vhdr->ImageLength &&
636 vhdr->PCIBus == rdev->pdev->bus->number &&
637 vhdr->PCIDevice == PCI_SLOT(rdev->pdev->devfn) &&
638 vhdr->PCIFunction == PCI_FUNC(rdev->pdev->devfn) &&
639 vhdr->VendorID == rdev->pdev->vendor &&
640 vhdr->DeviceID == rdev->pdev->device) {
641 rdev->bios = kmemdup(&vbios->VbiosContent,
642 vhdr->ImageLength,
643 GFP_KERNEL);
645 if (!rdev->bios)
646 return false;
647 return true;
651 DRM_ERROR("ACPI VFCT table present but broken (too short #2)\n");
652 return false;
654 #else
655 static inline bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
657 return false;
659 #endif
661 bool radeon_get_bios(struct radeon_device *rdev)
663 bool r;
664 uint16_t tmp;
666 r = radeon_atrm_get_bios(rdev);
667 if (!r)
668 r = radeon_acpi_vfct_bios(rdev);
669 if (!r)
670 r = igp_read_bios_from_vram(rdev);
671 if (!r)
672 r = radeon_read_bios(rdev);
673 if (!r)
674 r = radeon_read_disabled_bios(rdev);
675 if (!r)
676 r = radeon_read_platform_bios(rdev);
677 if (!r || rdev->bios == NULL) {
678 DRM_ERROR("Unable to locate a BIOS ROM\n");
679 rdev->bios = NULL;
680 return false;
682 if (rdev->bios[0] != 0x55 || rdev->bios[1] != 0xaa) {
683 printk("BIOS signature incorrect %x %x\n", rdev->bios[0], rdev->bios[1]);
684 goto free_bios;
687 tmp = RBIOS16(0x18);
688 if (RBIOS8(tmp + 0x14) != 0x0) {
689 DRM_INFO("Not an x86 BIOS ROM, not using.\n");
690 goto free_bios;
693 rdev->bios_header_start = RBIOS16(0x48);
694 if (!rdev->bios_header_start) {
695 goto free_bios;
697 tmp = rdev->bios_header_start + 4;
698 if (!memcmp(rdev->bios + tmp, "ATOM", 4) ||
699 !memcmp(rdev->bios + tmp, "MOTA", 4)) {
700 rdev->is_atom_bios = true;
701 } else {
702 rdev->is_atom_bios = false;
705 DRM_DEBUG("%sBIOS detected\n", rdev->is_atom_bios ? "ATOM" : "COM");
706 return true;
707 free_bios:
708 kfree(rdev->bios);
709 rdev->bios = NULL;
710 return false;