1 1.15 tnn /* $NetBSD: radeon_bios.c,v 1.15 2025/05/09 20:09:13 tnn Exp $ */ 2 1.5 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright 2008 Advanced Micro Devices, Inc. 5 1.1 riastrad * Copyright 2008 Red Hat Inc. 6 1.1 riastrad * Copyright 2009 Jerome Glisse. 7 1.1 riastrad * 8 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 9 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 10 1.1 riastrad * to deal in the Software without restriction, including without limitation 11 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 13 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 14 1.1 riastrad * 15 1.1 riastrad * The above copyright notice and this permission notice shall be included in 16 1.1 riastrad * all copies or substantial portions of the Software. 17 1.1 riastrad * 18 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 1.1 riastrad * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 22 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 25 1.1 riastrad * 26 1.1 riastrad * Authors: Dave Airlie 27 1.1 riastrad * Alex Deucher 28 1.1 riastrad * Jerome Glisse 29 1.1 riastrad */ 30 1.8 riastrad 31 1.5 riastrad #include <sys/cdefs.h> 32 1.15 tnn __KERNEL_RCSID(0, "$NetBSD: radeon_bios.c,v 1.15 2025/05/09 20:09:13 tnn Exp $"); 33 1.8 riastrad 34 1.8 riastrad #include <linux/acpi.h> 35 1.8 riastrad #include <linux/pci.h> 36 1.8 riastrad #include <linux/slab.h> 37 1.8 riastrad 38 1.8 riastrad #include <drm/drm_device.h> 39 1.5 riastrad 40 1.8 riastrad #include "atom.h" 41 1.8 riastrad #include "radeon.h" 42 1.1 riastrad #include "radeon_reg.h" 43 1.1 riastrad 44 1.14 riastrad #if defined(__NetBSD__) && defined(CONFIG_ACPI) 45 1.11 riastrad #include <dev/acpi/acpireg.h> 46 1.11 riastrad #define _COMPONENT ACPI_DISPLAY_COMPONENT 47 1.11 riastrad ACPI_MODULE_NAME("radeon_acpi") 48 1.9 riastrad #include <linux/nbsd-namespace-acpi.h> 49 1.11 riastrad #endif 50 1.9 riastrad 51 1.1 riastrad /* 52 1.1 riastrad * BIOS. 53 1.1 riastrad */ 54 1.1 riastrad 55 1.1 riastrad /* If you boot an IGP board with a discrete card as the primary, 56 1.1 riastrad * the IGP rom is not accessible via the rom bar as the IGP rom is 57 1.1 riastrad * part of the system bios. On boot, the system bios puts a 58 1.1 riastrad * copy of the igp rom at the start of vram if a discrete card is 59 1.1 riastrad * present. 60 1.1 riastrad */ 61 1.1 riastrad static bool igp_read_bios_from_vram(struct radeon_device *rdev) 62 1.1 riastrad { 63 1.2 riastrad #ifdef __NetBSD__ 64 1.2 riastrad bus_space_tag_t bst; 65 1.2 riastrad bus_space_handle_t bsh; 66 1.2 riastrad bus_size_t size; 67 1.2 riastrad #else 68 1.1 riastrad uint8_t __iomem *bios; 69 1.1 riastrad resource_size_t vram_base; 70 1.1 riastrad resource_size_t size = 256 * 1024; /* ??? */ 71 1.2 riastrad #endif 72 1.1 riastrad 73 1.1 riastrad if (!(rdev->flags & RADEON_IS_IGP)) 74 1.1 riastrad if (!radeon_card_posted(rdev)) 75 1.1 riastrad return false; 76 1.1 riastrad 77 1.1 riastrad rdev->bios = NULL; 78 1.2 riastrad #ifdef __NetBSD__ 79 1.2 riastrad if (pci_mapreg_map(&rdev->pdev->pd_pa, PCI_BAR(0), 80 1.2 riastrad /* XXX Dunno what type to expect here; fill me in... */ 81 1.2 riastrad pci_mapreg_type(rdev->pdev->pd_pa.pa_pc, 82 1.2 riastrad rdev->pdev->pd_pa.pa_tag, PCI_BAR(0)), 83 1.2 riastrad 0, &bst, &bsh, NULL, &size)) 84 1.2 riastrad return false; 85 1.2 riastrad if ((size == 0) || 86 1.2 riastrad (size < 256 * 1024) || 87 1.2 riastrad (bus_space_read_1(bst, bsh, 0) != 0x55) || 88 1.2 riastrad (bus_space_read_1(bst, bsh, 1) != 0xaa) || 89 1.3 jakllsch ((rdev->bios = kmalloc(size, GFP_KERNEL)) == NULL)) { 90 1.2 riastrad bus_space_unmap(bst, bsh, size); 91 1.2 riastrad return false; 92 1.2 riastrad } 93 1.2 riastrad bus_space_read_region_1(bst, bsh, 0, rdev->bios, size); 94 1.2 riastrad bus_space_unmap(bst, bsh, size); 95 1.2 riastrad #else 96 1.1 riastrad vram_base = pci_resource_start(rdev->pdev, 0); 97 1.1 riastrad bios = ioremap(vram_base, size); 98 1.1 riastrad if (!bios) { 99 1.1 riastrad return false; 100 1.1 riastrad } 101 1.1 riastrad 102 1.1 riastrad if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) { 103 1.1 riastrad iounmap(bios); 104 1.1 riastrad return false; 105 1.1 riastrad } 106 1.1 riastrad rdev->bios = kmalloc(size, GFP_KERNEL); 107 1.1 riastrad if (rdev->bios == NULL) { 108 1.1 riastrad iounmap(bios); 109 1.1 riastrad return false; 110 1.1 riastrad } 111 1.1 riastrad memcpy_fromio(rdev->bios, bios, size); 112 1.1 riastrad iounmap(bios); 113 1.2 riastrad #endif 114 1.1 riastrad return true; 115 1.1 riastrad } 116 1.1 riastrad 117 1.2 riastrad #ifdef __NetBSD__ 118 1.2 riastrad #define __iomem __pci_rom_iomem 119 1.2 riastrad #endif 120 1.2 riastrad 121 1.1 riastrad static bool radeon_read_bios(struct radeon_device *rdev) 122 1.1 riastrad { 123 1.5 riastrad uint8_t __iomem *bios, val1, val2; 124 1.1 riastrad size_t size; 125 1.1 riastrad 126 1.1 riastrad rdev->bios = NULL; 127 1.1 riastrad /* XXX: some cards may return 0 for rom size? ddx has a workaround */ 128 1.1 riastrad bios = pci_map_rom(rdev->pdev, &size); 129 1.1 riastrad if (!bios) { 130 1.1 riastrad return false; 131 1.1 riastrad } 132 1.1 riastrad 133 1.4 riastrad #ifdef __NetBSD__ 134 1.6 riastrad const bus_space_tag_t bst = rdev->pdev->pd_rom_bst; 135 1.6 riastrad const bus_space_handle_t bsh = rdev->pdev->pd_rom_found_bsh; 136 1.6 riastrad 137 1.5 riastrad val1 = bus_space_read_1(bst, bsh, 0); 138 1.5 riastrad val2 = bus_space_read_1(bst, bsh, 1); 139 1.5 riastrad #else 140 1.5 riastrad val1 = readb(&bios[0]); 141 1.5 riastrad val2 = readb(&bios[1]); 142 1.5 riastrad #endif 143 1.4 riastrad 144 1.5 riastrad if (size == 0 || val1 != 0x55 || val2 != 0xaa) { 145 1.4 riastrad pci_unmap_rom(rdev->pdev, bios); 146 1.4 riastrad return false; 147 1.4 riastrad } 148 1.5 riastrad rdev->bios = kzalloc(size, GFP_KERNEL); 149 1.4 riastrad if (rdev->bios == NULL) { 150 1.4 riastrad pci_unmap_rom(rdev->pdev, bios); 151 1.4 riastrad return false; 152 1.4 riastrad } 153 1.5 riastrad #ifdef __NetBSD__ 154 1.4 riastrad bus_space_read_region_1(bst, bsh, 0, rdev->bios, size); 155 1.4 riastrad #else 156 1.5 riastrad memcpy_fromio(rdev->bios, bios, size); 157 1.4 riastrad #endif 158 1.1 riastrad pci_unmap_rom(rdev->pdev, bios); 159 1.1 riastrad return true; 160 1.1 riastrad } 161 1.1 riastrad 162 1.2 riastrad #ifdef __NetBSD__ 163 1.2 riastrad #undef __iomem 164 1.2 riastrad #endif 165 1.2 riastrad 166 1.1 riastrad static bool radeon_read_platform_bios(struct radeon_device *rdev) 167 1.1 riastrad { 168 1.2 riastrad #ifdef __NetBSD__ /* XXX radeon platform bios */ 169 1.2 riastrad return false; 170 1.2 riastrad #else 171 1.1 riastrad uint8_t __iomem *bios; 172 1.1 riastrad size_t size; 173 1.1 riastrad 174 1.1 riastrad rdev->bios = NULL; 175 1.1 riastrad 176 1.1 riastrad bios = pci_platform_rom(rdev->pdev, &size); 177 1.1 riastrad if (!bios) { 178 1.1 riastrad return false; 179 1.1 riastrad } 180 1.1 riastrad 181 1.1 riastrad if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) { 182 1.1 riastrad return false; 183 1.1 riastrad } 184 1.1 riastrad rdev->bios = kmemdup(bios, size, GFP_KERNEL); 185 1.1 riastrad if (rdev->bios == NULL) { 186 1.1 riastrad return false; 187 1.1 riastrad } 188 1.1 riastrad 189 1.1 riastrad return true; 190 1.2 riastrad #endif 191 1.1 riastrad } 192 1.1 riastrad 193 1.1 riastrad #ifdef CONFIG_ACPI 194 1.1 riastrad /* ATRM is used to get the BIOS on the discrete cards in 195 1.1 riastrad * dual-gpu systems. 196 1.1 riastrad */ 197 1.1 riastrad /* retrieve the ROM in 4k blocks */ 198 1.1 riastrad #define ATRM_BIOS_PAGE 4096 199 1.1 riastrad /** 200 1.1 riastrad * radeon_atrm_call - fetch a chunk of the vbios 201 1.1 riastrad * 202 1.1 riastrad * @atrm_handle: acpi ATRM handle 203 1.1 riastrad * @bios: vbios image pointer 204 1.1 riastrad * @offset: offset of vbios image data to fetch 205 1.1 riastrad * @len: length of vbios image data to fetch 206 1.1 riastrad * 207 1.1 riastrad * Executes ATRM to fetch a chunk of the discrete 208 1.1 riastrad * vbios image on PX systems (all asics). 209 1.1 riastrad * Returns the length of the buffer fetched. 210 1.1 riastrad */ 211 1.1 riastrad static int radeon_atrm_call(acpi_handle atrm_handle, uint8_t *bios, 212 1.1 riastrad int offset, int len) 213 1.1 riastrad { 214 1.1 riastrad acpi_status status; 215 1.1 riastrad union acpi_object atrm_arg_elements[2], *obj; 216 1.1 riastrad struct acpi_object_list atrm_arg; 217 1.1 riastrad struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL}; 218 1.1 riastrad 219 1.1 riastrad atrm_arg.count = 2; 220 1.1 riastrad atrm_arg.pointer = &atrm_arg_elements[0]; 221 1.1 riastrad 222 1.1 riastrad atrm_arg_elements[0].type = ACPI_TYPE_INTEGER; 223 1.1 riastrad atrm_arg_elements[0].integer.value = offset; 224 1.1 riastrad 225 1.1 riastrad atrm_arg_elements[1].type = ACPI_TYPE_INTEGER; 226 1.1 riastrad atrm_arg_elements[1].integer.value = len; 227 1.1 riastrad 228 1.1 riastrad status = acpi_evaluate_object(atrm_handle, NULL, &atrm_arg, &buffer); 229 1.1 riastrad if (ACPI_FAILURE(status)) { 230 1.1 riastrad printk("failed to evaluate ATRM got %s\n", acpi_format_exception(status)); 231 1.1 riastrad return -ENODEV; 232 1.1 riastrad } 233 1.1 riastrad 234 1.1 riastrad obj = (union acpi_object *)buffer.pointer; 235 1.1 riastrad memcpy(bios+offset, obj->buffer.pointer, obj->buffer.length); 236 1.1 riastrad len = obj->buffer.length; 237 1.10 riastrad ACPI_FREE(buffer.pointer); 238 1.1 riastrad return len; 239 1.1 riastrad } 240 1.1 riastrad 241 1.1 riastrad static bool radeon_atrm_get_bios(struct radeon_device *rdev) 242 1.1 riastrad { 243 1.1 riastrad int ret; 244 1.1 riastrad int size = 256 * 1024; 245 1.1 riastrad int i; 246 1.1 riastrad struct pci_dev *pdev = NULL; 247 1.1 riastrad acpi_handle dhandle, atrm_handle; 248 1.1 riastrad acpi_status status; 249 1.1 riastrad bool found = false; 250 1.1 riastrad 251 1.1 riastrad /* ATRM is for the discrete card only */ 252 1.1 riastrad if (rdev->flags & RADEON_IS_IGP) 253 1.1 riastrad return false; 254 1.1 riastrad 255 1.15 tnn while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) { 256 1.9 riastrad #ifdef __NetBSD__ 257 1.9 riastrad dhandle = (pdev->pd_ad ? pdev->pd_ad->ad_handle : NULL); 258 1.9 riastrad #else 259 1.1 riastrad dhandle = ACPI_HANDLE(&pdev->dev); 260 1.9 riastrad #endif 261 1.1 riastrad if (!dhandle) 262 1.1 riastrad continue; 263 1.1 riastrad 264 1.1 riastrad status = acpi_get_handle(dhandle, "ATRM", &atrm_handle); 265 1.1 riastrad if (!ACPI_FAILURE(status)) { 266 1.1 riastrad found = true; 267 1.1 riastrad break; 268 1.1 riastrad } 269 1.1 riastrad } 270 1.1 riastrad 271 1.1 riastrad if (!found) { 272 1.15 tnn while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) { 273 1.9 riastrad #ifdef __NetBSD__ 274 1.9 riastrad dhandle = (pdev->pd_ad ? pdev->pd_ad->ad_handle 275 1.9 riastrad : NULL); 276 1.9 riastrad #else 277 1.1 riastrad dhandle = ACPI_HANDLE(&pdev->dev); 278 1.9 riastrad #endif 279 1.1 riastrad if (!dhandle) 280 1.1 riastrad continue; 281 1.1 riastrad 282 1.1 riastrad status = acpi_get_handle(dhandle, "ATRM", &atrm_handle); 283 1.1 riastrad if (!ACPI_FAILURE(status)) { 284 1.1 riastrad found = true; 285 1.1 riastrad break; 286 1.1 riastrad } 287 1.1 riastrad } 288 1.1 riastrad } 289 1.1 riastrad 290 1.1 riastrad if (!found) 291 1.1 riastrad return false; 292 1.1 riastrad 293 1.1 riastrad rdev->bios = kmalloc(size, GFP_KERNEL); 294 1.1 riastrad if (!rdev->bios) { 295 1.1 riastrad DRM_ERROR("Unable to allocate bios\n"); 296 1.1 riastrad return false; 297 1.1 riastrad } 298 1.1 riastrad 299 1.1 riastrad for (i = 0; i < size / ATRM_BIOS_PAGE; i++) { 300 1.1 riastrad ret = radeon_atrm_call(atrm_handle, 301 1.1 riastrad rdev->bios, 302 1.1 riastrad (i * ATRM_BIOS_PAGE), 303 1.1 riastrad ATRM_BIOS_PAGE); 304 1.1 riastrad if (ret < ATRM_BIOS_PAGE) 305 1.1 riastrad break; 306 1.1 riastrad } 307 1.1 riastrad 308 1.1 riastrad if (i == 0 || rdev->bios[0] != 0x55 || rdev->bios[1] != 0xaa) { 309 1.1 riastrad kfree(rdev->bios); 310 1.1 riastrad return false; 311 1.1 riastrad } 312 1.1 riastrad return true; 313 1.1 riastrad } 314 1.1 riastrad #else 315 1.1 riastrad static inline bool radeon_atrm_get_bios(struct radeon_device *rdev) 316 1.1 riastrad { 317 1.1 riastrad return false; 318 1.1 riastrad } 319 1.1 riastrad #endif 320 1.1 riastrad 321 1.1 riastrad static bool ni_read_disabled_bios(struct radeon_device *rdev) 322 1.1 riastrad { 323 1.1 riastrad u32 bus_cntl; 324 1.1 riastrad u32 d1vga_control; 325 1.1 riastrad u32 d2vga_control; 326 1.1 riastrad u32 vga_render_control; 327 1.1 riastrad u32 rom_cntl; 328 1.1 riastrad bool r; 329 1.1 riastrad 330 1.1 riastrad bus_cntl = RREG32(R600_BUS_CNTL); 331 1.1 riastrad d1vga_control = RREG32(AVIVO_D1VGA_CONTROL); 332 1.1 riastrad d2vga_control = RREG32(AVIVO_D2VGA_CONTROL); 333 1.1 riastrad vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL); 334 1.1 riastrad rom_cntl = RREG32(R600_ROM_CNTL); 335 1.1 riastrad 336 1.1 riastrad /* enable the rom */ 337 1.1 riastrad WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS)); 338 1.1 riastrad if (!ASIC_IS_NODCE(rdev)) { 339 1.1 riastrad /* Disable VGA mode */ 340 1.1 riastrad WREG32(AVIVO_D1VGA_CONTROL, 341 1.1 riastrad (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE | 342 1.1 riastrad AVIVO_DVGA_CONTROL_TIMING_SELECT))); 343 1.1 riastrad WREG32(AVIVO_D2VGA_CONTROL, 344 1.1 riastrad (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE | 345 1.1 riastrad AVIVO_DVGA_CONTROL_TIMING_SELECT))); 346 1.1 riastrad WREG32(AVIVO_VGA_RENDER_CONTROL, 347 1.1 riastrad (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK)); 348 1.1 riastrad } 349 1.1 riastrad WREG32(R600_ROM_CNTL, rom_cntl | R600_SCK_OVERWRITE); 350 1.1 riastrad 351 1.1 riastrad r = radeon_read_bios(rdev); 352 1.1 riastrad 353 1.1 riastrad /* restore regs */ 354 1.1 riastrad WREG32(R600_BUS_CNTL, bus_cntl); 355 1.1 riastrad if (!ASIC_IS_NODCE(rdev)) { 356 1.1 riastrad WREG32(AVIVO_D1VGA_CONTROL, d1vga_control); 357 1.1 riastrad WREG32(AVIVO_D2VGA_CONTROL, d2vga_control); 358 1.1 riastrad WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control); 359 1.1 riastrad } 360 1.1 riastrad WREG32(R600_ROM_CNTL, rom_cntl); 361 1.1 riastrad return r; 362 1.1 riastrad } 363 1.1 riastrad 364 1.1 riastrad static bool r700_read_disabled_bios(struct radeon_device *rdev) 365 1.1 riastrad { 366 1.1 riastrad uint32_t viph_control; 367 1.1 riastrad uint32_t bus_cntl; 368 1.1 riastrad uint32_t d1vga_control; 369 1.1 riastrad uint32_t d2vga_control; 370 1.1 riastrad uint32_t vga_render_control; 371 1.1 riastrad uint32_t rom_cntl; 372 1.1 riastrad uint32_t cg_spll_func_cntl = 0; 373 1.1 riastrad uint32_t cg_spll_status; 374 1.1 riastrad bool r; 375 1.1 riastrad 376 1.1 riastrad viph_control = RREG32(RADEON_VIPH_CONTROL); 377 1.1 riastrad bus_cntl = RREG32(R600_BUS_CNTL); 378 1.1 riastrad d1vga_control = RREG32(AVIVO_D1VGA_CONTROL); 379 1.1 riastrad d2vga_control = RREG32(AVIVO_D2VGA_CONTROL); 380 1.1 riastrad vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL); 381 1.1 riastrad rom_cntl = RREG32(R600_ROM_CNTL); 382 1.1 riastrad 383 1.1 riastrad /* disable VIP */ 384 1.1 riastrad WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN)); 385 1.1 riastrad /* enable the rom */ 386 1.1 riastrad WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS)); 387 1.1 riastrad /* Disable VGA mode */ 388 1.1 riastrad WREG32(AVIVO_D1VGA_CONTROL, 389 1.1 riastrad (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE | 390 1.1 riastrad AVIVO_DVGA_CONTROL_TIMING_SELECT))); 391 1.1 riastrad WREG32(AVIVO_D2VGA_CONTROL, 392 1.1 riastrad (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE | 393 1.1 riastrad AVIVO_DVGA_CONTROL_TIMING_SELECT))); 394 1.1 riastrad WREG32(AVIVO_VGA_RENDER_CONTROL, 395 1.1 riastrad (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK)); 396 1.1 riastrad 397 1.1 riastrad if (rdev->family == CHIP_RV730) { 398 1.1 riastrad cg_spll_func_cntl = RREG32(R600_CG_SPLL_FUNC_CNTL); 399 1.1 riastrad 400 1.1 riastrad /* enable bypass mode */ 401 1.1 riastrad WREG32(R600_CG_SPLL_FUNC_CNTL, (cg_spll_func_cntl | 402 1.1 riastrad R600_SPLL_BYPASS_EN)); 403 1.1 riastrad 404 1.1 riastrad /* wait for SPLL_CHG_STATUS to change to 1 */ 405 1.1 riastrad cg_spll_status = 0; 406 1.1 riastrad while (!(cg_spll_status & R600_SPLL_CHG_STATUS)) 407 1.1 riastrad cg_spll_status = RREG32(R600_CG_SPLL_STATUS); 408 1.1 riastrad 409 1.1 riastrad WREG32(R600_ROM_CNTL, (rom_cntl & ~R600_SCK_OVERWRITE)); 410 1.1 riastrad } else 411 1.1 riastrad WREG32(R600_ROM_CNTL, (rom_cntl | R600_SCK_OVERWRITE)); 412 1.1 riastrad 413 1.1 riastrad r = radeon_read_bios(rdev); 414 1.1 riastrad 415 1.1 riastrad /* restore regs */ 416 1.1 riastrad if (rdev->family == CHIP_RV730) { 417 1.1 riastrad WREG32(R600_CG_SPLL_FUNC_CNTL, cg_spll_func_cntl); 418 1.1 riastrad 419 1.1 riastrad /* wait for SPLL_CHG_STATUS to change to 1 */ 420 1.1 riastrad cg_spll_status = 0; 421 1.1 riastrad while (!(cg_spll_status & R600_SPLL_CHG_STATUS)) 422 1.1 riastrad cg_spll_status = RREG32(R600_CG_SPLL_STATUS); 423 1.1 riastrad } 424 1.1 riastrad WREG32(RADEON_VIPH_CONTROL, viph_control); 425 1.1 riastrad WREG32(R600_BUS_CNTL, bus_cntl); 426 1.1 riastrad WREG32(AVIVO_D1VGA_CONTROL, d1vga_control); 427 1.1 riastrad WREG32(AVIVO_D2VGA_CONTROL, d2vga_control); 428 1.1 riastrad WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control); 429 1.1 riastrad WREG32(R600_ROM_CNTL, rom_cntl); 430 1.1 riastrad return r; 431 1.1 riastrad } 432 1.1 riastrad 433 1.1 riastrad static bool r600_read_disabled_bios(struct radeon_device *rdev) 434 1.1 riastrad { 435 1.1 riastrad uint32_t viph_control; 436 1.1 riastrad uint32_t bus_cntl; 437 1.1 riastrad uint32_t d1vga_control; 438 1.1 riastrad uint32_t d2vga_control; 439 1.1 riastrad uint32_t vga_render_control; 440 1.1 riastrad uint32_t rom_cntl; 441 1.1 riastrad uint32_t general_pwrmgt; 442 1.1 riastrad uint32_t low_vid_lower_gpio_cntl; 443 1.1 riastrad uint32_t medium_vid_lower_gpio_cntl; 444 1.1 riastrad uint32_t high_vid_lower_gpio_cntl; 445 1.1 riastrad uint32_t ctxsw_vid_lower_gpio_cntl; 446 1.1 riastrad uint32_t lower_gpio_enable; 447 1.1 riastrad bool r; 448 1.1 riastrad 449 1.1 riastrad viph_control = RREG32(RADEON_VIPH_CONTROL); 450 1.1 riastrad bus_cntl = RREG32(R600_BUS_CNTL); 451 1.1 riastrad d1vga_control = RREG32(AVIVO_D1VGA_CONTROL); 452 1.1 riastrad d2vga_control = RREG32(AVIVO_D2VGA_CONTROL); 453 1.1 riastrad vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL); 454 1.1 riastrad rom_cntl = RREG32(R600_ROM_CNTL); 455 1.1 riastrad general_pwrmgt = RREG32(R600_GENERAL_PWRMGT); 456 1.1 riastrad low_vid_lower_gpio_cntl = RREG32(R600_LOW_VID_LOWER_GPIO_CNTL); 457 1.1 riastrad medium_vid_lower_gpio_cntl = RREG32(R600_MEDIUM_VID_LOWER_GPIO_CNTL); 458 1.1 riastrad high_vid_lower_gpio_cntl = RREG32(R600_HIGH_VID_LOWER_GPIO_CNTL); 459 1.1 riastrad ctxsw_vid_lower_gpio_cntl = RREG32(R600_CTXSW_VID_LOWER_GPIO_CNTL); 460 1.1 riastrad lower_gpio_enable = RREG32(R600_LOWER_GPIO_ENABLE); 461 1.1 riastrad 462 1.1 riastrad /* disable VIP */ 463 1.1 riastrad WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN)); 464 1.1 riastrad /* enable the rom */ 465 1.1 riastrad WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS)); 466 1.1 riastrad /* Disable VGA mode */ 467 1.1 riastrad WREG32(AVIVO_D1VGA_CONTROL, 468 1.1 riastrad (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE | 469 1.1 riastrad AVIVO_DVGA_CONTROL_TIMING_SELECT))); 470 1.1 riastrad WREG32(AVIVO_D2VGA_CONTROL, 471 1.1 riastrad (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE | 472 1.1 riastrad AVIVO_DVGA_CONTROL_TIMING_SELECT))); 473 1.1 riastrad WREG32(AVIVO_VGA_RENDER_CONTROL, 474 1.1 riastrad (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK)); 475 1.1 riastrad 476 1.1 riastrad WREG32(R600_ROM_CNTL, 477 1.1 riastrad ((rom_cntl & ~R600_SCK_PRESCALE_CRYSTAL_CLK_MASK) | 478 1.1 riastrad (1 << R600_SCK_PRESCALE_CRYSTAL_CLK_SHIFT) | 479 1.1 riastrad R600_SCK_OVERWRITE)); 480 1.1 riastrad 481 1.1 riastrad WREG32(R600_GENERAL_PWRMGT, (general_pwrmgt & ~R600_OPEN_DRAIN_PADS)); 482 1.1 riastrad WREG32(R600_LOW_VID_LOWER_GPIO_CNTL, 483 1.1 riastrad (low_vid_lower_gpio_cntl & ~0x400)); 484 1.1 riastrad WREG32(R600_MEDIUM_VID_LOWER_GPIO_CNTL, 485 1.1 riastrad (medium_vid_lower_gpio_cntl & ~0x400)); 486 1.1 riastrad WREG32(R600_HIGH_VID_LOWER_GPIO_CNTL, 487 1.1 riastrad (high_vid_lower_gpio_cntl & ~0x400)); 488 1.1 riastrad WREG32(R600_CTXSW_VID_LOWER_GPIO_CNTL, 489 1.1 riastrad (ctxsw_vid_lower_gpio_cntl & ~0x400)); 490 1.1 riastrad WREG32(R600_LOWER_GPIO_ENABLE, (lower_gpio_enable | 0x400)); 491 1.1 riastrad 492 1.1 riastrad r = radeon_read_bios(rdev); 493 1.1 riastrad 494 1.1 riastrad /* restore regs */ 495 1.1 riastrad WREG32(RADEON_VIPH_CONTROL, viph_control); 496 1.1 riastrad WREG32(R600_BUS_CNTL, bus_cntl); 497 1.1 riastrad WREG32(AVIVO_D1VGA_CONTROL, d1vga_control); 498 1.1 riastrad WREG32(AVIVO_D2VGA_CONTROL, d2vga_control); 499 1.1 riastrad WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control); 500 1.1 riastrad WREG32(R600_ROM_CNTL, rom_cntl); 501 1.1 riastrad WREG32(R600_GENERAL_PWRMGT, general_pwrmgt); 502 1.1 riastrad WREG32(R600_LOW_VID_LOWER_GPIO_CNTL, low_vid_lower_gpio_cntl); 503 1.1 riastrad WREG32(R600_MEDIUM_VID_LOWER_GPIO_CNTL, medium_vid_lower_gpio_cntl); 504 1.1 riastrad WREG32(R600_HIGH_VID_LOWER_GPIO_CNTL, high_vid_lower_gpio_cntl); 505 1.1 riastrad WREG32(R600_CTXSW_VID_LOWER_GPIO_CNTL, ctxsw_vid_lower_gpio_cntl); 506 1.1 riastrad WREG32(R600_LOWER_GPIO_ENABLE, lower_gpio_enable); 507 1.1 riastrad return r; 508 1.1 riastrad } 509 1.1 riastrad 510 1.1 riastrad static bool avivo_read_disabled_bios(struct radeon_device *rdev) 511 1.1 riastrad { 512 1.1 riastrad uint32_t seprom_cntl1; 513 1.1 riastrad uint32_t viph_control; 514 1.1 riastrad uint32_t bus_cntl; 515 1.1 riastrad uint32_t d1vga_control; 516 1.1 riastrad uint32_t d2vga_control; 517 1.1 riastrad uint32_t vga_render_control; 518 1.1 riastrad uint32_t gpiopad_a; 519 1.1 riastrad uint32_t gpiopad_en; 520 1.1 riastrad uint32_t gpiopad_mask; 521 1.1 riastrad bool r; 522 1.1 riastrad 523 1.1 riastrad seprom_cntl1 = RREG32(RADEON_SEPROM_CNTL1); 524 1.1 riastrad viph_control = RREG32(RADEON_VIPH_CONTROL); 525 1.1 riastrad bus_cntl = RREG32(RV370_BUS_CNTL); 526 1.1 riastrad d1vga_control = RREG32(AVIVO_D1VGA_CONTROL); 527 1.1 riastrad d2vga_control = RREG32(AVIVO_D2VGA_CONTROL); 528 1.1 riastrad vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL); 529 1.1 riastrad gpiopad_a = RREG32(RADEON_GPIOPAD_A); 530 1.1 riastrad gpiopad_en = RREG32(RADEON_GPIOPAD_EN); 531 1.1 riastrad gpiopad_mask = RREG32(RADEON_GPIOPAD_MASK); 532 1.1 riastrad 533 1.1 riastrad WREG32(RADEON_SEPROM_CNTL1, 534 1.1 riastrad ((seprom_cntl1 & ~RADEON_SCK_PRESCALE_MASK) | 535 1.1 riastrad (0xc << RADEON_SCK_PRESCALE_SHIFT))); 536 1.1 riastrad WREG32(RADEON_GPIOPAD_A, 0); 537 1.1 riastrad WREG32(RADEON_GPIOPAD_EN, 0); 538 1.1 riastrad WREG32(RADEON_GPIOPAD_MASK, 0); 539 1.1 riastrad 540 1.1 riastrad /* disable VIP */ 541 1.1 riastrad WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN)); 542 1.1 riastrad 543 1.1 riastrad /* enable the rom */ 544 1.1 riastrad WREG32(RV370_BUS_CNTL, (bus_cntl & ~RV370_BUS_BIOS_DIS_ROM)); 545 1.1 riastrad 546 1.1 riastrad /* Disable VGA mode */ 547 1.1 riastrad WREG32(AVIVO_D1VGA_CONTROL, 548 1.1 riastrad (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE | 549 1.1 riastrad AVIVO_DVGA_CONTROL_TIMING_SELECT))); 550 1.1 riastrad WREG32(AVIVO_D2VGA_CONTROL, 551 1.1 riastrad (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE | 552 1.1 riastrad AVIVO_DVGA_CONTROL_TIMING_SELECT))); 553 1.1 riastrad WREG32(AVIVO_VGA_RENDER_CONTROL, 554 1.1 riastrad (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK)); 555 1.1 riastrad 556 1.1 riastrad r = radeon_read_bios(rdev); 557 1.1 riastrad 558 1.1 riastrad /* restore regs */ 559 1.1 riastrad WREG32(RADEON_SEPROM_CNTL1, seprom_cntl1); 560 1.1 riastrad WREG32(RADEON_VIPH_CONTROL, viph_control); 561 1.1 riastrad WREG32(RV370_BUS_CNTL, bus_cntl); 562 1.1 riastrad WREG32(AVIVO_D1VGA_CONTROL, d1vga_control); 563 1.1 riastrad WREG32(AVIVO_D2VGA_CONTROL, d2vga_control); 564 1.1 riastrad WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control); 565 1.1 riastrad WREG32(RADEON_GPIOPAD_A, gpiopad_a); 566 1.1 riastrad WREG32(RADEON_GPIOPAD_EN, gpiopad_en); 567 1.1 riastrad WREG32(RADEON_GPIOPAD_MASK, gpiopad_mask); 568 1.1 riastrad return r; 569 1.1 riastrad } 570 1.1 riastrad 571 1.1 riastrad static bool legacy_read_disabled_bios(struct radeon_device *rdev) 572 1.1 riastrad { 573 1.1 riastrad uint32_t seprom_cntl1; 574 1.1 riastrad uint32_t viph_control; 575 1.1 riastrad uint32_t bus_cntl; 576 1.1 riastrad uint32_t crtc_gen_cntl; 577 1.1 riastrad uint32_t crtc2_gen_cntl; 578 1.1 riastrad uint32_t crtc_ext_cntl; 579 1.1 riastrad uint32_t fp2_gen_cntl; 580 1.1 riastrad bool r; 581 1.1 riastrad 582 1.1 riastrad seprom_cntl1 = RREG32(RADEON_SEPROM_CNTL1); 583 1.1 riastrad viph_control = RREG32(RADEON_VIPH_CONTROL); 584 1.1 riastrad if (rdev->flags & RADEON_IS_PCIE) 585 1.1 riastrad bus_cntl = RREG32(RV370_BUS_CNTL); 586 1.1 riastrad else 587 1.1 riastrad bus_cntl = RREG32(RADEON_BUS_CNTL); 588 1.1 riastrad crtc_gen_cntl = RREG32(RADEON_CRTC_GEN_CNTL); 589 1.1 riastrad crtc2_gen_cntl = 0; 590 1.1 riastrad crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL); 591 1.1 riastrad fp2_gen_cntl = 0; 592 1.1 riastrad 593 1.1 riastrad if (rdev->ddev->pdev->device == PCI_DEVICE_ID_ATI_RADEON_QY) { 594 1.1 riastrad fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL); 595 1.1 riastrad } 596 1.1 riastrad 597 1.1 riastrad if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 598 1.1 riastrad crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL); 599 1.1 riastrad } 600 1.1 riastrad 601 1.1 riastrad WREG32(RADEON_SEPROM_CNTL1, 602 1.1 riastrad ((seprom_cntl1 & ~RADEON_SCK_PRESCALE_MASK) | 603 1.1 riastrad (0xc << RADEON_SCK_PRESCALE_SHIFT))); 604 1.1 riastrad 605 1.1 riastrad /* disable VIP */ 606 1.1 riastrad WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN)); 607 1.1 riastrad 608 1.1 riastrad /* enable the rom */ 609 1.1 riastrad if (rdev->flags & RADEON_IS_PCIE) 610 1.1 riastrad WREG32(RV370_BUS_CNTL, (bus_cntl & ~RV370_BUS_BIOS_DIS_ROM)); 611 1.1 riastrad else 612 1.1 riastrad WREG32(RADEON_BUS_CNTL, (bus_cntl & ~RADEON_BUS_BIOS_DIS_ROM)); 613 1.1 riastrad 614 1.1 riastrad /* Turn off mem requests and CRTC for both controllers */ 615 1.1 riastrad WREG32(RADEON_CRTC_GEN_CNTL, 616 1.1 riastrad ((crtc_gen_cntl & ~RADEON_CRTC_EN) | 617 1.1 riastrad (RADEON_CRTC_DISP_REQ_EN_B | 618 1.1 riastrad RADEON_CRTC_EXT_DISP_EN))); 619 1.1 riastrad if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 620 1.1 riastrad WREG32(RADEON_CRTC2_GEN_CNTL, 621 1.1 riastrad ((crtc2_gen_cntl & ~RADEON_CRTC2_EN) | 622 1.1 riastrad RADEON_CRTC2_DISP_REQ_EN_B)); 623 1.1 riastrad } 624 1.1 riastrad /* Turn off CRTC */ 625 1.1 riastrad WREG32(RADEON_CRTC_EXT_CNTL, 626 1.1 riastrad ((crtc_ext_cntl & ~RADEON_CRTC_CRT_ON) | 627 1.1 riastrad (RADEON_CRTC_SYNC_TRISTAT | 628 1.1 riastrad RADEON_CRTC_DISPLAY_DIS))); 629 1.1 riastrad 630 1.1 riastrad if (rdev->ddev->pdev->device == PCI_DEVICE_ID_ATI_RADEON_QY) { 631 1.1 riastrad WREG32(RADEON_FP2_GEN_CNTL, (fp2_gen_cntl & ~RADEON_FP2_ON)); 632 1.1 riastrad } 633 1.1 riastrad 634 1.1 riastrad r = radeon_read_bios(rdev); 635 1.1 riastrad 636 1.1 riastrad /* restore regs */ 637 1.1 riastrad WREG32(RADEON_SEPROM_CNTL1, seprom_cntl1); 638 1.1 riastrad WREG32(RADEON_VIPH_CONTROL, viph_control); 639 1.1 riastrad if (rdev->flags & RADEON_IS_PCIE) 640 1.1 riastrad WREG32(RV370_BUS_CNTL, bus_cntl); 641 1.1 riastrad else 642 1.1 riastrad WREG32(RADEON_BUS_CNTL, bus_cntl); 643 1.1 riastrad WREG32(RADEON_CRTC_GEN_CNTL, crtc_gen_cntl); 644 1.1 riastrad if (!(rdev->flags & RADEON_SINGLE_CRTC)) { 645 1.1 riastrad WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl); 646 1.1 riastrad } 647 1.1 riastrad WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl); 648 1.1 riastrad if (rdev->ddev->pdev->device == PCI_DEVICE_ID_ATI_RADEON_QY) { 649 1.1 riastrad WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl); 650 1.1 riastrad } 651 1.1 riastrad return r; 652 1.1 riastrad } 653 1.1 riastrad 654 1.1 riastrad static bool radeon_read_disabled_bios(struct radeon_device *rdev) 655 1.1 riastrad { 656 1.1 riastrad if (rdev->flags & RADEON_IS_IGP) 657 1.1 riastrad return igp_read_bios_from_vram(rdev); 658 1.1 riastrad else if (rdev->family >= CHIP_BARTS) 659 1.1 riastrad return ni_read_disabled_bios(rdev); 660 1.1 riastrad else if (rdev->family >= CHIP_RV770) 661 1.1 riastrad return r700_read_disabled_bios(rdev); 662 1.1 riastrad else if (rdev->family >= CHIP_R600) 663 1.1 riastrad return r600_read_disabled_bios(rdev); 664 1.1 riastrad else if (rdev->family >= CHIP_RS600) 665 1.1 riastrad return avivo_read_disabled_bios(rdev); 666 1.1 riastrad else 667 1.1 riastrad return legacy_read_disabled_bios(rdev); 668 1.1 riastrad } 669 1.1 riastrad 670 1.1 riastrad #ifdef CONFIG_ACPI 671 1.1 riastrad static bool radeon_acpi_vfct_bios(struct radeon_device *rdev) 672 1.1 riastrad { 673 1.1 riastrad struct acpi_table_header *hdr; 674 1.1 riastrad acpi_size tbl_size; 675 1.1 riastrad UEFI_ACPI_VFCT *vfct; 676 1.8 riastrad unsigned offset; 677 1.1 riastrad 678 1.8 riastrad if (!ACPI_SUCCESS(acpi_get_table("VFCT", 1, &hdr))) 679 1.1 riastrad return false; 680 1.8 riastrad tbl_size = hdr->length; 681 1.1 riastrad if (tbl_size < sizeof(UEFI_ACPI_VFCT)) { 682 1.1 riastrad DRM_ERROR("ACPI VFCT table present but broken (too short #1)\n"); 683 1.8 riastrad return false; 684 1.1 riastrad } 685 1.1 riastrad 686 1.1 riastrad vfct = (UEFI_ACPI_VFCT *)hdr; 687 1.8 riastrad offset = vfct->VBIOSImageOffset; 688 1.1 riastrad 689 1.8 riastrad while (offset < tbl_size) { 690 1.8 riastrad GOP_VBIOS_CONTENT *vbios = (GOP_VBIOS_CONTENT *)((char *)hdr + offset); 691 1.8 riastrad VFCT_IMAGE_HEADER *vhdr = &vbios->VbiosHeader; 692 1.8 riastrad 693 1.8 riastrad offset += sizeof(VFCT_IMAGE_HEADER); 694 1.8 riastrad if (offset > tbl_size) { 695 1.8 riastrad DRM_ERROR("ACPI VFCT image header truncated\n"); 696 1.8 riastrad return false; 697 1.8 riastrad } 698 1.1 riastrad 699 1.8 riastrad offset += vhdr->ImageLength; 700 1.8 riastrad if (offset > tbl_size) { 701 1.8 riastrad DRM_ERROR("ACPI VFCT image truncated\n"); 702 1.8 riastrad return false; 703 1.8 riastrad } 704 1.1 riastrad 705 1.8 riastrad if (vhdr->ImageLength && 706 1.8 riastrad vhdr->PCIBus == rdev->pdev->bus->number && 707 1.8 riastrad vhdr->PCIDevice == PCI_SLOT(rdev->pdev->devfn) && 708 1.8 riastrad vhdr->PCIFunction == PCI_FUNC(rdev->pdev->devfn) && 709 1.8 riastrad vhdr->VendorID == rdev->pdev->vendor && 710 1.8 riastrad vhdr->DeviceID == rdev->pdev->device) { 711 1.8 riastrad rdev->bios = kmemdup(&vbios->VbiosContent, 712 1.8 riastrad vhdr->ImageLength, 713 1.8 riastrad GFP_KERNEL); 714 1.8 riastrad 715 1.8 riastrad if (!rdev->bios) 716 1.8 riastrad return false; 717 1.8 riastrad return true; 718 1.8 riastrad } 719 1.1 riastrad } 720 1.1 riastrad 721 1.8 riastrad DRM_ERROR("ACPI VFCT table present but broken (too short #2)\n"); 722 1.8 riastrad return false; 723 1.1 riastrad } 724 1.1 riastrad #else 725 1.1 riastrad static inline bool radeon_acpi_vfct_bios(struct radeon_device *rdev) 726 1.1 riastrad { 727 1.1 riastrad return false; 728 1.1 riastrad } 729 1.1 riastrad #endif 730 1.1 riastrad 731 1.1 riastrad bool radeon_get_bios(struct radeon_device *rdev) 732 1.1 riastrad { 733 1.1 riastrad bool r; 734 1.1 riastrad uint16_t tmp; 735 1.1 riastrad 736 1.1 riastrad r = radeon_atrm_get_bios(rdev); 737 1.8 riastrad if (!r) 738 1.1 riastrad r = radeon_acpi_vfct_bios(rdev); 739 1.8 riastrad if (!r) 740 1.1 riastrad r = igp_read_bios_from_vram(rdev); 741 1.8 riastrad if (!r) 742 1.1 riastrad r = radeon_read_bios(rdev); 743 1.8 riastrad if (!r) 744 1.1 riastrad r = radeon_read_disabled_bios(rdev); 745 1.8 riastrad if (!r) 746 1.1 riastrad r = radeon_read_platform_bios(rdev); 747 1.8 riastrad if (!r || rdev->bios == NULL) { 748 1.1 riastrad DRM_ERROR("Unable to locate a BIOS ROM\n"); 749 1.1 riastrad rdev->bios = NULL; 750 1.1 riastrad return false; 751 1.1 riastrad } 752 1.1 riastrad if (rdev->bios[0] != 0x55 || rdev->bios[1] != 0xaa) { 753 1.1 riastrad printk("BIOS signature incorrect %x %x\n", rdev->bios[0], rdev->bios[1]); 754 1.1 riastrad goto free_bios; 755 1.1 riastrad } 756 1.1 riastrad 757 1.1 riastrad tmp = RBIOS16(0x18); 758 1.1 riastrad if (RBIOS8(tmp + 0x14) != 0x0) { 759 1.1 riastrad DRM_INFO("Not an x86 BIOS ROM, not using.\n"); 760 1.1 riastrad goto free_bios; 761 1.1 riastrad } 762 1.1 riastrad 763 1.1 riastrad rdev->bios_header_start = RBIOS16(0x48); 764 1.1 riastrad if (!rdev->bios_header_start) { 765 1.1 riastrad goto free_bios; 766 1.1 riastrad } 767 1.1 riastrad tmp = rdev->bios_header_start + 4; 768 1.1 riastrad if (!memcmp(rdev->bios + tmp, "ATOM", 4) || 769 1.1 riastrad !memcmp(rdev->bios + tmp, "MOTA", 4)) { 770 1.1 riastrad rdev->is_atom_bios = true; 771 1.1 riastrad } else { 772 1.1 riastrad rdev->is_atom_bios = false; 773 1.1 riastrad } 774 1.1 riastrad 775 1.1 riastrad DRM_DEBUG("%sBIOS detected\n", rdev->is_atom_bios ? "ATOM" : "COM"); 776 1.1 riastrad return true; 777 1.1 riastrad free_bios: 778 1.1 riastrad kfree(rdev->bios); 779 1.1 riastrad rdev->bios = NULL; 780 1.1 riastrad return false; 781 1.1 riastrad } 782