radeon_bios.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  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:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  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.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include <drm/drmP.h>
  29. #include "radeon_reg.h"
  30. #include "radeon.h"
  31. #include "atom.h"
  32. #include <linux/slab.h>
  33. #include <linux/acpi.h>
  34. /*
  35. * BIOS.
  36. */
  37. /* If you boot an IGP board with a discrete card as the primary,
  38. * the IGP rom is not accessible via the rom bar as the IGP rom is
  39. * part of the system bios. On boot, the system bios puts a
  40. * copy of the igp rom at the start of vram if a discrete card is
  41. * present.
  42. */
  43. static bool igp_read_bios_from_vram(struct radeon_device *rdev)
  44. {
  45. uint8_t __iomem *bios;
  46. resource_size_t vram_base;
  47. resource_size_t size = 256 * 1024; /* ??? */
  48. if (!(rdev->flags & RADEON_IS_IGP))
  49. if (!radeon_card_posted(rdev))
  50. return false;
  51. rdev->bios = NULL;
  52. vram_base = pci_resource_start(rdev->pdev, 0);
  53. bios = ioremap(vram_base, size);
  54. if (!bios) {
  55. return false;
  56. }
  57. if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) {
  58. iounmap(bios);
  59. return false;
  60. }
  61. rdev->bios = kmalloc(size, GFP_KERNEL);
  62. if (rdev->bios == NULL) {
  63. iounmap(bios);
  64. return false;
  65. }
  66. memcpy_fromio(rdev->bios, bios, size);
  67. iounmap(bios);
  68. return true;
  69. }
  70. static bool radeon_read_bios(struct radeon_device *rdev)
  71. {
  72. uint8_t __iomem *bios, val1, val2;
  73. size_t size;
  74. rdev->bios = NULL;
  75. /* XXX: some cards may return 0 for rom size? ddx has a workaround */
  76. bios = pci_map_rom(rdev->pdev, &size);
  77. if (!bios) {
  78. return false;
  79. }
  80. val1 = readb(&bios[0]);
  81. val2 = readb(&bios[1]);
  82. if (size == 0 || val1 != 0x55 || val2 != 0xaa) {
  83. pci_unmap_rom(rdev->pdev, bios);
  84. return false;
  85. }
  86. rdev->bios = kzalloc(size, GFP_KERNEL);
  87. if (rdev->bios == NULL) {
  88. pci_unmap_rom(rdev->pdev, bios);
  89. return false;
  90. }
  91. memcpy_fromio(rdev->bios, bios, size);
  92. pci_unmap_rom(rdev->pdev, bios);
  93. return true;
  94. }
  95. static bool radeon_read_platform_bios(struct radeon_device *rdev)
  96. {
  97. uint8_t __iomem *bios;
  98. size_t size;
  99. rdev->bios = NULL;
  100. bios = pci_platform_rom(rdev->pdev, &size);
  101. if (!bios) {
  102. return false;
  103. }
  104. if (size == 0 || bios[0] != 0x55 || bios[1] != 0xaa) {
  105. return false;
  106. }
  107. rdev->bios = kmemdup(bios, size, GFP_KERNEL);
  108. if (rdev->bios == NULL) {
  109. return false;
  110. }
  111. return true;
  112. }
  113. #ifdef CONFIG_ACPI
  114. /* ATRM is used to get the BIOS on the discrete cards in
  115. * dual-gpu systems.
  116. */
  117. /* retrieve the ROM in 4k blocks */
  118. #define ATRM_BIOS_PAGE 4096
  119. /**
  120. * radeon_atrm_call - fetch a chunk of the vbios
  121. *
  122. * @atrm_handle: acpi ATRM handle
  123. * @bios: vbios image pointer
  124. * @offset: offset of vbios image data to fetch
  125. * @len: length of vbios image data to fetch
  126. *
  127. * Executes ATRM to fetch a chunk of the discrete
  128. * vbios image on PX systems (all asics).
  129. * Returns the length of the buffer fetched.
  130. */
  131. static int radeon_atrm_call(acpi_handle atrm_handle, uint8_t *bios,
  132. int offset, int len)
  133. {
  134. acpi_status status;
  135. union acpi_object atrm_arg_elements[2], *obj;
  136. struct acpi_object_list atrm_arg;
  137. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL};
  138. atrm_arg.count = 2;
  139. atrm_arg.pointer = &atrm_arg_elements[0];
  140. atrm_arg_elements[0].type = ACPI_TYPE_INTEGER;
  141. atrm_arg_elements[0].integer.value = offset;
  142. atrm_arg_elements[1].type = ACPI_TYPE_INTEGER;
  143. atrm_arg_elements[1].integer.value = len;
  144. status = acpi_evaluate_object(atrm_handle, NULL, &atrm_arg, &buffer);
  145. if (ACPI_FAILURE(status)) {
  146. printk("failed to evaluate ATRM got %s\n", acpi_format_exception(status));
  147. return -ENODEV;
  148. }
  149. obj = (union acpi_object *)buffer.pointer;
  150. memcpy(bios+offset, obj->buffer.pointer, obj->buffer.length);
  151. len = obj->buffer.length;
  152. kfree(buffer.pointer);
  153. return len;
  154. }
  155. static bool radeon_atrm_get_bios(struct radeon_device *rdev)
  156. {
  157. int ret;
  158. int size = 256 * 1024;
  159. int i;
  160. struct pci_dev *pdev = NULL;
  161. acpi_handle dhandle, atrm_handle;
  162. acpi_status status;
  163. bool found = false;
  164. /* ATRM is for the discrete card only */
  165. if (rdev->flags & RADEON_IS_IGP)
  166. return false;
  167. while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
  168. dhandle = ACPI_HANDLE(&pdev->dev);
  169. if (!dhandle)
  170. continue;
  171. status = acpi_get_handle(dhandle, "ATRM", &atrm_handle);
  172. if (!ACPI_FAILURE(status)) {
  173. found = true;
  174. break;
  175. }
  176. }
  177. if (!found) {
  178. while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) {
  179. dhandle = ACPI_HANDLE(&pdev->dev);
  180. if (!dhandle)
  181. continue;
  182. status = acpi_get_handle(dhandle, "ATRM", &atrm_handle);
  183. if (!ACPI_FAILURE(status)) {
  184. found = true;
  185. break;
  186. }
  187. }
  188. }
  189. if (!found)
  190. return false;
  191. rdev->bios = kmalloc(size, GFP_KERNEL);
  192. if (!rdev->bios) {
  193. DRM_ERROR("Unable to allocate bios\n");
  194. return false;
  195. }
  196. for (i = 0; i < size / ATRM_BIOS_PAGE; i++) {
  197. ret = radeon_atrm_call(atrm_handle,
  198. rdev->bios,
  199. (i * ATRM_BIOS_PAGE),
  200. ATRM_BIOS_PAGE);
  201. if (ret < ATRM_BIOS_PAGE)
  202. break;
  203. }
  204. if (i == 0 || rdev->bios[0] != 0x55 || rdev->bios[1] != 0xaa) {
  205. kfree(rdev->bios);
  206. return false;
  207. }
  208. return true;
  209. }
  210. #else
  211. static inline bool radeon_atrm_get_bios(struct radeon_device *rdev)
  212. {
  213. return false;
  214. }
  215. #endif
  216. static bool ni_read_disabled_bios(struct radeon_device *rdev)
  217. {
  218. u32 bus_cntl;
  219. u32 d1vga_control;
  220. u32 d2vga_control;
  221. u32 vga_render_control;
  222. u32 rom_cntl;
  223. bool r;
  224. bus_cntl = RREG32(R600_BUS_CNTL);
  225. d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
  226. d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
  227. vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
  228. rom_cntl = RREG32(R600_ROM_CNTL);
  229. /* enable the rom */
  230. WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS));
  231. if (!ASIC_IS_NODCE(rdev)) {
  232. /* Disable VGA mode */
  233. WREG32(AVIVO_D1VGA_CONTROL,
  234. (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
  235. AVIVO_DVGA_CONTROL_TIMING_SELECT)));
  236. WREG32(AVIVO_D2VGA_CONTROL,
  237. (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
  238. AVIVO_DVGA_CONTROL_TIMING_SELECT)));
  239. WREG32(AVIVO_VGA_RENDER_CONTROL,
  240. (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK));
  241. }
  242. WREG32(R600_ROM_CNTL, rom_cntl | R600_SCK_OVERWRITE);
  243. r = radeon_read_bios(rdev);
  244. /* restore regs */
  245. WREG32(R600_BUS_CNTL, bus_cntl);
  246. if (!ASIC_IS_NODCE(rdev)) {
  247. WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
  248. WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
  249. WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
  250. }
  251. WREG32(R600_ROM_CNTL, rom_cntl);
  252. return r;
  253. }
  254. static bool r700_read_disabled_bios(struct radeon_device *rdev)
  255. {
  256. uint32_t viph_control;
  257. uint32_t bus_cntl;
  258. uint32_t d1vga_control;
  259. uint32_t d2vga_control;
  260. uint32_t vga_render_control;
  261. uint32_t rom_cntl;
  262. uint32_t cg_spll_func_cntl = 0;
  263. uint32_t cg_spll_status;
  264. bool r;
  265. viph_control = RREG32(RADEON_VIPH_CONTROL);
  266. bus_cntl = RREG32(R600_BUS_CNTL);
  267. d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
  268. d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
  269. vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
  270. rom_cntl = RREG32(R600_ROM_CNTL);
  271. /* disable VIP */
  272. WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
  273. /* enable the rom */
  274. WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS));
  275. /* Disable VGA mode */
  276. WREG32(AVIVO_D1VGA_CONTROL,
  277. (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
  278. AVIVO_DVGA_CONTROL_TIMING_SELECT)));
  279. WREG32(AVIVO_D2VGA_CONTROL,
  280. (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
  281. AVIVO_DVGA_CONTROL_TIMING_SELECT)));
  282. WREG32(AVIVO_VGA_RENDER_CONTROL,
  283. (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK));
  284. if (rdev->family == CHIP_RV730) {
  285. cg_spll_func_cntl = RREG32(R600_CG_SPLL_FUNC_CNTL);
  286. /* enable bypass mode */
  287. WREG32(R600_CG_SPLL_FUNC_CNTL, (cg_spll_func_cntl |
  288. R600_SPLL_BYPASS_EN));
  289. /* wait for SPLL_CHG_STATUS to change to 1 */
  290. cg_spll_status = 0;
  291. while (!(cg_spll_status & R600_SPLL_CHG_STATUS))
  292. cg_spll_status = RREG32(R600_CG_SPLL_STATUS);
  293. WREG32(R600_ROM_CNTL, (rom_cntl & ~R600_SCK_OVERWRITE));
  294. } else
  295. WREG32(R600_ROM_CNTL, (rom_cntl | R600_SCK_OVERWRITE));
  296. r = radeon_read_bios(rdev);
  297. /* restore regs */
  298. if (rdev->family == CHIP_RV730) {
  299. WREG32(R600_CG_SPLL_FUNC_CNTL, cg_spll_func_cntl);
  300. /* wait for SPLL_CHG_STATUS to change to 1 */
  301. cg_spll_status = 0;
  302. while (!(cg_spll_status & R600_SPLL_CHG_STATUS))
  303. cg_spll_status = RREG32(R600_CG_SPLL_STATUS);
  304. }
  305. WREG32(RADEON_VIPH_CONTROL, viph_control);
  306. WREG32(R600_BUS_CNTL, bus_cntl);
  307. WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
  308. WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
  309. WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
  310. WREG32(R600_ROM_CNTL, rom_cntl);
  311. return r;
  312. }
  313. static bool r600_read_disabled_bios(struct radeon_device *rdev)
  314. {
  315. uint32_t viph_control;
  316. uint32_t bus_cntl;
  317. uint32_t d1vga_control;
  318. uint32_t d2vga_control;
  319. uint32_t vga_render_control;
  320. uint32_t rom_cntl;
  321. uint32_t general_pwrmgt;
  322. uint32_t low_vid_lower_gpio_cntl;
  323. uint32_t medium_vid_lower_gpio_cntl;
  324. uint32_t high_vid_lower_gpio_cntl;
  325. uint32_t ctxsw_vid_lower_gpio_cntl;
  326. uint32_t lower_gpio_enable;
  327. bool r;
  328. viph_control = RREG32(RADEON_VIPH_CONTROL);
  329. bus_cntl = RREG32(R600_BUS_CNTL);
  330. d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
  331. d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
  332. vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
  333. rom_cntl = RREG32(R600_ROM_CNTL);
  334. general_pwrmgt = RREG32(R600_GENERAL_PWRMGT);
  335. low_vid_lower_gpio_cntl = RREG32(R600_LOW_VID_LOWER_GPIO_CNTL);
  336. medium_vid_lower_gpio_cntl = RREG32(R600_MEDIUM_VID_LOWER_GPIO_CNTL);
  337. high_vid_lower_gpio_cntl = RREG32(R600_HIGH_VID_LOWER_GPIO_CNTL);
  338. ctxsw_vid_lower_gpio_cntl = RREG32(R600_CTXSW_VID_LOWER_GPIO_CNTL);
  339. lower_gpio_enable = RREG32(R600_LOWER_GPIO_ENABLE);
  340. /* disable VIP */
  341. WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
  342. /* enable the rom */
  343. WREG32(R600_BUS_CNTL, (bus_cntl & ~R600_BIOS_ROM_DIS));
  344. /* Disable VGA mode */
  345. WREG32(AVIVO_D1VGA_CONTROL,
  346. (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
  347. AVIVO_DVGA_CONTROL_TIMING_SELECT)));
  348. WREG32(AVIVO_D2VGA_CONTROL,
  349. (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
  350. AVIVO_DVGA_CONTROL_TIMING_SELECT)));
  351. WREG32(AVIVO_VGA_RENDER_CONTROL,
  352. (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK));
  353. WREG32(R600_ROM_CNTL,
  354. ((rom_cntl & ~R600_SCK_PRESCALE_CRYSTAL_CLK_MASK) |
  355. (1 << R600_SCK_PRESCALE_CRYSTAL_CLK_SHIFT) |
  356. R600_SCK_OVERWRITE));
  357. WREG32(R600_GENERAL_PWRMGT, (general_pwrmgt & ~R600_OPEN_DRAIN_PADS));
  358. WREG32(R600_LOW_VID_LOWER_GPIO_CNTL,
  359. (low_vid_lower_gpio_cntl & ~0x400));
  360. WREG32(R600_MEDIUM_VID_LOWER_GPIO_CNTL,
  361. (medium_vid_lower_gpio_cntl & ~0x400));
  362. WREG32(R600_HIGH_VID_LOWER_GPIO_CNTL,
  363. (high_vid_lower_gpio_cntl & ~0x400));
  364. WREG32(R600_CTXSW_VID_LOWER_GPIO_CNTL,
  365. (ctxsw_vid_lower_gpio_cntl & ~0x400));
  366. WREG32(R600_LOWER_GPIO_ENABLE, (lower_gpio_enable | 0x400));
  367. r = radeon_read_bios(rdev);
  368. /* restore regs */
  369. WREG32(RADEON_VIPH_CONTROL, viph_control);
  370. WREG32(R600_BUS_CNTL, bus_cntl);
  371. WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
  372. WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
  373. WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
  374. WREG32(R600_ROM_CNTL, rom_cntl);
  375. WREG32(R600_GENERAL_PWRMGT, general_pwrmgt);
  376. WREG32(R600_LOW_VID_LOWER_GPIO_CNTL, low_vid_lower_gpio_cntl);
  377. WREG32(R600_MEDIUM_VID_LOWER_GPIO_CNTL, medium_vid_lower_gpio_cntl);
  378. WREG32(R600_HIGH_VID_LOWER_GPIO_CNTL, high_vid_lower_gpio_cntl);
  379. WREG32(R600_CTXSW_VID_LOWER_GPIO_CNTL, ctxsw_vid_lower_gpio_cntl);
  380. WREG32(R600_LOWER_GPIO_ENABLE, lower_gpio_enable);
  381. return r;
  382. }
  383. static bool avivo_read_disabled_bios(struct radeon_device *rdev)
  384. {
  385. uint32_t seprom_cntl1;
  386. uint32_t viph_control;
  387. uint32_t bus_cntl;
  388. uint32_t d1vga_control;
  389. uint32_t d2vga_control;
  390. uint32_t vga_render_control;
  391. uint32_t gpiopad_a;
  392. uint32_t gpiopad_en;
  393. uint32_t gpiopad_mask;
  394. bool r;
  395. seprom_cntl1 = RREG32(RADEON_SEPROM_CNTL1);
  396. viph_control = RREG32(RADEON_VIPH_CONTROL);
  397. bus_cntl = RREG32(RV370_BUS_CNTL);
  398. d1vga_control = RREG32(AVIVO_D1VGA_CONTROL);
  399. d2vga_control = RREG32(AVIVO_D2VGA_CONTROL);
  400. vga_render_control = RREG32(AVIVO_VGA_RENDER_CONTROL);
  401. gpiopad_a = RREG32(RADEON_GPIOPAD_A);
  402. gpiopad_en = RREG32(RADEON_GPIOPAD_EN);
  403. gpiopad_mask = RREG32(RADEON_GPIOPAD_MASK);
  404. WREG32(RADEON_SEPROM_CNTL1,
  405. ((seprom_cntl1 & ~RADEON_SCK_PRESCALE_MASK) |
  406. (0xc << RADEON_SCK_PRESCALE_SHIFT)));
  407. WREG32(RADEON_GPIOPAD_A, 0);
  408. WREG32(RADEON_GPIOPAD_EN, 0);
  409. WREG32(RADEON_GPIOPAD_MASK, 0);
  410. /* disable VIP */
  411. WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
  412. /* enable the rom */
  413. WREG32(RV370_BUS_CNTL, (bus_cntl & ~RV370_BUS_BIOS_DIS_ROM));
  414. /* Disable VGA mode */
  415. WREG32(AVIVO_D1VGA_CONTROL,
  416. (d1vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
  417. AVIVO_DVGA_CONTROL_TIMING_SELECT)));
  418. WREG32(AVIVO_D2VGA_CONTROL,
  419. (d2vga_control & ~(AVIVO_DVGA_CONTROL_MODE_ENABLE |
  420. AVIVO_DVGA_CONTROL_TIMING_SELECT)));
  421. WREG32(AVIVO_VGA_RENDER_CONTROL,
  422. (vga_render_control & ~AVIVO_VGA_VSTATUS_CNTL_MASK));
  423. r = radeon_read_bios(rdev);
  424. /* restore regs */
  425. WREG32(RADEON_SEPROM_CNTL1, seprom_cntl1);
  426. WREG32(RADEON_VIPH_CONTROL, viph_control);
  427. WREG32(RV370_BUS_CNTL, bus_cntl);
  428. WREG32(AVIVO_D1VGA_CONTROL, d1vga_control);
  429. WREG32(AVIVO_D2VGA_CONTROL, d2vga_control);
  430. WREG32(AVIVO_VGA_RENDER_CONTROL, vga_render_control);
  431. WREG32(RADEON_GPIOPAD_A, gpiopad_a);
  432. WREG32(RADEON_GPIOPAD_EN, gpiopad_en);
  433. WREG32(RADEON_GPIOPAD_MASK, gpiopad_mask);
  434. return r;
  435. }
  436. static bool legacy_read_disabled_bios(struct radeon_device *rdev)
  437. {
  438. uint32_t seprom_cntl1;
  439. uint32_t viph_control;
  440. uint32_t bus_cntl;
  441. uint32_t crtc_gen_cntl;
  442. uint32_t crtc2_gen_cntl;
  443. uint32_t crtc_ext_cntl;
  444. uint32_t fp2_gen_cntl;
  445. bool r;
  446. seprom_cntl1 = RREG32(RADEON_SEPROM_CNTL1);
  447. viph_control = RREG32(RADEON_VIPH_CONTROL);
  448. if (rdev->flags & RADEON_IS_PCIE)
  449. bus_cntl = RREG32(RV370_BUS_CNTL);
  450. else
  451. bus_cntl = RREG32(RADEON_BUS_CNTL);
  452. crtc_gen_cntl = RREG32(RADEON_CRTC_GEN_CNTL);
  453. crtc2_gen_cntl = 0;
  454. crtc_ext_cntl = RREG32(RADEON_CRTC_EXT_CNTL);
  455. fp2_gen_cntl = 0;
  456. if (rdev->ddev->pdev->device == PCI_DEVICE_ID_ATI_RADEON_QY) {
  457. fp2_gen_cntl = RREG32(RADEON_FP2_GEN_CNTL);
  458. }
  459. if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
  460. crtc2_gen_cntl = RREG32(RADEON_CRTC2_GEN_CNTL);
  461. }
  462. WREG32(RADEON_SEPROM_CNTL1,
  463. ((seprom_cntl1 & ~RADEON_SCK_PRESCALE_MASK) |
  464. (0xc << RADEON_SCK_PRESCALE_SHIFT)));
  465. /* disable VIP */
  466. WREG32(RADEON_VIPH_CONTROL, (viph_control & ~RADEON_VIPH_EN));
  467. /* enable the rom */
  468. if (rdev->flags & RADEON_IS_PCIE)
  469. WREG32(RV370_BUS_CNTL, (bus_cntl & ~RV370_BUS_BIOS_DIS_ROM));
  470. else
  471. WREG32(RADEON_BUS_CNTL, (bus_cntl & ~RADEON_BUS_BIOS_DIS_ROM));
  472. /* Turn off mem requests and CRTC for both controllers */
  473. WREG32(RADEON_CRTC_GEN_CNTL,
  474. ((crtc_gen_cntl & ~RADEON_CRTC_EN) |
  475. (RADEON_CRTC_DISP_REQ_EN_B |
  476. RADEON_CRTC_EXT_DISP_EN)));
  477. if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
  478. WREG32(RADEON_CRTC2_GEN_CNTL,
  479. ((crtc2_gen_cntl & ~RADEON_CRTC2_EN) |
  480. RADEON_CRTC2_DISP_REQ_EN_B));
  481. }
  482. /* Turn off CRTC */
  483. WREG32(RADEON_CRTC_EXT_CNTL,
  484. ((crtc_ext_cntl & ~RADEON_CRTC_CRT_ON) |
  485. (RADEON_CRTC_SYNC_TRISTAT |
  486. RADEON_CRTC_DISPLAY_DIS)));
  487. if (rdev->ddev->pdev->device == PCI_DEVICE_ID_ATI_RADEON_QY) {
  488. WREG32(RADEON_FP2_GEN_CNTL, (fp2_gen_cntl & ~RADEON_FP2_ON));
  489. }
  490. r = radeon_read_bios(rdev);
  491. /* restore regs */
  492. WREG32(RADEON_SEPROM_CNTL1, seprom_cntl1);
  493. WREG32(RADEON_VIPH_CONTROL, viph_control);
  494. if (rdev->flags & RADEON_IS_PCIE)
  495. WREG32(RV370_BUS_CNTL, bus_cntl);
  496. else
  497. WREG32(RADEON_BUS_CNTL, bus_cntl);
  498. WREG32(RADEON_CRTC_GEN_CNTL, crtc_gen_cntl);
  499. if (!(rdev->flags & RADEON_SINGLE_CRTC)) {
  500. WREG32(RADEON_CRTC2_GEN_CNTL, crtc2_gen_cntl);
  501. }
  502. WREG32(RADEON_CRTC_EXT_CNTL, crtc_ext_cntl);
  503. if (rdev->ddev->pdev->device == PCI_DEVICE_ID_ATI_RADEON_QY) {
  504. WREG32(RADEON_FP2_GEN_CNTL, fp2_gen_cntl);
  505. }
  506. return r;
  507. }
  508. static bool radeon_read_disabled_bios(struct radeon_device *rdev)
  509. {
  510. if (rdev->flags & RADEON_IS_IGP)
  511. return igp_read_bios_from_vram(rdev);
  512. else if (rdev->family >= CHIP_BARTS)
  513. return ni_read_disabled_bios(rdev);
  514. else if (rdev->family >= CHIP_RV770)
  515. return r700_read_disabled_bios(rdev);
  516. else if (rdev->family >= CHIP_R600)
  517. return r600_read_disabled_bios(rdev);
  518. else if (rdev->family >= CHIP_RS600)
  519. return avivo_read_disabled_bios(rdev);
  520. else
  521. return legacy_read_disabled_bios(rdev);
  522. }
  523. #ifdef CONFIG_ACPI
  524. static bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
  525. {
  526. bool ret = false;
  527. struct acpi_table_header *hdr;
  528. acpi_size tbl_size;
  529. UEFI_ACPI_VFCT *vfct;
  530. GOP_VBIOS_CONTENT *vbios;
  531. VFCT_IMAGE_HEADER *vhdr;
  532. if (!ACPI_SUCCESS(acpi_get_table_with_size("VFCT", 1, &hdr, &tbl_size)))
  533. return false;
  534. if (tbl_size < sizeof(UEFI_ACPI_VFCT)) {
  535. DRM_ERROR("ACPI VFCT table present but broken (too short #1)\n");
  536. goto out_unmap;
  537. }
  538. vfct = (UEFI_ACPI_VFCT *)hdr;
  539. if (vfct->VBIOSImageOffset + sizeof(VFCT_IMAGE_HEADER) > tbl_size) {
  540. DRM_ERROR("ACPI VFCT table present but broken (too short #2)\n");
  541. goto out_unmap;
  542. }
  543. vbios = (GOP_VBIOS_CONTENT *)((char *)hdr + vfct->VBIOSImageOffset);
  544. vhdr = &vbios->VbiosHeader;
  545. DRM_INFO("ACPI VFCT contains a BIOS for %02x:%02x.%d %04x:%04x, size %d\n",
  546. vhdr->PCIBus, vhdr->PCIDevice, vhdr->PCIFunction,
  547. vhdr->VendorID, vhdr->DeviceID, vhdr->ImageLength);
  548. if (vhdr->PCIBus != rdev->pdev->bus->number ||
  549. vhdr->PCIDevice != PCI_SLOT(rdev->pdev->devfn) ||
  550. vhdr->PCIFunction != PCI_FUNC(rdev->pdev->devfn) ||
  551. vhdr->VendorID != rdev->pdev->vendor ||
  552. vhdr->DeviceID != rdev->pdev->device) {
  553. DRM_INFO("ACPI VFCT table is not for this card\n");
  554. goto out_unmap;
  555. }
  556. if (vfct->VBIOSImageOffset + sizeof(VFCT_IMAGE_HEADER) + vhdr->ImageLength > tbl_size) {
  557. DRM_ERROR("ACPI VFCT image truncated\n");
  558. goto out_unmap;
  559. }
  560. rdev->bios = kmemdup(&vbios->VbiosContent, vhdr->ImageLength, GFP_KERNEL);
  561. ret = !!rdev->bios;
  562. out_unmap:
  563. return ret;
  564. }
  565. #else
  566. static inline bool radeon_acpi_vfct_bios(struct radeon_device *rdev)
  567. {
  568. return false;
  569. }
  570. #endif
  571. bool radeon_get_bios(struct radeon_device *rdev)
  572. {
  573. bool r;
  574. uint16_t tmp;
  575. r = radeon_atrm_get_bios(rdev);
  576. if (r == false)
  577. r = radeon_acpi_vfct_bios(rdev);
  578. if (r == false)
  579. r = igp_read_bios_from_vram(rdev);
  580. if (r == false)
  581. r = radeon_read_bios(rdev);
  582. if (r == false)
  583. r = radeon_read_disabled_bios(rdev);
  584. if (r == false)
  585. r = radeon_read_platform_bios(rdev);
  586. if (r == false || rdev->bios == NULL) {
  587. DRM_ERROR("Unable to locate a BIOS ROM\n");
  588. rdev->bios = NULL;
  589. return false;
  590. }
  591. if (rdev->bios[0] != 0x55 || rdev->bios[1] != 0xaa) {
  592. printk("BIOS signature incorrect %x %x\n", rdev->bios[0], rdev->bios[1]);
  593. goto free_bios;
  594. }
  595. tmp = RBIOS16(0x18);
  596. if (RBIOS8(tmp + 0x14) != 0x0) {
  597. DRM_INFO("Not an x86 BIOS ROM, not using.\n");
  598. goto free_bios;
  599. }
  600. rdev->bios_header_start = RBIOS16(0x48);
  601. if (!rdev->bios_header_start) {
  602. goto free_bios;
  603. }
  604. tmp = rdev->bios_header_start + 4;
  605. if (!memcmp(rdev->bios + tmp, "ATOM", 4) ||
  606. !memcmp(rdev->bios + tmp, "MOTA", 4)) {
  607. rdev->is_atom_bios = true;
  608. } else {
  609. rdev->is_atom_bios = false;
  610. }
  611. DRM_DEBUG("%sBIOS detected\n", rdev->is_atom_bios ? "ATOM" : "COM");
  612. return true;
  613. free_bios:
  614. kfree(rdev->bios);
  615. rdev->bios = NULL;
  616. return false;
  617. }