radeon_bios.c revision 254885
1254885Sdumbbell/*
2254885Sdumbbell * Copyright 2008 Advanced Micro Devices, Inc.
3254885Sdumbbell * Copyright 2008 Red Hat Inc.
4254885Sdumbbell * Copyright 2009 Jerome Glisse.
5254885Sdumbbell *
6254885Sdumbbell * Permission is hereby granted, free of charge, to any person obtaining a
7254885Sdumbbell * copy of this software and associated documentation files (the "Software"),
8254885Sdumbbell * to deal in the Software without restriction, including without limitation
9254885Sdumbbell * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10254885Sdumbbell * and/or sell copies of the Software, and to permit persons to whom the
11254885Sdumbbell * Software is furnished to do so, subject to the following conditions:
12254885Sdumbbell *
13254885Sdumbbell * The above copyright notice and this permission notice shall be included in
14254885Sdumbbell * all copies or substantial portions of the Software.
15254885Sdumbbell *
16254885Sdumbbell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17254885Sdumbbell * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18254885Sdumbbell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19254885Sdumbbell * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20254885Sdumbbell * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21254885Sdumbbell * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22254885Sdumbbell * OTHER DEALINGS IN THE SOFTWARE.
23254885Sdumbbell *
24254885Sdumbbell * Authors: Dave Airlie
25254885Sdumbbell *          Alex Deucher
26254885Sdumbbell *          Jerome Glisse
27254885Sdumbbell */
28254885Sdumbbell
29254885Sdumbbell#include <sys/cdefs.h>
30254885Sdumbbell__FBSDID("$FreeBSD: head/sys/dev/drm2/radeon/radeon_bios.c 254885 2013-08-25 19:37:15Z dumbbell $");
31254885Sdumbbell
32254885Sdumbbell#include <dev/drm2/drmP.h>
33254885Sdumbbell#include "radeon_reg.h"
34254885Sdumbbell#include "radeon.h"
35254885Sdumbbell#include "atom.h"
36254885Sdumbbell
37254885Sdumbbell/*
38254885Sdumbbell * BIOS.
39254885Sdumbbell */
40254885Sdumbbell
41254885Sdumbbell/* If you boot an IGP board with a discrete card as the primary,
42254885Sdumbbell * the IGP rom is not accessible via the rom bar as the IGP rom is
43254885Sdumbbell * part of the system bios.  On boot, the system bios puts a
44254885Sdumbbell * copy of the igp rom at the start of vram if a discrete card is
45254885Sdumbbell * present.
46254885Sdumbbell */
47254885Sdumbbellstatic bool igp_read_bios_from_vram(struct radeon_device *rdev)
48254885Sdumbbell{
49254885Sdumbbell	drm_local_map_t bios_map;
50254885Sdumbbell	uint8_t __iomem *bios;
51254885Sdumbbell	resource_size_t vram_base;
52254885Sdumbbell	resource_size_t size = 256 * 1024; /* ??? */
53254885Sdumbbell
54254885Sdumbbell	DRM_INFO("%s: ===> Try IGP's VRAM...\n", __func__);
55254885Sdumbbell
56254885Sdumbbell	if (!(rdev->flags & RADEON_IS_IGP))
57254885Sdumbbell		if (!radeon_card_posted(rdev)) {
58254885Sdumbbell			DRM_INFO("%s: not POSTed discrete card detected, skipping this method...\n",
59254885Sdumbbell			    __func__);
60254885Sdumbbell			return false;
61254885Sdumbbell		}
62254885Sdumbbell
63254885Sdumbbell	rdev->bios = NULL;
64254885Sdumbbell	vram_base = drm_get_resource_start(rdev->ddev, 0);
65254885Sdumbbell	DRM_INFO("%s: VRAM base address: 0x%jx\n", __func__, (uintmax_t)vram_base);
66254885Sdumbbell
67254885Sdumbbell	bios_map.offset = vram_base;
68254885Sdumbbell	bios_map.size   = size;
69254885Sdumbbell	bios_map.type   = 0;
70254885Sdumbbell	bios_map.flags  = 0;
71254885Sdumbbell	bios_map.mtrr   = 0;
72254885Sdumbbell	drm_core_ioremap(&bios_map, rdev->ddev);
73254885Sdumbbell	if (bios_map.virtual == NULL) {
74254885Sdumbbell		DRM_INFO("%s: failed to ioremap\n", __func__);
75254885Sdumbbell		return false;
76254885Sdumbbell	}
77254885Sdumbbell	bios = bios_map.virtual;
78254885Sdumbbell	size = bios_map.size;
79254885Sdumbbell	DRM_INFO("%s: Map address: %p (%ju bytes)\n", __func__, bios, (uintmax_t)size);
80254885Sdumbbell
81254885Sdumbbell	if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) {
82254885Sdumbbell		if (size == 0) {
83254885Sdumbbell			DRM_INFO("%s: Incorrect BIOS size\n", __func__);
84254885Sdumbbell		} else {
85254885Sdumbbell			DRM_INFO("%s: Incorrect BIOS signature: 0x%02X%02X\n",
86254885Sdumbbell			    __func__, bios[0], bios[1]);
87254885Sdumbbell		}
88254885Sdumbbell		drm_core_ioremapfree(&bios_map, rdev->ddev);
89254885Sdumbbell		return false;
90254885Sdumbbell	}
91254885Sdumbbell	rdev->bios = malloc(size, DRM_MEM_DRIVER, M_WAITOK);
92254885Sdumbbell	if (rdev->bios == NULL) {
93254885Sdumbbell		drm_core_ioremapfree(&bios_map, rdev->ddev);
94254885Sdumbbell		return false;
95254885Sdumbbell	}
96254885Sdumbbell	memcpy_fromio(rdev->bios, bios, size);
97254885Sdumbbell	drm_core_ioremapfree(&bios_map, rdev->ddev);
98254885Sdumbbell	return true;
99254885Sdumbbell}
100254885Sdumbbell
101254885Sdumbbellstatic bool radeon_read_bios(struct radeon_device *rdev)
102254885Sdumbbell{
103254885Sdumbbell	uint8_t __iomem *bios;
104254885Sdumbbell	size_t size;
105254885Sdumbbell
106254885Sdumbbell	DRM_INFO("%s: ===> Try PCI Expansion ROM...\n", __func__);
107254885Sdumbbell
108254885Sdumbbell	rdev->bios = NULL;
109254885Sdumbbell	/* XXX: some cards may return 0 for rom size? ddx has a workaround */
110254885Sdumbbell	bios = vga_pci_map_bios(rdev->dev, &size);
111254885Sdumbbell	if (!bios) {
112254885Sdumbbell		return false;
113254885Sdumbbell	}
114254885Sdumbbell	DRM_INFO("%s: Map address: %p (%zu bytes)\n", __func__, bios, size);
115254885Sdumbbell
116254885Sdumbbell	if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) {
117254885Sdumbbell		if (size == 0) {
118254885Sdumbbell			DRM_INFO("%s: Incorrect BIOS size\n", __func__);
119254885Sdumbbell		} else {
120254885Sdumbbell			DRM_INFO("%s: Incorrect BIOS signature: 0x%02X%02X\n",
121254885Sdumbbell			    __func__, bios[0], bios[1]);
122254885Sdumbbell		}
123254885Sdumbbell		vga_pci_unmap_bios(rdev->dev, bios);
124254885Sdumbbell	}
125254885Sdumbbell	rdev->bios = malloc(size, DRM_MEM_DRIVER, M_WAITOK);
126254885Sdumbbell	memcpy(rdev->bios, bios, size);
127254885Sdumbbell	vga_pci_unmap_bios(rdev->dev, bios);
128254885Sdumbbell	return true;
129254885Sdumbbell}
130254885Sdumbbell
131254885Sdumbbell/* ATRM is used to get the BIOS on the discrete cards in
132254885Sdumbbell * dual-gpu systems.
133254885Sdumbbell */
134254885Sdumbbell/* retrieve the ROM in 4k blocks */
135254885Sdumbbell#define ATRM_BIOS_PAGE 4096
136254885Sdumbbell/**
137254885Sdumbbell * radeon_atrm_call - fetch a chunk of the vbios
138254885Sdumbbell *
139254885Sdumbbell * @atrm_handle: acpi ATRM handle
140254885Sdumbbell * @bios: vbios image pointer
141254885Sdumbbell * @offset: offset of vbios image data to fetch
142254885Sdumbbell * @len: length of vbios image data to fetch
143254885Sdumbbell *
144254885Sdumbbell * Executes ATRM to fetch a chunk of the discrete
145254885Sdumbbell * vbios image on PX systems (all asics).
146254885Sdumbbell * Returns the length of the buffer fetched.
147254885Sdumbbell */
148254885Sdumbbellstatic int radeon_atrm_call(ACPI_HANDLE atrm_handle, uint8_t *bios,
149254885Sdumbbell			    int offset, int len)
150254885Sdumbbell{
151254885Sdumbbell	ACPI_STATUS status;
152254885Sdumbbell	ACPI_OBJECT atrm_arg_elements[2], *obj;
153254885Sdumbbell	ACPI_OBJECT_LIST atrm_arg;
154254885Sdumbbell	ACPI_BUFFER buffer = { ACPI_ALLOCATE_BUFFER, NULL};
155254885Sdumbbell
156254885Sdumbbell	atrm_arg.Count = 2;
157254885Sdumbbell	atrm_arg.Pointer = &atrm_arg_elements[0];
158254885Sdumbbell
159254885Sdumbbell	atrm_arg_elements[0].Type = ACPI_TYPE_INTEGER;
160254885Sdumbbell	atrm_arg_elements[0].Integer.Value = offset;
161254885Sdumbbell
162254885Sdumbbell	atrm_arg_elements[1].Type = ACPI_TYPE_INTEGER;
163254885Sdumbbell	atrm_arg_elements[1].Integer.Value = len;
164254885Sdumbbell
165254885Sdumbbell	status = AcpiEvaluateObject(atrm_handle, NULL, &atrm_arg, &buffer);
166254885Sdumbbell	if (ACPI_FAILURE(status)) {
167254885Sdumbbell		DRM_ERROR("failed to evaluate ATRM got %s\n", AcpiFormatException(status));
168254885Sdumbbell		return -ENODEV;
169254885Sdumbbell	}
170254885Sdumbbell
171254885Sdumbbell	obj = (ACPI_OBJECT *)buffer.Pointer;
172254885Sdumbbell	memcpy(bios+offset, obj->Buffer.Pointer, obj->Buffer.Length);
173254885Sdumbbell	len = obj->Buffer.Length;
174254885Sdumbbell	AcpiOsFree(buffer.Pointer);
175254885Sdumbbell	return len;
176254885Sdumbbell}
177254885Sdumbbell
178254885Sdumbbellstatic bool radeon_atrm_get_bios(struct radeon_device *rdev)
179254885Sdumbbell{
180254885Sdumbbell	int ret;
181254885Sdumbbell	int size = 256 * 1024;
182254885Sdumbbell	int i;
183254885Sdumbbell	device_t dev;
184254885Sdumbbell	ACPI_HANDLE dhandle, atrm_handle;
185254885Sdumbbell	ACPI_STATUS status;
186254885Sdumbbell	bool found = false;
187254885Sdumbbell
188254885Sdumbbell	DRM_INFO("%s: ===> Try ATRM...\n", __func__);
189254885Sdumbbell
190254885Sdumbbell	/* ATRM is for the discrete card only */
191254885Sdumbbell	if (rdev->flags & RADEON_IS_IGP) {
192254885Sdumbbell		DRM_INFO("%s: IGP card detected, skipping this method...\n",
193254885Sdumbbell		    __func__);
194254885Sdumbbell		return false;
195254885Sdumbbell	}
196254885Sdumbbell
197254885Sdumbbell#ifdef DUMBBELL_WIP
198254885Sdumbbell	while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
199254885Sdumbbell#endif /* DUMBBELL_WIP */
200254885Sdumbbell	if ((dev = pci_find_class(PCIC_DISPLAY, PCIS_DISPLAY_VGA)) != NULL) {
201254885Sdumbbell		DRM_INFO("%s: pci_find_class() found: %d:%d:%d:%d, vendor=%04x, device=%04x\n",
202254885Sdumbbell		    __func__,
203254885Sdumbbell		    pci_get_domain(dev),
204254885Sdumbbell		    pci_get_bus(dev),
205254885Sdumbbell		    pci_get_slot(dev),
206254885Sdumbbell		    pci_get_function(dev),
207254885Sdumbbell		    pci_get_vendor(dev),
208254885Sdumbbell		    pci_get_device(dev));
209254885Sdumbbell		DRM_INFO("%s: Get ACPI device handle\n", __func__);
210254885Sdumbbell		dhandle = acpi_get_handle(dev);
211254885Sdumbbell#ifdef DUMBBELL_WIP
212254885Sdumbbell		if (!dhandle)
213254885Sdumbbell			continue;
214254885Sdumbbell#endif /* DUMBBELL_WIP */
215254885Sdumbbell		if (!dhandle)
216254885Sdumbbell			return false;
217254885Sdumbbell
218254885Sdumbbell		DRM_INFO("%s: Get ACPI handle for \"ATRM\"\n", __func__);
219254885Sdumbbell		status = AcpiGetHandle(dhandle, "ATRM", &atrm_handle);
220254885Sdumbbell		if (!ACPI_FAILURE(status)) {
221254885Sdumbbell			found = true;
222254885Sdumbbell#ifdef DUMBBELL_WIP
223254885Sdumbbell			break;
224254885Sdumbbell#endif /* DUMBBELL_WIP */
225254885Sdumbbell		} else {
226254885Sdumbbell			DRM_INFO("%s: Failed to get \"ATRM\" handle: %s\n",
227254885Sdumbbell			    __func__, AcpiFormatException(status));
228254885Sdumbbell		}
229254885Sdumbbell	}
230254885Sdumbbell
231254885Sdumbbell	if (!found)
232254885Sdumbbell		return false;
233254885Sdumbbell
234254885Sdumbbell	rdev->bios = malloc(size, DRM_MEM_DRIVER, M_WAITOK);
235254885Sdumbbell	if (!rdev->bios) {
236254885Sdumbbell		DRM_ERROR("Unable to allocate bios\n");
237254885Sdumbbell		return false;
238254885Sdumbbell	}
239254885Sdumbbell
240254885Sdumbbell	for (i = 0; i < size / ATRM_BIOS_PAGE; i++) {
241254885Sdumbbell		DRM_INFO("%s: Call radeon_atrm_call()\n", __func__);
242254885Sdumbbell		ret = radeon_atrm_call(atrm_handle,
243254885Sdumbbell				       rdev->bios,
244254885Sdumbbell				       (i * ATRM_BIOS_PAGE),
245254885Sdumbbell				       ATRM_BIOS_PAGE);
246254885Sdumbbell		if (ret < ATRM_BIOS_PAGE)
247254885Sdumbbell			break;
248254885Sdumbbell	}
249254885Sdumbbell
250254885Sdumbbell	if (i == 0 || rdev->bios[0] != 0x55 || rdev->bios[1] != 0xaa) {
251254885Sdumbbell		if (i == 0) {
252254885Sdumbbell			DRM_INFO("%s: Incorrect BIOS size\n", __func__);
253254885Sdumbbell		} else {
254254885Sdumbbell			DRM_INFO("%s: Incorrect BIOS signature: 0x%02X%02X\n",
255254885Sdumbbell			    __func__, rdev->bios[0], rdev->bios[1]);
256254885Sdumbbell		}
257254885Sdumbbell		free(rdev->bios, DRM_MEM_DRIVER);
258254885Sdumbbell		return false;
259254885Sdumbbell	}
260254885Sdumbbell	return true;
261254885Sdumbbell}
262254885Sdumbbell
263254885Sdumbbellstatic bool ni_read_disabled_bios(struct radeon_device *rdev)
264254885Sdumbbell{
265254885Sdumbbell	u32 bus_cntl;
266254885Sdumbbell	u32 d1vga_control;
267254885Sdumbbell	u32 d2vga_control;
268254885Sdumbbell	u32 vga_render_control;
269254885Sdumbbell	u32 rom_cntl;
270254885Sdumbbell	bool r;
271254885Sdumbbell
272254885Sdumbbell	DRM_INFO("%s: ===> Try disabled BIOS (ni)...\n", __func__);
273254885Sdumbbell
274254885Sdumbbell	bus_cntl = RREG32(R600_BUS_CNTL);
275254885Sdumbbell	d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
276254885Sdumbbell	d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
277254885Sdumbbell	vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
278254885Sdumbbell	rom_cntl = RREG32(R600_ROM_CNTL);
279254885Sdumbbell
280254885Sdumbbell	/* enable the rom */
281254885Sdumbbell	WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS));
282254885Sdumbbell	/* Disable VGA mode */
283254885Sdumbbell	WREG32(AVIVO_D1VGA_CONTROL,
284254885Sdumbbell	       (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
285254885Sdumbbell		AVIVO_DVGA_CONTROL_TIMING_SELECT)));
286254885Sdumbbell	WREG32(AVIVO_D2VGA_CONTROL,
287254885Sdumbbell	       (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
288254885Sdumbbell		AVIVO_DVGA_CONTROL_TIMING_SELECT)));
289254885Sdumbbell	WREG32(AVIVO_VGA_RENDER_CONTROL,
290254885Sdumbbell	       (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK));
291254885Sdumbbell	WREG32(R600_ROM_CNTL, rom_cntl | R600_SCK_OVERWRITE);
292254885Sdumbbell
293254885Sdumbbell	r = radeon_read_bios(rdev);
294254885Sdumbbell
295254885Sdumbbell	/* restore regs */
296254885Sdumbbell	WREG32(R600_BUS_CNTL, bus_cntl);
297254885Sdumbbell	WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
298254885Sdumbbell	WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
299254885Sdumbbell	WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
300254885Sdumbbell	WREG32(R600_ROM_CNTL, rom_cntl);
301254885Sdumbbell	return r;
302254885Sdumbbell}
303254885Sdumbbell
304254885Sdumbbellstatic bool r700_read_disabled_bios(struct radeon_device *rdev)
305254885Sdumbbell{
306254885Sdumbbell	uint32_t viph_control;
307254885Sdumbbell	uint32_t bus_cntl;
308254885Sdumbbell	uint32_t d1vga_control;
309254885Sdumbbell	uint32_t d2vga_control;
310254885Sdumbbell	uint32_t vga_render_control;
311254885Sdumbbell	uint32_t rom_cntl;
312254885Sdumbbell	uint32_t cg_spll_func_cntl = 0;
313254885Sdumbbell	uint32_t cg_spll_status;
314254885Sdumbbell	bool r;
315254885Sdumbbell
316254885Sdumbbell	DRM_INFO("%s: ===> Try disabled BIOS (r700)...\n", __func__);
317254885Sdumbbell
318254885Sdumbbell	viph_control = RREG32(RADEON_VIPH_CONTROL);
319254885Sdumbbell	bus_cntl = RREG32(R600_BUS_CNTL);
320254885Sdumbbell	d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
321254885Sdumbbell	d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
322254885Sdumbbell	vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
323254885Sdumbbell	rom_cntl = RREG32(R600_ROM_CNTL);
324254885Sdumbbell
325254885Sdumbbell	/* disable VIP */
326254885Sdumbbell	WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
327254885Sdumbbell	/* enable the rom */
328254885Sdumbbell	WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS));
329254885Sdumbbell	/* Disable VGA mode */
330254885Sdumbbell	WREG32(AVIVO_D1VGA_CONTROL,
331254885Sdumbbell	       (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
332254885Sdumbbell		AVIVO_DVGA_CONTROL_TIMING_SELECT)));
333254885Sdumbbell	WREG32(AVIVO_D2VGA_CONTROL,
334254885Sdumbbell	       (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
335254885Sdumbbell		AVIVO_DVGA_CONTROL_TIMING_SELECT)));
336254885Sdumbbell	WREG32(AVIVO_VGA_RENDER_CONTROL,
337254885Sdumbbell	       (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK));
338254885Sdumbbell
339254885Sdumbbell	if (rdev->family == CHIP_RV730) {
340254885Sdumbbell		cg_spll_func_cntl = RREG32(R600_CG_SPLL_FUNC_CNTL);
341254885Sdumbbell
342254885Sdumbbell		/* enable bypass mode */
343254885Sdumbbell		WREG32(R600_CG_SPLL_FUNC_CNTL, (cg_spll_func_cntl |
344254885Sdumbbell						R600_SPLL_BYPASS_EN));
345254885Sdumbbell
346254885Sdumbbell		/* wait for SPLL_CHG_STATUS to change to 1 */
347254885Sdumbbell		cg_spll_status = 0;
348254885Sdumbbell		while (!(cg_spll_status & R600_SPLL_CHG_STATUS))
349254885Sdumbbell			cg_spll_status = RREG32(R600_CG_SPLL_STATUS);
350254885Sdumbbell
351254885Sdumbbell		WREG32(R600_ROM_CNTL, (rom_cntl & ~R600_SCK_OVERWRITE));
352254885Sdumbbell	} else
353254885Sdumbbell		WREG32(R600_ROM_CNTL, (rom_cntl | R600_SCK_OVERWRITE));
354254885Sdumbbell
355254885Sdumbbell	r = radeon_read_bios(rdev);
356254885Sdumbbell
357254885Sdumbbell	/* restore regs */
358254885Sdumbbell	if (rdev->family == CHIP_RV730) {
359254885Sdumbbell		WREG32(R600_CG_SPLL_FUNC_CNTL, cg_spll_func_cntl);
360254885Sdumbbell
361254885Sdumbbell		/* wait for SPLL_CHG_STATUS to change to 1 */
362254885Sdumbbell		cg_spll_status = 0;
363254885Sdumbbell		while (!(cg_spll_status & R600_SPLL_CHG_STATUS))
364254885Sdumbbell			cg_spll_status = RREG32(R600_CG_SPLL_STATUS);
365254885Sdumbbell	}
366254885Sdumbbell	WREG32(RADEON_VIPH_CONTROL, viph_control);
367254885Sdumbbell	WREG32(R600_BUS_CNTL, bus_cntl);
368254885Sdumbbell	WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
369254885Sdumbbell	WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
370254885Sdumbbell	WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
371254885Sdumbbell	WREG32(R600_ROM_CNTL, rom_cntl);
372254885Sdumbbell	return r;
373254885Sdumbbell}
374254885Sdumbbell
375254885Sdumbbellstatic bool r600_read_disabled_bios(struct radeon_device *rdev)
376254885Sdumbbell{
377254885Sdumbbell	uint32_t viph_control;
378254885Sdumbbell	uint32_t bus_cntl;
379254885Sdumbbell	uint32_t d1vga_control;
380254885Sdumbbell	uint32_t d2vga_control;
381254885Sdumbbell	uint32_t vga_render_control;
382254885Sdumbbell	uint32_t rom_cntl;
383254885Sdumbbell	uint32_t general_pwrmgt;
384254885Sdumbbell	uint32_t low_vid_lower_gpio_cntl;
385254885Sdumbbell	uint32_t medium_vid_lower_gpio_cntl;
386254885Sdumbbell	uint32_t high_vid_lower_gpio_cntl;
387254885Sdumbbell	uint32_t ctxsw_vid_lower_gpio_cntl;
388254885Sdumbbell	uint32_t lower_gpio_enable;
389254885Sdumbbell	bool r;
390254885Sdumbbell
391254885Sdumbbell	DRM_INFO("%s: ===> Try disabled BIOS (r600)...\n", __func__);
392254885Sdumbbell
393254885Sdumbbell	viph_control = RREG32(RADEON_VIPH_CONTROL);
394254885Sdumbbell	bus_cntl = RREG32(R600_BUS_CNTL);
395254885Sdumbbell	d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
396254885Sdumbbell	d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
397254885Sdumbbell	vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
398254885Sdumbbell	rom_cntl = RREG32(R600_ROM_CNTL);
399254885Sdumbbell	general_pwrmgt = RREG32(R600_GENERAL_PWRMGT);
400254885Sdumbbell	low_vid_lower_gpio_cntl = RREG32(R600_LOW_VID_LOWER_GPIO_CNTL);
401254885Sdumbbell	medium_vid_lower_gpio_cntl = RREG32(R600_MEDIUM_VID_LOWER_GPIO_CNTL);
402254885Sdumbbell	high_vid_lower_gpio_cntl = RREG32(R600_HIGH_VID_LOWER_GPIO_CNTL);
403254885Sdumbbell	ctxsw_vid_lower_gpio_cntl = RREG32(R600_CTXSW_VID_LOWER_GPIO_CNTL);
404254885Sdumbbell	lower_gpio_enable = RREG32(R600_LOWER_GPIO_ENABLE);
405254885Sdumbbell
406254885Sdumbbell	/* disable VIP */
407254885Sdumbbell	WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
408254885Sdumbbell	/* enable the rom */
409254885Sdumbbell	WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS));
410254885Sdumbbell	/* Disable VGA mode */
411254885Sdumbbell	WREG32(AVIVO_D1VGA_CONTROL,
412254885Sdumbbell	       (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
413254885Sdumbbell		AVIVO_DVGA_CONTROL_TIMING_SELECT)));
414254885Sdumbbell	WREG32(AVIVO_D2VGA_CONTROL,
415254885Sdumbbell	       (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
416254885Sdumbbell		AVIVO_DVGA_CONTROL_TIMING_SELECT)));
417254885Sdumbbell	WREG32(AVIVO_VGA_RENDER_CONTROL,
418254885Sdumbbell	       (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK));
419254885Sdumbbell
420254885Sdumbbell	WREG32(R600_ROM_CNTL,
421254885Sdumbbell	       ((rom_cntl & ~R600_SCK_PRESCALE_CRYSTAL_CLK_MASK) |
422254885Sdumbbell		(1 << R600_SCK_PRESCALE_CRYSTAL_CLK_SHIFT) |
423254885Sdumbbell		R600_SCK_OVERWRITE));
424254885Sdumbbell
425254885Sdumbbell	WREG32(R600_GENERAL_PWRMGT, (general_pwrmgt & ~R600_OPEN_DRAIN_PADS));
426254885Sdumbbell	WREG32(R600_LOW_VID_LOWER_GPIO_CNTL,
427254885Sdumbbell	       (low_vid_lower_gpio_cntl & ~0x400));
428254885Sdumbbell	WREG32(R600_MEDIUM_VID_LOWER_GPIO_CNTL,
429254885Sdumbbell	       (medium_vid_lower_gpio_cntl & ~0x400));
430254885Sdumbbell	WREG32(R600_HIGH_VID_LOWER_GPIO_CNTL,
431254885Sdumbbell	       (high_vid_lower_gpio_cntl & ~0x400));
432254885Sdumbbell	WREG32(R600_CTXSW_VID_LOWER_GPIO_CNTL,
433254885Sdumbbell	       (ctxsw_vid_lower_gpio_cntl & ~0x400));
434254885Sdumbbell	WREG32(R600_LOWER_GPIO_ENABLE, (lower_gpio_enable | 0x400));
435254885Sdumbbell
436254885Sdumbbell	r = radeon_read_bios(rdev);
437254885Sdumbbell
438254885Sdumbbell	/* restore regs */
439254885Sdumbbell	WREG32(RADEON_VIPH_CONTROL, viph_control);
440254885Sdumbbell	WREG32(R600_BUS_CNTL, bus_cntl);
441254885Sdumbbell	WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
442254885Sdumbbell	WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
443254885Sdumbbell	WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
444254885Sdumbbell	WREG32(R600_ROM_CNTL, rom_cntl);
445254885Sdumbbell	WREG32(R600_GENERAL_PWRMGT, general_pwrmgt);
446254885Sdumbbell	WREG32(R600_LOW_VID_LOWER_GPIO_CNTL, low_vid_lower_gpio_cntl);
447254885Sdumbbell	WREG32(R600_MEDIUM_VID_LOWER_GPIO_CNTL, medium_vid_lower_gpio_cntl);
448254885Sdumbbell	WREG32(R600_HIGH_VID_LOWER_GPIO_CNTL, high_vid_lower_gpio_cntl);
449254885Sdumbbell	WREG32(R600_CTXSW_VID_LOWER_GPIO_CNTL, ctxsw_vid_lower_gpio_cntl);
450254885Sdumbbell	WREG32(R600_LOWER_GPIO_ENABLE, lower_gpio_enable);
451254885Sdumbbell	return r;
452254885Sdumbbell}
453254885Sdumbbell
454254885Sdumbbellstatic bool avivo_read_disabled_bios(struct radeon_device *rdev)
455254885Sdumbbell{
456254885Sdumbbell	uint32_t seprom_cntl1;
457254885Sdumbbell	uint32_t viph_control;
458254885Sdumbbell	uint32_t bus_cntl;
459254885Sdumbbell	uint32_t d1vga_control;
460254885Sdumbbell	uint32_t d2vga_control;
461254885Sdumbbell	uint32_t vga_render_control;
462254885Sdumbbell	uint32_t gpiopad_a;
463254885Sdumbbell	uint32_t gpiopad_en;
464254885Sdumbbell	uint32_t gpiopad_mask;
465254885Sdumbbell	bool r;
466254885Sdumbbell
467254885Sdumbbell	DRM_INFO("%s: ===> Try disabled BIOS (avivo)...\n", __func__);
468254885Sdumbbell
469254885Sdumbbell	seprom_cntl1 = RREG32(RADEON_SEPROM_CNTL1);
470254885Sdumbbell	viph_control = RREG32(RADEON_VIPH_CONTROL);
471254885Sdumbbell	bus_cntl = RREG32(RV370_BUS_CNTL);
472254885Sdumbbell	d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
473254885Sdumbbell	d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
474254885Sdumbbell	vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
475254885Sdumbbell	gpiopad_a = RREG32(RADEON_GPIOPAD_A);
476254885Sdumbbell	gpiopad_en = RREG32(RADEON_GPIOPAD_EN);
477254885Sdumbbell	gpiopad_mask = RREG32(RADEON_GPIOPAD_MASK);
478254885Sdumbbell
479254885Sdumbbell	WREG32(RADEON_SEPROM_CNTL1,
480254885Sdumbbell	       ((seprom_cntl1 & ~RADEON_SCK_PRESCALE_MASK) |
481254885Sdumbbell		(0xc << RADEON_SCK_PRESCALE_SHIFT)));
482254885Sdumbbell	WREG32(RADEON_GPIOPAD_A, 0);
483254885Sdumbbell	WREG32(RADEON_GPIOPAD_EN, 0);
484254885Sdumbbell	WREG32(RADEON_GPIOPAD_MASK, 0);
485254885Sdumbbell
486254885Sdumbbell	/* disable VIP */
487254885Sdumbbell	WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
488254885Sdumbbell
489254885Sdumbbell	/* enable the rom */
490254885Sdumbbell	WREG32(RV370_BUS_CNTL, (bus_cntl & ~RV370_BUS_BIOS_DIS_ROM));
491254885Sdumbbell
492254885Sdumbbell	/* Disable VGA mode */
493254885Sdumbbell	WREG32(AVIVO_D1VGA_CONTROL,
494254885Sdumbbell	       (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
495254885Sdumbbell		AVIVO_DVGA_CONTROL_TIMING_SELECT)));
496254885Sdumbbell	WREG32(AVIVO_D2VGA_CONTROL,
497254885Sdumbbell	       (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
498254885Sdumbbell		AVIVO_DVGA_CONTROL_TIMING_SELECT)));
499254885Sdumbbell	WREG32(AVIVO_VGA_RENDER_CONTROL,
500254885Sdumbbell	       (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK));
501254885Sdumbbell
502254885Sdumbbell	r = radeon_read_bios(rdev);
503254885Sdumbbell
504254885Sdumbbell	/* restore regs */
505254885Sdumbbell	WREG32(RADEON_SEPROM_CNTL1, seprom_cntl1);
506254885Sdumbbell	WREG32(RADEON_VIPH_CONTROL, viph_control);
507254885Sdumbbell	WREG32(RV370_BUS_CNTL, bus_cntl);
508254885Sdumbbell	WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
509254885Sdumbbell	WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
510254885Sdumbbell	WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
511254885Sdumbbell	WREG32(RADEON_GPIOPAD_A, gpiopad_a);
512254885Sdumbbell	WREG32(RADEON_GPIOPAD_EN, gpiopad_en);
513254885Sdumbbell	WREG32(RADEON_GPIOPAD_MASK, gpiopad_mask);
514254885Sdumbbell	return r;
515254885Sdumbbell}
516254885Sdumbbell
517254885Sdumbbellstatic bool legacy_read_disabled_bios(struct radeon_device *rdev)
518254885Sdumbbell{
519254885Sdumbbell	uint32_t seprom_cntl1;
520254885Sdumbbell	uint32_t viph_control;
521254885Sdumbbell	uint32_t bus_cntl;
522254885Sdumbbell	uint32_t crtc_gen_cntl;
523254885Sdumbbell	uint32_t crtc2_gen_cntl;
524254885Sdumbbell	uint32_t crtc_ext_cntl;
525254885Sdumbbell	uint32_t fp2_gen_cntl;
526254885Sdumbbell	bool r;
527254885Sdumbbell
528254885Sdumbbell	DRM_INFO("%s: ===> Try disabled BIOS (legacy)...\n", __func__);
529254885Sdumbbell
530254885Sdumbbell	seprom_cntl1 = RREG32(RADEON_SEPROM_CNTL1);
531254885Sdumbbell	viph_control = RREG32(RADEON_VIPH_CONTROL);
532254885Sdumbbell	if (rdev->flags & RADEON_IS_PCIE)
533254885Sdumbbell		bus_cntl = RREG32(RV370_BUS_CNTL);
534254885Sdumbbell	else
535254885Sdumbbell		bus_cntl = RREG32(RADEON_BUS_CNTL);
536254885Sdumbbell	crtc_gen_cntl = RREG32(RADEON_CRTC_GEN_CNTL);
537254885Sdumbbell	crtc2_gen_cntl = 0;
538254885Sdumbbell	crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
539254885Sdumbbell	fp2_gen_cntl = 0;
540254885Sdumbbell
541254885Sdumbbell#define	PCI_DEVICE_ID_ATI_RADEON_QY	0x5159
542254885Sdumbbell
543254885Sdumbbell	if (rdev->ddev->pci_device == PCI_DEVICE_ID_ATI_RADEON_QY) {
544254885Sdumbbell		fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
545254885Sdumbbell	}
546254885Sdumbbell
547254885Sdumbbell	if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
548254885Sdumbbell		crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
549254885Sdumbbell	}
550254885Sdumbbell
551254885Sdumbbell	WREG32(RADEON_SEPROM_CNTL1,
552254885Sdumbbell	       ((seprom_cntl1 & ~RADEON_SCK_PRESCALE_MASK) |
553254885Sdumbbell		(0xc << RADEON_SCK_PRESCALE_SHIFT)));
554254885Sdumbbell
555254885Sdumbbell	/* disable VIP */
556254885Sdumbbell	WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
557254885Sdumbbell
558254885Sdumbbell	/* enable the rom */
559254885Sdumbbell	if (rdev->flags & RADEON_IS_PCIE)
560254885Sdumbbell		WREG32(RV370_BUS_CNTL, (bus_cntl & ~RV370_BUS_BIOS_DIS_ROM));
561254885Sdumbbell	else
562254885Sdumbbell		WREG32(RADEON_BUS_CNTL, (bus_cntl & ~RADEON_BUS_BIOS_DIS_ROM));
563254885Sdumbbell
564254885Sdumbbell	/* Turn off mem requests and CRTC for both controllers */
565254885Sdumbbell	WREG32(RADEON_CRTC_GEN_CNTL,
566254885Sdumbbell	       ((crtc_gen_cntl & ~RADEON_CRTC_EN) |
567254885Sdumbbell		(RADEON_CRTC_DISP_REQ_EN_B |
568254885Sdumbbell		 RADEON_CRTC_EXT_DISP_EN)));
569254885Sdumbbell	if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
570254885Sdumbbell		WREG32(RADEON_CRTC2_GEN_CNTL,
571254885Sdumbbell		       ((crtc2_gen_cntl & ~RADEON_CRTC2_EN) |
572254885Sdumbbell			RADEON_CRTC2_DISP_REQ_EN_B));
573254885Sdumbbell	}
574254885Sdumbbell	/* Turn off CRTC */
575254885Sdumbbell	WREG32(RADEON_CRTC_EXT_CNTL,
576254885Sdumbbell	       ((crtc_ext_cntl & ~RADEON_CRTC_CRT_ON) |
577254885Sdumbbell		(RADEON_CRTC_SYNC_TRISTAT |
578254885Sdumbbell		 RADEON_CRTC_DISPLAY_DIS)));
579254885Sdumbbell
580254885Sdumbbell	if (rdev->ddev->pci_device == PCI_DEVICE_ID_ATI_RADEON_QY) {
581254885Sdumbbell		WREG32(RADEON_FP2_GEN_CNTL, (fp2_gen_cntl & ~RADEON_FP2_ON));
582254885Sdumbbell	}
583254885Sdumbbell
584254885Sdumbbell	r = radeon_read_bios(rdev);
585254885Sdumbbell
586254885Sdumbbell	/* restore regs */
587254885Sdumbbell	WREG32(RADEON_SEPROM_CNTL1, seprom_cntl1);
588254885Sdumbbell	WREG32(RADEON_VIPH_CONTROL, viph_control);
589254885Sdumbbell	if (rdev->flags & RADEON_IS_PCIE)
590254885Sdumbbell		WREG32(RV370_BUS_CNTL, bus_cntl);
591254885Sdumbbell	else
592254885Sdumbbell		WREG32(RADEON_BUS_CNTL, bus_cntl);
593254885Sdumbbell	WREG32(RADEON_CRTC_GEN_CNTL, crtc_gen_cntl);
594254885Sdumbbell	if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
595254885Sdumbbell		WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
596254885Sdumbbell	}
597254885Sdumbbell	WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
598254885Sdumbbell	if (rdev->ddev->pci_device == PCI_DEVICE_ID_ATI_RADEON_QY) {
599254885Sdumbbell		WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
600254885Sdumbbell	}
601254885Sdumbbell	return r;
602254885Sdumbbell}
603254885Sdumbbell
604254885Sdumbbellstatic bool radeon_read_disabled_bios(struct radeon_device *rdev)
605254885Sdumbbell{
606254885Sdumbbell	if (rdev->flags & RADEON_IS_IGP)
607254885Sdumbbell		return igp_read_bios_from_vram(rdev);
608254885Sdumbbell	else if (rdev->family >= CHIP_BARTS)
609254885Sdumbbell		return ni_read_disabled_bios(rdev);
610254885Sdumbbell	else if (rdev->family >= CHIP_RV770)
611254885Sdumbbell		return r700_read_disabled_bios(rdev);
612254885Sdumbbell	else if (rdev->family >= CHIP_R600)
613254885Sdumbbell		return r600_read_disabled_bios(rdev);
614254885Sdumbbell	else if (rdev->family >= CHIP_RS600)
615254885Sdumbbell		return avivo_read_disabled_bios(rdev);
616254885Sdumbbell	else
617254885Sdumbbell		return legacy_read_disabled_bios(rdev);
618254885Sdumbbell}
619254885Sdumbbell
620254885Sdumbbellstatic bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
621254885Sdumbbell{
622254885Sdumbbell	bool ret = false;
623254885Sdumbbell	ACPI_TABLE_HEADER *hdr;
624254885Sdumbbell	ACPI_SIZE tbl_size;
625254885Sdumbbell	UEFI_ACPI_VFCT *vfct;
626254885Sdumbbell	GOP_VBIOS_CONTENT *vbios;
627254885Sdumbbell	VFCT_IMAGE_HEADER *vhdr;
628254885Sdumbbell	ACPI_STATUS status;
629254885Sdumbbell
630254885Sdumbbell	DRM_INFO("%s: ===> Try VFCT...\n", __func__);
631254885Sdumbbell
632254885Sdumbbell	DRM_INFO("%s: Get \"VFCT\" ACPI table\n", __func__);
633254885Sdumbbell	status = AcpiGetTable("VFCT", 1, &hdr);
634254885Sdumbbell	if (!ACPI_SUCCESS(status)) {
635254885Sdumbbell		DRM_INFO("%s: Failed to get \"VFCT\" table: %s\n",
636254885Sdumbbell		    __func__, AcpiFormatException(status));
637254885Sdumbbell		return false;
638254885Sdumbbell	}
639254885Sdumbbell	tbl_size = hdr->Length;
640254885Sdumbbell	if (tbl_size < sizeof(UEFI_ACPI_VFCT)) {
641254885Sdumbbell		DRM_ERROR("ACPI VFCT table present but broken (too short #1)\n");
642254885Sdumbbell		goto out_unmap;
643254885Sdumbbell	}
644254885Sdumbbell
645254885Sdumbbell	vfct = (UEFI_ACPI_VFCT *)hdr;
646254885Sdumbbell	if (vfct->VBIOSImageOffset + sizeof(VFCT_IMAGE_HEADER) > tbl_size) {
647254885Sdumbbell		DRM_ERROR("ACPI VFCT table present but broken (too short #2)\n");
648254885Sdumbbell		goto out_unmap;
649254885Sdumbbell	}
650254885Sdumbbell
651254885Sdumbbell	vbios = (GOP_VBIOS_CONTENT *)((char *)hdr + vfct->VBIOSImageOffset);
652254885Sdumbbell	vhdr = &vbios->VbiosHeader;
653254885Sdumbbell	DRM_INFO("ACPI VFCT contains a BIOS for %02x:%02x.%d %04x:%04x, size %d\n",
654254885Sdumbbell			vhdr->PCIBus, vhdr->PCIDevice, vhdr->PCIFunction,
655254885Sdumbbell			vhdr->VendorID, vhdr->DeviceID, vhdr->ImageLength);
656254885Sdumbbell
657254885Sdumbbell	if (vhdr->PCIBus != rdev->ddev->pci_bus ||
658254885Sdumbbell	    vhdr->PCIDevice != rdev->ddev->pci_slot ||
659254885Sdumbbell	    vhdr->PCIFunction != rdev->ddev->pci_func ||
660254885Sdumbbell	    vhdr->VendorID != rdev->ddev->pci_vendor ||
661254885Sdumbbell	    vhdr->DeviceID != rdev->ddev->pci_device) {
662254885Sdumbbell		DRM_INFO("ACPI VFCT table is not for this card\n");
663254885Sdumbbell		goto out_unmap;
664254885Sdumbbell	};
665254885Sdumbbell
666254885Sdumbbell	if (vfct->VBIOSImageOffset + sizeof(VFCT_IMAGE_HEADER) + vhdr->ImageLength > tbl_size) {
667254885Sdumbbell		DRM_ERROR("ACPI VFCT image truncated\n");
668254885Sdumbbell		goto out_unmap;
669254885Sdumbbell	}
670254885Sdumbbell
671254885Sdumbbell	rdev->bios = malloc(vhdr->ImageLength, DRM_MEM_DRIVER, M_WAITOK);
672254885Sdumbbell	memcpy(rdev->bios, &vbios->VbiosContent, vhdr->ImageLength);
673254885Sdumbbell	ret = !!rdev->bios;
674254885Sdumbbell
675254885Sdumbbellout_unmap:
676254885Sdumbbell	return ret;
677254885Sdumbbell}
678254885Sdumbbell
679254885Sdumbbellbool radeon_get_bios(struct radeon_device *rdev)
680254885Sdumbbell{
681254885Sdumbbell	bool r;
682254885Sdumbbell	uint16_t tmp;
683254885Sdumbbell
684254885Sdumbbell	r = radeon_atrm_get_bios(rdev);
685254885Sdumbbell	if (r == false)
686254885Sdumbbell		r = radeon_acpi_vfct_bios(rdev);
687254885Sdumbbell	if (r == false)
688254885Sdumbbell		r = igp_read_bios_from_vram(rdev);
689254885Sdumbbell	if (r == false)
690254885Sdumbbell		r = radeon_read_bios(rdev);
691254885Sdumbbell	if (r == false) {
692254885Sdumbbell		r = radeon_read_disabled_bios(rdev);
693254885Sdumbbell	}
694254885Sdumbbell	if (r == false || rdev->bios == NULL) {
695254885Sdumbbell		DRM_ERROR("Unable to locate a BIOS ROM\n");
696254885Sdumbbell		rdev->bios = NULL;
697254885Sdumbbell		return false;
698254885Sdumbbell	}
699254885Sdumbbell	if (rdev->bios[0] != 0x55 || rdev->bios[1] != 0xaa) {
700254885Sdumbbell		DRM_ERROR("BIOS signature incorrect %x %x\n", rdev->bios[0], rdev->bios[1]);
701254885Sdumbbell		goto free_bios;
702254885Sdumbbell	}
703254885Sdumbbell
704254885Sdumbbell	tmp = RBIOS16(0x18);
705254885Sdumbbell	if (RBIOS8(tmp + 0x14) != 0x0) {
706254885Sdumbbell		DRM_INFO("Not an x86 BIOS ROM, not using.\n");
707254885Sdumbbell		goto free_bios;
708254885Sdumbbell	}
709254885Sdumbbell
710254885Sdumbbell	rdev->bios_header_start = RBIOS16(0x48);
711254885Sdumbbell	if (!rdev->bios_header_start) {
712254885Sdumbbell		goto free_bios;
713254885Sdumbbell	}
714254885Sdumbbell	tmp = rdev->bios_header_start + 4;
715254885Sdumbbell	if (!memcmp(rdev->bios + tmp, "ATOM", 4) ||
716254885Sdumbbell	    !memcmp(rdev->bios + tmp, "MOTA", 4)) {
717254885Sdumbbell		rdev->is_atom_bios = true;
718254885Sdumbbell	} else {
719254885Sdumbbell		rdev->is_atom_bios = false;
720254885Sdumbbell	}
721254885Sdumbbell
722254885Sdumbbell	DRM_DEBUG("%sBIOS detected\n", rdev->is_atom_bios ? "ATOM" : "COM");
723254885Sdumbbell	return true;
724254885Sdumbbellfree_bios:
725254885Sdumbbell	free(rdev->bios, DRM_MEM_DRIVER);
726254885Sdumbbell	rdev->bios = NULL;
727254885Sdumbbell	return false;
728254885Sdumbbell}
729