radeon_device.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859
  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 <linux/console.h>
  29. #include <linux/slab.h>
  30. #include <drm/drmP.h>
  31. #include <drm/drm_crtc_helper.h>
  32. #include <drm/radeon_drm.h>
  33. #include <linux/vgaarb.h>
  34. #include <linux/vga_switcheroo.h>
  35. #include <linux/efi.h>
  36. #include "radeon_reg.h"
  37. #include "radeon.h"
  38. #include "atom.h"
  39. static const char radeon_family_name[][16] = {
  40. "R100",
  41. "RV100",
  42. "RS100",
  43. "RV200",
  44. "RS200",
  45. "R200",
  46. "RV250",
  47. "RS300",
  48. "RV280",
  49. "R300",
  50. "R350",
  51. "RV350",
  52. "RV380",
  53. "R420",
  54. "R423",
  55. "RV410",
  56. "RS400",
  57. "RS480",
  58. "RS600",
  59. "RS690",
  60. "RS740",
  61. "RV515",
  62. "R520",
  63. "RV530",
  64. "RV560",
  65. "RV570",
  66. "R580",
  67. "R600",
  68. "RV610",
  69. "RV630",
  70. "RV670",
  71. "RV620",
  72. "RV635",
  73. "RS780",
  74. "RS880",
  75. "RV770",
  76. "RV730",
  77. "RV710",
  78. "RV740",
  79. "CEDAR",
  80. "REDWOOD",
  81. "JUNIPER",
  82. "CYPRESS",
  83. "HEMLOCK",
  84. "PALM",
  85. "SUMO",
  86. "SUMO2",
  87. "BARTS",
  88. "TURKS",
  89. "CAICOS",
  90. "CAYMAN",
  91. "ARUBA",
  92. "TAHITI",
  93. "PITCAIRN",
  94. "VERDE",
  95. "OLAND",
  96. "HAINAN",
  97. "BONAIRE",
  98. "KAVERI",
  99. "KABINI",
  100. "HAWAII",
  101. "MULLINS",
  102. "LAST",
  103. };
  104. #define RADEON_PX_QUIRK_DISABLE_PX (1 << 0)
  105. #define RADEON_PX_QUIRK_LONG_WAKEUP (1 << 1)
  106. struct radeon_px_quirk {
  107. u32 chip_vendor;
  108. u32 chip_device;
  109. u32 subsys_vendor;
  110. u32 subsys_device;
  111. u32 px_quirk_flags;
  112. };
  113. static struct radeon_px_quirk radeon_px_quirk_list[] = {
  114. /* Acer aspire 5560g (CPU: AMD A4-3305M; GPU: AMD Radeon HD 6480g + 7470m)
  115. * https://bugzilla.kernel.org/show_bug.cgi?id=74551
  116. */
  117. { PCI_VENDOR_ID_ATI, 0x6760, 0x1025, 0x0672, RADEON_PX_QUIRK_DISABLE_PX },
  118. /* Asus K73TA laptop with AMD A6-3400M APU and Radeon 6550 GPU
  119. * https://bugzilla.kernel.org/show_bug.cgi?id=51381
  120. */
  121. { PCI_VENDOR_ID_ATI, 0x6741, 0x1043, 0x108c, RADEON_PX_QUIRK_DISABLE_PX },
  122. /* Asus K53TK laptop with AMD A6-3420M APU and Radeon 7670m GPU
  123. * https://bugzilla.kernel.org/show_bug.cgi?id=51381
  124. */
  125. { PCI_VENDOR_ID_ATI, 0x6840, 0x1043, 0x2122, RADEON_PX_QUIRK_DISABLE_PX },
  126. /* macbook pro 8.2 */
  127. { PCI_VENDOR_ID_ATI, 0x6741, PCI_VENDOR_ID_APPLE, 0x00e2, RADEON_PX_QUIRK_LONG_WAKEUP },
  128. { 0, 0, 0, 0, 0 },
  129. };
  130. bool radeon_is_px(struct drm_device *dev)
  131. {
  132. struct radeon_device *rdev = dev->dev_private;
  133. if (rdev->flags & RADEON_IS_PX)
  134. return true;
  135. return false;
  136. }
  137. static void radeon_device_handle_px_quirks(struct radeon_device *rdev)
  138. {
  139. struct radeon_px_quirk *p = radeon_px_quirk_list;
  140. /* Apply PX quirks */
  141. while (p && p->chip_device != 0) {
  142. if (rdev->pdev->vendor == p->chip_vendor &&
  143. rdev->pdev->device == p->chip_device &&
  144. rdev->pdev->subsystem_vendor == p->subsys_vendor &&
  145. rdev->pdev->subsystem_device == p->subsys_device) {
  146. rdev->px_quirk_flags = p->px_quirk_flags;
  147. break;
  148. }
  149. ++p;
  150. }
  151. if (rdev->px_quirk_flags & RADEON_PX_QUIRK_DISABLE_PX)
  152. rdev->flags &= ~RADEON_IS_PX;
  153. }
  154. /**
  155. * radeon_program_register_sequence - program an array of registers.
  156. *
  157. * @rdev: radeon_device pointer
  158. * @registers: pointer to the register array
  159. * @array_size: size of the register array
  160. *
  161. * Programs an array or registers with and and or masks.
  162. * This is a helper for setting golden registers.
  163. */
  164. void radeon_program_register_sequence(struct radeon_device *rdev,
  165. const u32 *registers,
  166. const u32 array_size)
  167. {
  168. u32 tmp, reg, and_mask, or_mask;
  169. int i;
  170. if (array_size % 3)
  171. return;
  172. for (i = 0; i < array_size; i +=3) {
  173. reg = registers[i + 0];
  174. and_mask = registers[i + 1];
  175. or_mask = registers[i + 2];
  176. if (and_mask == 0xffffffff) {
  177. tmp = or_mask;
  178. } else {
  179. tmp = RREG32(reg);
  180. tmp &= ~and_mask;
  181. tmp |= or_mask;
  182. }
  183. WREG32(reg, tmp);
  184. }
  185. }
  186. void radeon_pci_config_reset(struct radeon_device *rdev)
  187. {
  188. pci_write_config_dword(rdev->pdev, 0x7c, RADEON_ASIC_RESET_DATA);
  189. }
  190. /**
  191. * radeon_surface_init - Clear GPU surface registers.
  192. *
  193. * @rdev: radeon_device pointer
  194. *
  195. * Clear GPU surface registers (r1xx-r5xx).
  196. */
  197. void radeon_surface_init(struct radeon_device *rdev)
  198. {
  199. /* FIXME: check this out */
  200. if (rdev->family < CHIP_R600) {
  201. int i;
  202. for (i = 0; i < RADEON_GEM_MAX_SURFACES; i++) {
  203. if (rdev->surface_regs[i].bo)
  204. radeon_bo_get_surface_reg(rdev->surface_regs[i].bo);
  205. else
  206. radeon_clear_surface_reg(rdev, i);
  207. }
  208. /* enable surfaces */
  209. WREG32(RADEON_SURFACE_CNTL, 0);
  210. }
  211. }
  212. /*
  213. * GPU scratch registers helpers function.
  214. */
  215. /**
  216. * radeon_scratch_init - Init scratch register driver information.
  217. *
  218. * @rdev: radeon_device pointer
  219. *
  220. * Init CP scratch register driver information (r1xx-r5xx)
  221. */
  222. void radeon_scratch_init(struct radeon_device *rdev)
  223. {
  224. int i;
  225. /* FIXME: check this out */
  226. if (rdev->family < CHIP_R300) {
  227. rdev->scratch.num_reg = 5;
  228. } else {
  229. rdev->scratch.num_reg = 7;
  230. }
  231. rdev->scratch.reg_base = RADEON_SCRATCH_REG0;
  232. for (i = 0; i < rdev->scratch.num_reg; i++) {
  233. rdev->scratch.free[i] = true;
  234. rdev->scratch.reg[i] = rdev->scratch.reg_base + (i * 4);
  235. }
  236. }
  237. /**
  238. * radeon_scratch_get - Allocate a scratch register
  239. *
  240. * @rdev: radeon_device pointer
  241. * @reg: scratch register mmio offset
  242. *
  243. * Allocate a CP scratch register for use by the driver (all asics).
  244. * Returns 0 on success or -EINVAL on failure.
  245. */
  246. int radeon_scratch_get(struct radeon_device *rdev, uint32_t *reg)
  247. {
  248. int i;
  249. for (i = 0; i < rdev->scratch.num_reg; i++) {
  250. if (rdev->scratch.free[i]) {
  251. rdev->scratch.free[i] = false;
  252. *reg = rdev->scratch.reg[i];
  253. return 0;
  254. }
  255. }
  256. return -EINVAL;
  257. }
  258. /**
  259. * radeon_scratch_free - Free a scratch register
  260. *
  261. * @rdev: radeon_device pointer
  262. * @reg: scratch register mmio offset
  263. *
  264. * Free a CP scratch register allocated for use by the driver (all asics)
  265. */
  266. void radeon_scratch_free(struct radeon_device *rdev, uint32_t reg)
  267. {
  268. int i;
  269. for (i = 0; i < rdev->scratch.num_reg; i++) {
  270. if (rdev->scratch.reg[i] == reg) {
  271. rdev->scratch.free[i] = true;
  272. return;
  273. }
  274. }
  275. }
  276. /*
  277. * GPU doorbell aperture helpers function.
  278. */
  279. /**
  280. * radeon_doorbell_init - Init doorbell driver information.
  281. *
  282. * @rdev: radeon_device pointer
  283. *
  284. * Init doorbell driver information (CIK)
  285. * Returns 0 on success, error on failure.
  286. */
  287. static int radeon_doorbell_init(struct radeon_device *rdev)
  288. {
  289. /* doorbell bar mapping */
  290. rdev->doorbell.base = pci_resource_start(rdev->pdev, 2);
  291. rdev->doorbell.size = pci_resource_len(rdev->pdev, 2);
  292. rdev->doorbell.num_doorbells = min_t(u32, rdev->doorbell.size / sizeof(u32), RADEON_MAX_DOORBELLS);
  293. if (rdev->doorbell.num_doorbells == 0)
  294. return -EINVAL;
  295. rdev->doorbell.ptr = ioremap(rdev->doorbell.base, rdev->doorbell.num_doorbells * sizeof(u32));
  296. if (rdev->doorbell.ptr == NULL) {
  297. return -ENOMEM;
  298. }
  299. DRM_INFO("doorbell mmio base: 0x%08X\n", (uint32_t)rdev->doorbell.base);
  300. DRM_INFO("doorbell mmio size: %u\n", (unsigned)rdev->doorbell.size);
  301. memset(&rdev->doorbell.used, 0, sizeof(rdev->doorbell.used));
  302. return 0;
  303. }
  304. /**
  305. * radeon_doorbell_fini - Tear down doorbell driver information.
  306. *
  307. * @rdev: radeon_device pointer
  308. *
  309. * Tear down doorbell driver information (CIK)
  310. */
  311. static void radeon_doorbell_fini(struct radeon_device *rdev)
  312. {
  313. iounmap(rdev->doorbell.ptr);
  314. rdev->doorbell.ptr = NULL;
  315. }
  316. /**
  317. * radeon_doorbell_get - Allocate a doorbell entry
  318. *
  319. * @rdev: radeon_device pointer
  320. * @doorbell: doorbell index
  321. *
  322. * Allocate a doorbell for use by the driver (all asics).
  323. * Returns 0 on success or -EINVAL on failure.
  324. */
  325. int radeon_doorbell_get(struct radeon_device *rdev, u32 *doorbell)
  326. {
  327. unsigned long offset = find_first_zero_bit(rdev->doorbell.used, rdev->doorbell.num_doorbells);
  328. if (offset < rdev->doorbell.num_doorbells) {
  329. __set_bit(offset, rdev->doorbell.used);
  330. *doorbell = offset;
  331. return 0;
  332. } else {
  333. return -EINVAL;
  334. }
  335. }
  336. /**
  337. * radeon_doorbell_free - Free a doorbell entry
  338. *
  339. * @rdev: radeon_device pointer
  340. * @doorbell: doorbell index
  341. *
  342. * Free a doorbell allocated for use by the driver (all asics)
  343. */
  344. void radeon_doorbell_free(struct radeon_device *rdev, u32 doorbell)
  345. {
  346. if (doorbell < rdev->doorbell.num_doorbells)
  347. __clear_bit(doorbell, rdev->doorbell.used);
  348. }
  349. /*
  350. * radeon_wb_*()
  351. * Writeback is the the method by which the the GPU updates special pages
  352. * in memory with the status of certain GPU events (fences, ring pointers,
  353. * etc.).
  354. */
  355. /**
  356. * radeon_wb_disable - Disable Writeback
  357. *
  358. * @rdev: radeon_device pointer
  359. *
  360. * Disables Writeback (all asics). Used for suspend.
  361. */
  362. void radeon_wb_disable(struct radeon_device *rdev)
  363. {
  364. rdev->wb.enabled = false;
  365. }
  366. /**
  367. * radeon_wb_fini - Disable Writeback and free memory
  368. *
  369. * @rdev: radeon_device pointer
  370. *
  371. * Disables Writeback and frees the Writeback memory (all asics).
  372. * Used at driver shutdown.
  373. */
  374. void radeon_wb_fini(struct radeon_device *rdev)
  375. {
  376. radeon_wb_disable(rdev);
  377. if (rdev->wb.wb_obj) {
  378. if (!radeon_bo_reserve(rdev->wb.wb_obj, false)) {
  379. radeon_bo_kunmap(rdev->wb.wb_obj);
  380. radeon_bo_unpin(rdev->wb.wb_obj);
  381. radeon_bo_unreserve(rdev->wb.wb_obj);
  382. }
  383. radeon_bo_unref(&rdev->wb.wb_obj);
  384. rdev->wb.wb = NULL;
  385. rdev->wb.wb_obj = NULL;
  386. }
  387. }
  388. /**
  389. * radeon_wb_init- Init Writeback driver info and allocate memory
  390. *
  391. * @rdev: radeon_device pointer
  392. *
  393. * Disables Writeback and frees the Writeback memory (all asics).
  394. * Used at driver startup.
  395. * Returns 0 on success or an -error on failure.
  396. */
  397. int radeon_wb_init(struct radeon_device *rdev)
  398. {
  399. int r;
  400. if (rdev->wb.wb_obj == NULL) {
  401. r = radeon_bo_create(rdev, RADEON_GPU_PAGE_SIZE, PAGE_SIZE, true,
  402. RADEON_GEM_DOMAIN_GTT, 0, NULL, NULL,
  403. &rdev->wb.wb_obj);
  404. if (r) {
  405. dev_warn(rdev->dev, "(%d) create WB bo failed\n", r);
  406. return r;
  407. }
  408. r = radeon_bo_reserve(rdev->wb.wb_obj, false);
  409. if (unlikely(r != 0)) {
  410. radeon_wb_fini(rdev);
  411. return r;
  412. }
  413. r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT,
  414. &rdev->wb.gpu_addr);
  415. if (r) {
  416. radeon_bo_unreserve(rdev->wb.wb_obj);
  417. dev_warn(rdev->dev, "(%d) pin WB bo failed\n", r);
  418. radeon_wb_fini(rdev);
  419. return r;
  420. }
  421. r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb);
  422. radeon_bo_unreserve(rdev->wb.wb_obj);
  423. if (r) {
  424. dev_warn(rdev->dev, "(%d) map WB bo failed\n", r);
  425. radeon_wb_fini(rdev);
  426. return r;
  427. }
  428. }
  429. /* clear wb memory */
  430. memset((char *)rdev->wb.wb, 0, RADEON_GPU_PAGE_SIZE);
  431. /* disable event_write fences */
  432. rdev->wb.use_event = false;
  433. /* disabled via module param */
  434. if (radeon_no_wb == 1) {
  435. rdev->wb.enabled = false;
  436. } else {
  437. if (rdev->flags & RADEON_IS_AGP) {
  438. /* often unreliable on AGP */
  439. rdev->wb.enabled = false;
  440. } else if (rdev->family < CHIP_R300) {
  441. /* often unreliable on pre-r300 */
  442. rdev->wb.enabled = false;
  443. } else {
  444. rdev->wb.enabled = true;
  445. /* event_write fences are only available on r600+ */
  446. if (rdev->family >= CHIP_R600) {
  447. rdev->wb.use_event = true;
  448. }
  449. }
  450. }
  451. /* always use writeback/events on NI, APUs */
  452. if (rdev->family >= CHIP_PALM) {
  453. rdev->wb.enabled = true;
  454. rdev->wb.use_event = true;
  455. }
  456. dev_info(rdev->dev, "WB %sabled\n", rdev->wb.enabled ? "en" : "dis");
  457. return 0;
  458. }
  459. /**
  460. * radeon_vram_location - try to find VRAM location
  461. * @rdev: radeon device structure holding all necessary informations
  462. * @mc: memory controller structure holding memory informations
  463. * @base: base address at which to put VRAM
  464. *
  465. * Function will place try to place VRAM at base address provided
  466. * as parameter (which is so far either PCI aperture address or
  467. * for IGP TOM base address).
  468. *
  469. * If there is not enough space to fit the unvisible VRAM in the 32bits
  470. * address space then we limit the VRAM size to the aperture.
  471. *
  472. * If we are using AGP and if the AGP aperture doesn't allow us to have
  473. * room for all the VRAM than we restrict the VRAM to the PCI aperture
  474. * size and print a warning.
  475. *
  476. * This function will never fails, worst case are limiting VRAM.
  477. *
  478. * Note: GTT start, end, size should be initialized before calling this
  479. * function on AGP platform.
  480. *
  481. * Note: We don't explicitly enforce VRAM start to be aligned on VRAM size,
  482. * this shouldn't be a problem as we are using the PCI aperture as a reference.
  483. * Otherwise this would be needed for rv280, all r3xx, and all r4xx, but
  484. * not IGP.
  485. *
  486. * Note: we use mc_vram_size as on some board we need to program the mc to
  487. * cover the whole aperture even if VRAM size is inferior to aperture size
  488. * Novell bug 204882 + along with lots of ubuntu ones
  489. *
  490. * Note: when limiting vram it's safe to overwritte real_vram_size because
  491. * we are not in case where real_vram_size is inferior to mc_vram_size (ie
  492. * note afected by bogus hw of Novell bug 204882 + along with lots of ubuntu
  493. * ones)
  494. *
  495. * Note: IGP TOM addr should be the same as the aperture addr, we don't
  496. * explicitly check for that thought.
  497. *
  498. * FIXME: when reducing VRAM size align new size on power of 2.
  499. */
  500. void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base)
  501. {
  502. uint64_t limit = (uint64_t)radeon_vram_limit << 20;
  503. mc->vram_start = base;
  504. if (mc->mc_vram_size > (rdev->mc.mc_mask - base + 1)) {
  505. dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n");
  506. mc->real_vram_size = mc->aper_size;
  507. mc->mc_vram_size = mc->aper_size;
  508. }
  509. mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
  510. if (rdev->flags & RADEON_IS_AGP && mc->vram_end > mc->gtt_start && mc->vram_start <= mc->gtt_end) {
  511. dev_warn(rdev->dev, "limiting VRAM to PCI aperture size\n");
  512. mc->real_vram_size = mc->aper_size;
  513. mc->mc_vram_size = mc->aper_size;
  514. }
  515. mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
  516. if (limit && limit < mc->real_vram_size)
  517. mc->real_vram_size = limit;
  518. dev_info(rdev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n",
  519. mc->mc_vram_size >> 20, mc->vram_start,
  520. mc->vram_end, mc->real_vram_size >> 20);
  521. }
  522. /**
  523. * radeon_gtt_location - try to find GTT location
  524. * @rdev: radeon device structure holding all necessary informations
  525. * @mc: memory controller structure holding memory informations
  526. *
  527. * Function will place try to place GTT before or after VRAM.
  528. *
  529. * If GTT size is bigger than space left then we ajust GTT size.
  530. * Thus function will never fails.
  531. *
  532. * FIXME: when reducing GTT size align new size on power of 2.
  533. */
  534. void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
  535. {
  536. u64 size_af, size_bf;
  537. size_af = ((rdev->mc.mc_mask - mc->vram_end) + mc->gtt_base_align) & ~mc->gtt_base_align;
  538. size_bf = mc->vram_start & ~mc->gtt_base_align;
  539. if (size_bf > size_af) {
  540. if (mc->gtt_size > size_bf) {
  541. dev_warn(rdev->dev, "limiting GTT\n");
  542. mc->gtt_size = size_bf;
  543. }
  544. mc->gtt_start = (mc->vram_start & ~mc->gtt_base_align) - mc->gtt_size;
  545. } else {
  546. if (mc->gtt_size > size_af) {
  547. dev_warn(rdev->dev, "limiting GTT\n");
  548. mc->gtt_size = size_af;
  549. }
  550. mc->gtt_start = (mc->vram_end + 1 + mc->gtt_base_align) & ~mc->gtt_base_align;
  551. }
  552. mc->gtt_end = mc->gtt_start + mc->gtt_size - 1;
  553. dev_info(rdev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n",
  554. mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end);
  555. }
  556. /*
  557. * GPU helpers function.
  558. */
  559. /**
  560. * radeon_card_posted - check if the hw has already been initialized
  561. *
  562. * @rdev: radeon_device pointer
  563. *
  564. * Check if the asic has been initialized (all asics).
  565. * Used at driver startup.
  566. * Returns true if initialized or false if not.
  567. */
  568. bool radeon_card_posted(struct radeon_device *rdev)
  569. {
  570. uint32_t reg;
  571. /* required for EFI mode on macbook2,1 which uses an r5xx asic */
  572. if (efi_enabled(EFI_BOOT) &&
  573. (rdev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE) &&
  574. (rdev->family < CHIP_R600))
  575. return false;
  576. if (ASIC_IS_NODCE(rdev))
  577. goto check_memsize;
  578. /* first check CRTCs */
  579. if (ASIC_IS_DCE4(rdev)) {
  580. reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) |
  581. RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET);
  582. if (rdev->num_crtc >= 4) {
  583. reg |= RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) |
  584. RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET);
  585. }
  586. if (rdev->num_crtc >= 6) {
  587. reg |= RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) |
  588. RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET);
  589. }
  590. if (reg & EVERGREEN_CRTC_MASTER_EN)
  591. return true;
  592. } else if (ASIC_IS_AVIVO(rdev)) {
  593. reg = RREG32(AVIVO_D1CRTC_CONTROL) |
  594. RREG32(AVIVO_D2CRTC_CONTROL);
  595. if (reg & AVIVO_CRTC_EN) {
  596. return true;
  597. }
  598. } else {
  599. reg = RREG32(RADEON_CRTC_GEN_CNTL) |
  600. RREG32(RADEON_CRTC2_GEN_CNTL);
  601. if (reg & RADEON_CRTC_EN) {
  602. return true;
  603. }
  604. }
  605. check_memsize:
  606. /* then check MEM_SIZE, in case the crtcs are off */
  607. if (rdev->family >= CHIP_R600)
  608. reg = RREG32(R600_CONFIG_MEMSIZE);
  609. else
  610. reg = RREG32(RADEON_CONFIG_MEMSIZE);
  611. if (reg)
  612. return true;
  613. return false;
  614. }
  615. /**
  616. * radeon_update_bandwidth_info - update display bandwidth params
  617. *
  618. * @rdev: radeon_device pointer
  619. *
  620. * Used when sclk/mclk are switched or display modes are set.
  621. * params are used to calculate display watermarks (all asics)
  622. */
  623. void radeon_update_bandwidth_info(struct radeon_device *rdev)
  624. {
  625. fixed20_12 a;
  626. u32 sclk = rdev->pm.current_sclk;
  627. u32 mclk = rdev->pm.current_mclk;
  628. /* sclk/mclk in Mhz */
  629. a.full = dfixed_const(100);
  630. rdev->pm.sclk.full = dfixed_const(sclk);
  631. rdev->pm.sclk.full = dfixed_div(rdev->pm.sclk, a);
  632. rdev->pm.mclk.full = dfixed_const(mclk);
  633. rdev->pm.mclk.full = dfixed_div(rdev->pm.mclk, a);
  634. if (rdev->flags & RADEON_IS_IGP) {
  635. a.full = dfixed_const(16);
  636. /* core_bandwidth = sclk(Mhz) * 16 */
  637. rdev->pm.core_bandwidth.full = dfixed_div(rdev->pm.sclk, a);
  638. }
  639. }
  640. /**
  641. * radeon_boot_test_post_card - check and possibly initialize the hw
  642. *
  643. * @rdev: radeon_device pointer
  644. *
  645. * Check if the asic is initialized and if not, attempt to initialize
  646. * it (all asics).
  647. * Returns true if initialized or false if not.
  648. */
  649. bool radeon_boot_test_post_card(struct radeon_device *rdev)
  650. {
  651. if (radeon_card_posted(rdev))
  652. return true;
  653. if (rdev->bios) {
  654. DRM_INFO("GPU not posted. posting now...\n");
  655. if (rdev->is_atom_bios)
  656. atom_asic_init(rdev->mode_info.atom_context);
  657. else
  658. radeon_combios_asic_init(rdev->ddev);
  659. return true;
  660. } else {
  661. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  662. return false;
  663. }
  664. }
  665. /**
  666. * radeon_dummy_page_init - init dummy page used by the driver
  667. *
  668. * @rdev: radeon_device pointer
  669. *
  670. * Allocate the dummy page used by the driver (all asics).
  671. * This dummy page is used by the driver as a filler for gart entries
  672. * when pages are taken out of the GART
  673. * Returns 0 on sucess, -ENOMEM on failure.
  674. */
  675. int radeon_dummy_page_init(struct radeon_device *rdev)
  676. {
  677. if (rdev->dummy_page.page)
  678. return 0;
  679. rdev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO);
  680. if (rdev->dummy_page.page == NULL)
  681. return -ENOMEM;
  682. rdev->dummy_page.addr = pci_map_page(rdev->pdev, rdev->dummy_page.page,
  683. 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  684. if (pci_dma_mapping_error(rdev->pdev, rdev->dummy_page.addr)) {
  685. dev_err(&rdev->pdev->dev, "Failed to DMA MAP the dummy page\n");
  686. __free_page(rdev->dummy_page.page);
  687. rdev->dummy_page.page = NULL;
  688. return -ENOMEM;
  689. }
  690. rdev->dummy_page.entry = radeon_gart_get_page_entry(rdev->dummy_page.addr,
  691. RADEON_GART_PAGE_DUMMY);
  692. return 0;
  693. }
  694. /**
  695. * radeon_dummy_page_fini - free dummy page used by the driver
  696. *
  697. * @rdev: radeon_device pointer
  698. *
  699. * Frees the dummy page used by the driver (all asics).
  700. */
  701. void radeon_dummy_page_fini(struct radeon_device *rdev)
  702. {
  703. if (rdev->dummy_page.page == NULL)
  704. return;
  705. pci_unmap_page(rdev->pdev, rdev->dummy_page.addr,
  706. PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  707. __free_page(rdev->dummy_page.page);
  708. rdev->dummy_page.page = NULL;
  709. }
  710. /* ATOM accessor methods */
  711. /*
  712. * ATOM is an interpreted byte code stored in tables in the vbios. The
  713. * driver registers callbacks to access registers and the interpreter
  714. * in the driver parses the tables and executes then to program specific
  715. * actions (set display modes, asic init, etc.). See radeon_atombios.c,
  716. * atombios.h, and atom.c
  717. */
  718. /**
  719. * cail_pll_read - read PLL register
  720. *
  721. * @info: atom card_info pointer
  722. * @reg: PLL register offset
  723. *
  724. * Provides a PLL register accessor for the atom interpreter (r4xx+).
  725. * Returns the value of the PLL register.
  726. */
  727. static uint32_t cail_pll_read(struct card_info *info, uint32_t reg)
  728. {
  729. struct radeon_device *rdev = info->dev->dev_private;
  730. uint32_t r;
  731. r = rdev->pll_rreg(rdev, reg);
  732. return r;
  733. }
  734. /**
  735. * cail_pll_write - write PLL register
  736. *
  737. * @info: atom card_info pointer
  738. * @reg: PLL register offset
  739. * @val: value to write to the pll register
  740. *
  741. * Provides a PLL register accessor for the atom interpreter (r4xx+).
  742. */
  743. static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val)
  744. {
  745. struct radeon_device *rdev = info->dev->dev_private;
  746. rdev->pll_wreg(rdev, reg, val);
  747. }
  748. /**
  749. * cail_mc_read - read MC (Memory Controller) register
  750. *
  751. * @info: atom card_info pointer
  752. * @reg: MC register offset
  753. *
  754. * Provides an MC register accessor for the atom interpreter (r4xx+).
  755. * Returns the value of the MC register.
  756. */
  757. static uint32_t cail_mc_read(struct card_info *info, uint32_t reg)
  758. {
  759. struct radeon_device *rdev = info->dev->dev_private;
  760. uint32_t r;
  761. r = rdev->mc_rreg(rdev, reg);
  762. return r;
  763. }
  764. /**
  765. * cail_mc_write - write MC (Memory Controller) register
  766. *
  767. * @info: atom card_info pointer
  768. * @reg: MC register offset
  769. * @val: value to write to the pll register
  770. *
  771. * Provides a MC register accessor for the atom interpreter (r4xx+).
  772. */
  773. static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val)
  774. {
  775. struct radeon_device *rdev = info->dev->dev_private;
  776. rdev->mc_wreg(rdev, reg, val);
  777. }
  778. /**
  779. * cail_reg_write - write MMIO register
  780. *
  781. * @info: atom card_info pointer
  782. * @reg: MMIO register offset
  783. * @val: value to write to the pll register
  784. *
  785. * Provides a MMIO register accessor for the atom interpreter (r4xx+).
  786. */
  787. static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val)
  788. {
  789. struct radeon_device *rdev = info->dev->dev_private;
  790. WREG32(reg*4, val);
  791. }
  792. /**
  793. * cail_reg_read - read MMIO register
  794. *
  795. * @info: atom card_info pointer
  796. * @reg: MMIO register offset
  797. *
  798. * Provides an MMIO register accessor for the atom interpreter (r4xx+).
  799. * Returns the value of the MMIO register.
  800. */
  801. static uint32_t cail_reg_read(struct card_info *info, uint32_t reg)
  802. {
  803. struct radeon_device *rdev = info->dev->dev_private;
  804. uint32_t r;
  805. r = RREG32(reg*4);
  806. return r;
  807. }
  808. /**
  809. * cail_ioreg_write - write IO register
  810. *
  811. * @info: atom card_info pointer
  812. * @reg: IO register offset
  813. * @val: value to write to the pll register
  814. *
  815. * Provides a IO register accessor for the atom interpreter (r4xx+).
  816. */
  817. static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val)
  818. {
  819. struct radeon_device *rdev = info->dev->dev_private;
  820. WREG32_IO(reg*4, val);
  821. }
  822. /**
  823. * cail_ioreg_read - read IO register
  824. *
  825. * @info: atom card_info pointer
  826. * @reg: IO register offset
  827. *
  828. * Provides an IO register accessor for the atom interpreter (r4xx+).
  829. * Returns the value of the IO register.
  830. */
  831. static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg)
  832. {
  833. struct radeon_device *rdev = info->dev->dev_private;
  834. uint32_t r;
  835. r = RREG32_IO(reg*4);
  836. return r;
  837. }
  838. /**
  839. * radeon_atombios_init - init the driver info and callbacks for atombios
  840. *
  841. * @rdev: radeon_device pointer
  842. *
  843. * Initializes the driver info and register access callbacks for the
  844. * ATOM interpreter (r4xx+).
  845. * Returns 0 on sucess, -ENOMEM on failure.
  846. * Called at driver startup.
  847. */
  848. int radeon_atombios_init(struct radeon_device *rdev)
  849. {
  850. struct card_info *atom_card_info =
  851. kzalloc(sizeof(struct card_info), GFP_KERNEL);
  852. if (!atom_card_info)
  853. return -ENOMEM;
  854. rdev->mode_info.atom_card_info = atom_card_info;
  855. atom_card_info->dev = rdev->ddev;
  856. atom_card_info->reg_read = cail_reg_read;
  857. atom_card_info->reg_write = cail_reg_write;
  858. /* needed for iio ops */
  859. if (rdev->rio_mem) {
  860. atom_card_info->ioreg_read = cail_ioreg_read;
  861. atom_card_info->ioreg_write = cail_ioreg_write;
  862. } else {
  863. DRM_ERROR("Unable to find PCI I/O BAR; using MMIO for ATOM IIO\n");
  864. atom_card_info->ioreg_read = cail_reg_read;
  865. atom_card_info->ioreg_write = cail_reg_write;
  866. }
  867. atom_card_info->mc_read = cail_mc_read;
  868. atom_card_info->mc_write = cail_mc_write;
  869. atom_card_info->pll_read = cail_pll_read;
  870. atom_card_info->pll_write = cail_pll_write;
  871. rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios);
  872. if (!rdev->mode_info.atom_context) {
  873. radeon_atombios_fini(rdev);
  874. return -ENOMEM;
  875. }
  876. mutex_init(&rdev->mode_info.atom_context->mutex);
  877. mutex_init(&rdev->mode_info.atom_context->scratch_mutex);
  878. radeon_atom_initialize_bios_scratch_regs(rdev->ddev);
  879. atom_allocate_fb_scratch(rdev->mode_info.atom_context);
  880. return 0;
  881. }
  882. /**
  883. * radeon_atombios_fini - free the driver info and callbacks for atombios
  884. *
  885. * @rdev: radeon_device pointer
  886. *
  887. * Frees the driver info and register access callbacks for the ATOM
  888. * interpreter (r4xx+).
  889. * Called at driver shutdown.
  890. */
  891. void radeon_atombios_fini(struct radeon_device *rdev)
  892. {
  893. if (rdev->mode_info.atom_context) {
  894. kfree(rdev->mode_info.atom_context->scratch);
  895. }
  896. kfree(rdev->mode_info.atom_context);
  897. rdev->mode_info.atom_context = NULL;
  898. kfree(rdev->mode_info.atom_card_info);
  899. rdev->mode_info.atom_card_info = NULL;
  900. }
  901. /* COMBIOS */
  902. /*
  903. * COMBIOS is the bios format prior to ATOM. It provides
  904. * command tables similar to ATOM, but doesn't have a unified
  905. * parser. See radeon_combios.c
  906. */
  907. /**
  908. * radeon_combios_init - init the driver info for combios
  909. *
  910. * @rdev: radeon_device pointer
  911. *
  912. * Initializes the driver info for combios (r1xx-r3xx).
  913. * Returns 0 on sucess.
  914. * Called at driver startup.
  915. */
  916. int radeon_combios_init(struct radeon_device *rdev)
  917. {
  918. radeon_combios_initialize_bios_scratch_regs(rdev->ddev);
  919. return 0;
  920. }
  921. /**
  922. * radeon_combios_fini - free the driver info for combios
  923. *
  924. * @rdev: radeon_device pointer
  925. *
  926. * Frees the driver info for combios (r1xx-r3xx).
  927. * Called at driver shutdown.
  928. */
  929. void radeon_combios_fini(struct radeon_device *rdev)
  930. {
  931. }
  932. /* if we get transitioned to only one device, take VGA back */
  933. /**
  934. * radeon_vga_set_decode - enable/disable vga decode
  935. *
  936. * @cookie: radeon_device pointer
  937. * @state: enable/disable vga decode
  938. *
  939. * Enable/disable vga decode (all asics).
  940. * Returns VGA resource flags.
  941. */
  942. static unsigned int radeon_vga_set_decode(void *cookie, bool state)
  943. {
  944. struct radeon_device *rdev = cookie;
  945. radeon_vga_set_state(rdev, state);
  946. if (state)
  947. return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
  948. VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  949. else
  950. return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  951. }
  952. /**
  953. * radeon_check_pot_argument - check that argument is a power of two
  954. *
  955. * @arg: value to check
  956. *
  957. * Validates that a certain argument is a power of two (all asics).
  958. * Returns true if argument is valid.
  959. */
  960. static bool radeon_check_pot_argument(int arg)
  961. {
  962. return (arg & (arg - 1)) == 0;
  963. }
  964. /**
  965. * radeon_check_arguments - validate module params
  966. *
  967. * @rdev: radeon_device pointer
  968. *
  969. * Validates certain module parameters and updates
  970. * the associated values used by the driver (all asics).
  971. */
  972. static void radeon_check_arguments(struct radeon_device *rdev)
  973. {
  974. /* vramlimit must be a power of two */
  975. if (!radeon_check_pot_argument(radeon_vram_limit)) {
  976. dev_warn(rdev->dev, "vram limit (%d) must be a power of 2\n",
  977. radeon_vram_limit);
  978. radeon_vram_limit = 0;
  979. }
  980. if (radeon_gart_size == -1) {
  981. /* default to a larger gart size on newer asics */
  982. if (rdev->family >= CHIP_RV770)
  983. radeon_gart_size = 1024;
  984. else
  985. radeon_gart_size = 512;
  986. }
  987. /* gtt size must be power of two and greater or equal to 32M */
  988. if (radeon_gart_size < 32) {
  989. dev_warn(rdev->dev, "gart size (%d) too small\n",
  990. radeon_gart_size);
  991. if (rdev->family >= CHIP_RV770)
  992. radeon_gart_size = 1024;
  993. else
  994. radeon_gart_size = 512;
  995. } else if (!radeon_check_pot_argument(radeon_gart_size)) {
  996. dev_warn(rdev->dev, "gart size (%d) must be a power of 2\n",
  997. radeon_gart_size);
  998. if (rdev->family >= CHIP_RV770)
  999. radeon_gart_size = 1024;
  1000. else
  1001. radeon_gart_size = 512;
  1002. }
  1003. rdev->mc.gtt_size = (uint64_t)radeon_gart_size << 20;
  1004. /* AGP mode can only be -1, 1, 2, 4, 8 */
  1005. switch (radeon_agpmode) {
  1006. case -1:
  1007. case 0:
  1008. case 1:
  1009. case 2:
  1010. case 4:
  1011. case 8:
  1012. break;
  1013. default:
  1014. dev_warn(rdev->dev, "invalid AGP mode %d (valid mode: "
  1015. "-1, 0, 1, 2, 4, 8)\n", radeon_agpmode);
  1016. radeon_agpmode = 0;
  1017. break;
  1018. }
  1019. if (!radeon_check_pot_argument(radeon_vm_size)) {
  1020. dev_warn(rdev->dev, "VM size (%d) must be a power of 2\n",
  1021. radeon_vm_size);
  1022. radeon_vm_size = 4;
  1023. }
  1024. if (radeon_vm_size < 1) {
  1025. dev_warn(rdev->dev, "VM size (%d) to small, min is 1GB\n",
  1026. radeon_vm_size);
  1027. radeon_vm_size = 4;
  1028. }
  1029. /*
  1030. * Max GPUVM size for Cayman, SI and CI are 40 bits.
  1031. */
  1032. if (radeon_vm_size > 1024) {
  1033. dev_warn(rdev->dev, "VM size (%d) too large, max is 1TB\n",
  1034. radeon_vm_size);
  1035. radeon_vm_size = 4;
  1036. }
  1037. /* defines number of bits in page table versus page directory,
  1038. * a page is 4KB so we have 12 bits offset, minimum 9 bits in the
  1039. * page table and the remaining bits are in the page directory */
  1040. if (radeon_vm_block_size == -1) {
  1041. /* Total bits covered by PD + PTs */
  1042. unsigned bits = ilog2(radeon_vm_size) + 18;
  1043. /* Make sure the PD is 4K in size up to 8GB address space.
  1044. Above that split equal between PD and PTs */
  1045. if (radeon_vm_size <= 8)
  1046. radeon_vm_block_size = bits - 9;
  1047. else
  1048. radeon_vm_block_size = (bits + 3) / 2;
  1049. } else if (radeon_vm_block_size < 9) {
  1050. dev_warn(rdev->dev, "VM page table size (%d) too small\n",
  1051. radeon_vm_block_size);
  1052. radeon_vm_block_size = 9;
  1053. }
  1054. if (radeon_vm_block_size > 24 ||
  1055. (radeon_vm_size * 1024) < (1ull << radeon_vm_block_size)) {
  1056. dev_warn(rdev->dev, "VM page table size (%d) too large\n",
  1057. radeon_vm_block_size);
  1058. radeon_vm_block_size = 9;
  1059. }
  1060. }
  1061. /**
  1062. * radeon_switcheroo_set_state - set switcheroo state
  1063. *
  1064. * @pdev: pci dev pointer
  1065. * @state: vga switcheroo state
  1066. *
  1067. * Callback for the switcheroo driver. Suspends or resumes the
  1068. * the asics before or after it is powered up using ACPI methods.
  1069. */
  1070. static void radeon_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
  1071. {
  1072. struct drm_device *dev = pci_get_drvdata(pdev);
  1073. struct radeon_device *rdev = dev->dev_private;
  1074. if (radeon_is_px(dev) && state == VGA_SWITCHEROO_OFF)
  1075. return;
  1076. if (state == VGA_SWITCHEROO_ON) {
  1077. unsigned d3_delay = dev->pdev->d3_delay;
  1078. printk(KERN_INFO "radeon: switched on\n");
  1079. /* don't suspend or resume card normally */
  1080. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  1081. if (d3_delay < 20 && (rdev->px_quirk_flags & RADEON_PX_QUIRK_LONG_WAKEUP))
  1082. dev->pdev->d3_delay = 20;
  1083. radeon_resume_kms(dev, true, true);
  1084. dev->pdev->d3_delay = d3_delay;
  1085. dev->switch_power_state = DRM_SWITCH_POWER_ON;
  1086. drm_kms_helper_poll_enable(dev);
  1087. } else {
  1088. printk(KERN_INFO "radeon: switched off\n");
  1089. drm_kms_helper_poll_disable(dev);
  1090. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  1091. radeon_suspend_kms(dev, true, true);
  1092. dev->switch_power_state = DRM_SWITCH_POWER_OFF;
  1093. }
  1094. }
  1095. /**
  1096. * radeon_switcheroo_can_switch - see if switcheroo state can change
  1097. *
  1098. * @pdev: pci dev pointer
  1099. *
  1100. * Callback for the switcheroo driver. Check of the switcheroo
  1101. * state can be changed.
  1102. * Returns true if the state can be changed, false if not.
  1103. */
  1104. static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
  1105. {
  1106. struct drm_device *dev = pci_get_drvdata(pdev);
  1107. /*
  1108. * FIXME: open_count is protected by drm_global_mutex but that would lead to
  1109. * locking inversion with the driver load path. And the access here is
  1110. * completely racy anyway. So don't bother with locking for now.
  1111. */
  1112. return dev->open_count == 0;
  1113. }
  1114. static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
  1115. .set_gpu_state = radeon_switcheroo_set_state,
  1116. .reprobe = NULL,
  1117. .can_switch = radeon_switcheroo_can_switch,
  1118. };
  1119. /**
  1120. * radeon_device_init - initialize the driver
  1121. *
  1122. * @rdev: radeon_device pointer
  1123. * @pdev: drm dev pointer
  1124. * @pdev: pci dev pointer
  1125. * @flags: driver flags
  1126. *
  1127. * Initializes the driver info and hw (all asics).
  1128. * Returns 0 for success or an error on failure.
  1129. * Called at driver startup.
  1130. */
  1131. int radeon_device_init(struct radeon_device *rdev,
  1132. struct drm_device *ddev,
  1133. struct pci_dev *pdev,
  1134. uint32_t flags)
  1135. {
  1136. int r, i;
  1137. int dma_bits;
  1138. bool runtime = false;
  1139. rdev->shutdown = false;
  1140. rdev->dev = &pdev->dev;
  1141. rdev->ddev = ddev;
  1142. rdev->pdev = pdev;
  1143. rdev->flags = flags;
  1144. rdev->family = flags & RADEON_FAMILY_MASK;
  1145. rdev->is_atom_bios = false;
  1146. rdev->usec_timeout = RADEON_MAX_USEC_TIMEOUT;
  1147. rdev->mc.gtt_size = 512 * 1024 * 1024;
  1148. rdev->accel_working = false;
  1149. /* set up ring ids */
  1150. for (i = 0; i < RADEON_NUM_RINGS; i++) {
  1151. rdev->ring[i].idx = i;
  1152. }
  1153. rdev->fence_context = fence_context_alloc(RADEON_NUM_RINGS);
  1154. DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X).\n",
  1155. radeon_family_name[rdev->family], pdev->vendor, pdev->device,
  1156. pdev->subsystem_vendor, pdev->subsystem_device);
  1157. /* mutex initialization are all done here so we
  1158. * can recall function without having locking issues */
  1159. mutex_init(&rdev->ring_lock);
  1160. mutex_init(&rdev->dc_hw_i2c_mutex);
  1161. atomic_set(&rdev->ih.lock, 0);
  1162. mutex_init(&rdev->gem.mutex);
  1163. mutex_init(&rdev->pm.mutex);
  1164. mutex_init(&rdev->gpu_clock_mutex);
  1165. mutex_init(&rdev->srbm_mutex);
  1166. init_rwsem(&rdev->pm.mclk_lock);
  1167. init_rwsem(&rdev->exclusive_lock);
  1168. init_waitqueue_head(&rdev->irq.vblank_queue);
  1169. mutex_init(&rdev->mn_lock);
  1170. hash_init(rdev->mn_hash);
  1171. r = radeon_gem_init(rdev);
  1172. if (r)
  1173. return r;
  1174. radeon_check_arguments(rdev);
  1175. /* Adjust VM size here.
  1176. * Max GPUVM size for cayman+ is 40 bits.
  1177. */
  1178. rdev->vm_manager.max_pfn = radeon_vm_size << 18;
  1179. /* Set asic functions */
  1180. r = radeon_asic_init(rdev);
  1181. if (r)
  1182. return r;
  1183. /* all of the newer IGP chips have an internal gart
  1184. * However some rs4xx report as AGP, so remove that here.
  1185. */
  1186. if ((rdev->family >= CHIP_RS400) &&
  1187. (rdev->flags & RADEON_IS_IGP)) {
  1188. rdev->flags &= ~RADEON_IS_AGP;
  1189. }
  1190. if (rdev->flags & RADEON_IS_AGP && radeon_agpmode == -1) {
  1191. radeon_agp_disable(rdev);
  1192. }
  1193. /* Set the internal MC address mask
  1194. * This is the max address of the GPU's
  1195. * internal address space.
  1196. */
  1197. if (rdev->family >= CHIP_CAYMAN)
  1198. rdev->mc.mc_mask = 0xffffffffffULL; /* 40 bit MC */
  1199. else if (rdev->family >= CHIP_CEDAR)
  1200. rdev->mc.mc_mask = 0xfffffffffULL; /* 36 bit MC */
  1201. else
  1202. rdev->mc.mc_mask = 0xffffffffULL; /* 32 bit MC */
  1203. /* set DMA mask + need_dma32 flags.
  1204. * PCIE - can handle 40-bits.
  1205. * IGP - can handle 40-bits
  1206. * AGP - generally dma32 is safest
  1207. * PCI - dma32 for legacy pci gart, 40 bits on newer asics
  1208. */
  1209. rdev->need_dma32 = false;
  1210. if (rdev->flags & RADEON_IS_AGP)
  1211. rdev->need_dma32 = true;
  1212. if ((rdev->flags & RADEON_IS_PCI) &&
  1213. (rdev->family <= CHIP_RS740))
  1214. rdev->need_dma32 = true;
  1215. dma_bits = rdev->need_dma32 ? 32 : 40;
  1216. r = pci_set_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits));
  1217. if (r) {
  1218. rdev->need_dma32 = true;
  1219. dma_bits = 32;
  1220. printk(KERN_WARNING "radeon: No suitable DMA available.\n");
  1221. }
  1222. r = pci_set_consistent_dma_mask(rdev->pdev, DMA_BIT_MASK(dma_bits));
  1223. if (r) {
  1224. pci_set_consistent_dma_mask(rdev->pdev, DMA_BIT_MASK(32));
  1225. printk(KERN_WARNING "radeon: No coherent DMA available.\n");
  1226. }
  1227. /* Registers mapping */
  1228. /* TODO: block userspace mapping of io register */
  1229. spin_lock_init(&rdev->mmio_idx_lock);
  1230. spin_lock_init(&rdev->smc_idx_lock);
  1231. spin_lock_init(&rdev->pll_idx_lock);
  1232. spin_lock_init(&rdev->mc_idx_lock);
  1233. spin_lock_init(&rdev->pcie_idx_lock);
  1234. spin_lock_init(&rdev->pciep_idx_lock);
  1235. spin_lock_init(&rdev->pif_idx_lock);
  1236. spin_lock_init(&rdev->cg_idx_lock);
  1237. spin_lock_init(&rdev->uvd_idx_lock);
  1238. spin_lock_init(&rdev->rcu_idx_lock);
  1239. spin_lock_init(&rdev->didt_idx_lock);
  1240. spin_lock_init(&rdev->end_idx_lock);
  1241. if (rdev->family >= CHIP_BONAIRE) {
  1242. rdev->rmmio_base = pci_resource_start(rdev->pdev, 5);
  1243. rdev->rmmio_size = pci_resource_len(rdev->pdev, 5);
  1244. } else {
  1245. rdev->rmmio_base = pci_resource_start(rdev->pdev, 2);
  1246. rdev->rmmio_size = pci_resource_len(rdev->pdev, 2);
  1247. }
  1248. rdev->rmmio = ioremap(rdev->rmmio_base, rdev->rmmio_size);
  1249. if (rdev->rmmio == NULL) {
  1250. return -ENOMEM;
  1251. }
  1252. DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)rdev->rmmio_base);
  1253. DRM_INFO("register mmio size: %u\n", (unsigned)rdev->rmmio_size);
  1254. /* doorbell bar mapping */
  1255. if (rdev->family >= CHIP_BONAIRE)
  1256. radeon_doorbell_init(rdev);
  1257. /* io port mapping */
  1258. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  1259. if (pci_resource_flags(rdev->pdev, i) & IORESOURCE_IO) {
  1260. rdev->rio_mem_size = pci_resource_len(rdev->pdev, i);
  1261. rdev->rio_mem = pci_iomap(rdev->pdev, i, rdev->rio_mem_size);
  1262. break;
  1263. }
  1264. }
  1265. if (rdev->rio_mem == NULL)
  1266. DRM_ERROR("Unable to find PCI I/O BAR\n");
  1267. if (rdev->flags & RADEON_IS_PX)
  1268. radeon_device_handle_px_quirks(rdev);
  1269. /* if we have > 1 VGA cards, then disable the radeon VGA resources */
  1270. /* this will fail for cards that aren't VGA class devices, just
  1271. * ignore it */
  1272. vga_client_register(rdev->pdev, rdev, NULL, radeon_vga_set_decode);
  1273. if (rdev->flags & RADEON_IS_PX)
  1274. runtime = true;
  1275. vga_switcheroo_register_client(rdev->pdev, &radeon_switcheroo_ops, runtime);
  1276. if (runtime)
  1277. vga_switcheroo_init_domain_pm_ops(rdev->dev, &rdev->vga_pm_domain);
  1278. r = radeon_init(rdev);
  1279. if (r)
  1280. goto failed;
  1281. r = radeon_gem_debugfs_init(rdev);
  1282. if (r) {
  1283. DRM_ERROR("registering gem debugfs failed (%d).\n", r);
  1284. }
  1285. if (rdev->flags & RADEON_IS_AGP && !rdev->accel_working) {
  1286. /* Acceleration not working on AGP card try again
  1287. * with fallback to PCI or PCIE GART
  1288. */
  1289. radeon_asic_reset(rdev);
  1290. radeon_fini(rdev);
  1291. radeon_agp_disable(rdev);
  1292. r = radeon_init(rdev);
  1293. if (r)
  1294. goto failed;
  1295. }
  1296. r = radeon_ib_ring_tests(rdev);
  1297. if (r)
  1298. DRM_ERROR("ib ring test failed (%d).\n", r);
  1299. /*
  1300. * Turks/Thames GPU will freeze whole laptop if DPM is not restarted
  1301. * after the CP ring have chew one packet at least. Hence here we stop
  1302. * and restart DPM after the radeon_ib_ring_tests().
  1303. */
  1304. if (rdev->pm.dpm_enabled &&
  1305. (rdev->pm.pm_method == PM_METHOD_DPM) &&
  1306. (rdev->family == CHIP_TURKS) &&
  1307. (rdev->flags & RADEON_IS_MOBILITY)) {
  1308. mutex_lock(&rdev->pm.mutex);
  1309. radeon_dpm_disable(rdev);
  1310. radeon_dpm_enable(rdev);
  1311. mutex_unlock(&rdev->pm.mutex);
  1312. }
  1313. if ((radeon_testing & 1)) {
  1314. if (rdev->accel_working)
  1315. radeon_test_moves(rdev);
  1316. else
  1317. DRM_INFO("radeon: acceleration disabled, skipping move tests\n");
  1318. }
  1319. if ((radeon_testing & 2)) {
  1320. if (rdev->accel_working)
  1321. radeon_test_syncing(rdev);
  1322. else
  1323. DRM_INFO("radeon: acceleration disabled, skipping sync tests\n");
  1324. }
  1325. if (radeon_benchmarking) {
  1326. if (rdev->accel_working)
  1327. radeon_benchmark(rdev, radeon_benchmarking);
  1328. else
  1329. DRM_INFO("radeon: acceleration disabled, skipping benchmarks\n");
  1330. }
  1331. return 0;
  1332. failed:
  1333. if (runtime)
  1334. vga_switcheroo_fini_domain_pm_ops(rdev->dev);
  1335. return r;
  1336. }
  1337. static void radeon_debugfs_remove_files(struct radeon_device *rdev);
  1338. /**
  1339. * radeon_device_fini - tear down the driver
  1340. *
  1341. * @rdev: radeon_device pointer
  1342. *
  1343. * Tear down the driver info (all asics).
  1344. * Called at driver shutdown.
  1345. */
  1346. void radeon_device_fini(struct radeon_device *rdev)
  1347. {
  1348. DRM_INFO("radeon: finishing device.\n");
  1349. rdev->shutdown = true;
  1350. /* evict vram memory */
  1351. radeon_bo_evict_vram(rdev);
  1352. radeon_fini(rdev);
  1353. vga_switcheroo_unregister_client(rdev->pdev);
  1354. if (rdev->flags & RADEON_IS_PX)
  1355. vga_switcheroo_fini_domain_pm_ops(rdev->dev);
  1356. vga_client_register(rdev->pdev, NULL, NULL, NULL);
  1357. if (rdev->rio_mem)
  1358. pci_iounmap(rdev->pdev, rdev->rio_mem);
  1359. rdev->rio_mem = NULL;
  1360. iounmap(rdev->rmmio);
  1361. rdev->rmmio = NULL;
  1362. if (rdev->family >= CHIP_BONAIRE)
  1363. radeon_doorbell_fini(rdev);
  1364. radeon_debugfs_remove_files(rdev);
  1365. }
  1366. /*
  1367. * Suspend & resume.
  1368. */
  1369. /**
  1370. * radeon_suspend_kms - initiate device suspend
  1371. *
  1372. * @pdev: drm dev pointer
  1373. * @state: suspend state
  1374. *
  1375. * Puts the hw in the suspend state (all asics).
  1376. * Returns 0 for success or an error on failure.
  1377. * Called at driver suspend.
  1378. */
  1379. int radeon_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon)
  1380. {
  1381. struct radeon_device *rdev;
  1382. struct drm_crtc *crtc;
  1383. struct drm_connector *connector;
  1384. int i, r;
  1385. if (dev == NULL || dev->dev_private == NULL) {
  1386. return -ENODEV;
  1387. }
  1388. rdev = dev->dev_private;
  1389. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1390. return 0;
  1391. drm_kms_helper_poll_disable(dev);
  1392. /* turn off display hw */
  1393. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1394. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
  1395. }
  1396. /* unpin the front buffers */
  1397. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1398. struct radeon_framebuffer *rfb = to_radeon_framebuffer(crtc->primary->fb);
  1399. struct radeon_bo *robj;
  1400. if (rfb == NULL || rfb->obj == NULL) {
  1401. continue;
  1402. }
  1403. robj = gem_to_radeon_bo(rfb->obj);
  1404. /* don't unpin kernel fb objects */
  1405. if (!radeon_fbdev_robj_is_fb(rdev, robj)) {
  1406. r = radeon_bo_reserve(robj, false);
  1407. if (r == 0) {
  1408. radeon_bo_unpin(robj);
  1409. radeon_bo_unreserve(robj);
  1410. }
  1411. }
  1412. }
  1413. /* evict vram memory */
  1414. radeon_bo_evict_vram(rdev);
  1415. /* wait for gpu to finish processing current batch */
  1416. for (i = 0; i < RADEON_NUM_RINGS; i++) {
  1417. r = radeon_fence_wait_empty(rdev, i);
  1418. if (r) {
  1419. /* delay GPU reset to resume */
  1420. radeon_fence_driver_force_completion(rdev, i);
  1421. }
  1422. }
  1423. radeon_save_bios_scratch_regs(rdev);
  1424. radeon_suspend(rdev);
  1425. radeon_hpd_fini(rdev);
  1426. /* evict remaining vram memory */
  1427. radeon_bo_evict_vram(rdev);
  1428. radeon_agp_suspend(rdev);
  1429. pci_save_state(dev->pdev);
  1430. if (suspend) {
  1431. /* Shut down the device */
  1432. pci_disable_device(dev->pdev);
  1433. pci_set_power_state(dev->pdev, PCI_D3hot);
  1434. }
  1435. if (fbcon) {
  1436. console_lock();
  1437. radeon_fbdev_set_suspend(rdev, 1);
  1438. console_unlock();
  1439. }
  1440. return 0;
  1441. }
  1442. /**
  1443. * radeon_resume_kms - initiate device resume
  1444. *
  1445. * @pdev: drm dev pointer
  1446. *
  1447. * Bring the hw back to operating state (all asics).
  1448. * Returns 0 for success or an error on failure.
  1449. * Called at driver resume.
  1450. */
  1451. int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon)
  1452. {
  1453. struct drm_connector *connector;
  1454. struct radeon_device *rdev = dev->dev_private;
  1455. int r;
  1456. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1457. return 0;
  1458. if (fbcon) {
  1459. console_lock();
  1460. }
  1461. if (resume) {
  1462. pci_set_power_state(dev->pdev, PCI_D0);
  1463. pci_restore_state(dev->pdev);
  1464. if (pci_enable_device(dev->pdev)) {
  1465. if (fbcon)
  1466. console_unlock();
  1467. return -1;
  1468. }
  1469. }
  1470. /* resume AGP if in use */
  1471. radeon_agp_resume(rdev);
  1472. radeon_resume(rdev);
  1473. r = radeon_ib_ring_tests(rdev);
  1474. if (r)
  1475. DRM_ERROR("ib ring test failed (%d).\n", r);
  1476. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  1477. /* do dpm late init */
  1478. r = radeon_pm_late_init(rdev);
  1479. if (r) {
  1480. rdev->pm.dpm_enabled = false;
  1481. DRM_ERROR("radeon_pm_late_init failed, disabling dpm\n");
  1482. }
  1483. } else {
  1484. /* resume old pm late */
  1485. radeon_pm_resume(rdev);
  1486. }
  1487. radeon_restore_bios_scratch_regs(rdev);
  1488. /* init dig PHYs, disp eng pll */
  1489. if (rdev->is_atom_bios) {
  1490. radeon_atom_encoder_init(rdev);
  1491. radeon_atom_disp_eng_pll_init(rdev);
  1492. /* turn on the BL */
  1493. if (rdev->mode_info.bl_encoder) {
  1494. u8 bl_level = radeon_get_backlight_level(rdev,
  1495. rdev->mode_info.bl_encoder);
  1496. radeon_set_backlight_level(rdev, rdev->mode_info.bl_encoder,
  1497. bl_level);
  1498. }
  1499. }
  1500. /* reset hpd state */
  1501. radeon_hpd_init(rdev);
  1502. /* blat the mode back in */
  1503. if (fbcon) {
  1504. drm_helper_resume_force_mode(dev);
  1505. /* turn on display hw */
  1506. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1507. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
  1508. }
  1509. }
  1510. drm_kms_helper_poll_enable(dev);
  1511. /* set the power state here in case we are a PX system or headless */
  1512. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled)
  1513. radeon_pm_compute_clocks(rdev);
  1514. if (fbcon) {
  1515. radeon_fbdev_set_suspend(rdev, 0);
  1516. console_unlock();
  1517. }
  1518. return 0;
  1519. }
  1520. /**
  1521. * radeon_gpu_reset - reset the asic
  1522. *
  1523. * @rdev: radeon device pointer
  1524. *
  1525. * Attempt the reset the GPU if it has hung (all asics).
  1526. * Returns 0 for success or an error on failure.
  1527. */
  1528. int radeon_gpu_reset(struct radeon_device *rdev)
  1529. {
  1530. unsigned ring_sizes[RADEON_NUM_RINGS];
  1531. uint32_t *ring_data[RADEON_NUM_RINGS];
  1532. bool saved = false;
  1533. int i, r;
  1534. int resched;
  1535. down_write(&rdev->exclusive_lock);
  1536. if (!rdev->needs_reset) {
  1537. up_write(&rdev->exclusive_lock);
  1538. return 0;
  1539. }
  1540. radeon_save_bios_scratch_regs(rdev);
  1541. /* block TTM */
  1542. resched = ttm_bo_lock_delayed_workqueue(&rdev->mman.bdev);
  1543. radeon_suspend(rdev);
  1544. radeon_hpd_fini(rdev);
  1545. for (i = 0; i < RADEON_NUM_RINGS; ++i) {
  1546. ring_sizes[i] = radeon_ring_backup(rdev, &rdev->ring[i],
  1547. &ring_data[i]);
  1548. if (ring_sizes[i]) {
  1549. saved = true;
  1550. dev_info(rdev->dev, "Saved %d dwords of commands "
  1551. "on ring %d.\n", ring_sizes[i], i);
  1552. }
  1553. }
  1554. r = radeon_asic_reset(rdev);
  1555. if (!r) {
  1556. dev_info(rdev->dev, "GPU reset succeeded, trying to resume\n");
  1557. radeon_resume(rdev);
  1558. }
  1559. radeon_restore_bios_scratch_regs(rdev);
  1560. for (i = 0; i < RADEON_NUM_RINGS; ++i) {
  1561. if (!r && ring_data[i]) {
  1562. radeon_ring_restore(rdev, &rdev->ring[i],
  1563. ring_sizes[i], ring_data[i]);
  1564. } else {
  1565. radeon_fence_driver_force_completion(rdev, i);
  1566. kfree(ring_data[i]);
  1567. }
  1568. }
  1569. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled) {
  1570. /* do dpm late init */
  1571. r = radeon_pm_late_init(rdev);
  1572. if (r) {
  1573. rdev->pm.dpm_enabled = false;
  1574. DRM_ERROR("radeon_pm_late_init failed, disabling dpm\n");
  1575. }
  1576. } else {
  1577. /* resume old pm late */
  1578. radeon_pm_resume(rdev);
  1579. }
  1580. /* init dig PHYs, disp eng pll */
  1581. if (rdev->is_atom_bios) {
  1582. radeon_atom_encoder_init(rdev);
  1583. radeon_atom_disp_eng_pll_init(rdev);
  1584. /* turn on the BL */
  1585. if (rdev->mode_info.bl_encoder) {
  1586. u8 bl_level = radeon_get_backlight_level(rdev,
  1587. rdev->mode_info.bl_encoder);
  1588. radeon_set_backlight_level(rdev, rdev->mode_info.bl_encoder,
  1589. bl_level);
  1590. }
  1591. }
  1592. /* reset hpd state */
  1593. radeon_hpd_init(rdev);
  1594. ttm_bo_unlock_delayed_workqueue(&rdev->mman.bdev, resched);
  1595. rdev->in_reset = true;
  1596. rdev->needs_reset = false;
  1597. downgrade_write(&rdev->exclusive_lock);
  1598. drm_helper_resume_force_mode(rdev->ddev);
  1599. /* set the power state here in case we are a PX system or headless */
  1600. if ((rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled)
  1601. radeon_pm_compute_clocks(rdev);
  1602. if (!r) {
  1603. r = radeon_ib_ring_tests(rdev);
  1604. if (r && saved)
  1605. r = -EAGAIN;
  1606. } else {
  1607. /* bad news, how to tell it to userspace ? */
  1608. dev_info(rdev->dev, "GPU reset failed\n");
  1609. }
  1610. rdev->needs_reset = r == -EAGAIN;
  1611. rdev->in_reset = false;
  1612. up_read(&rdev->exclusive_lock);
  1613. return r;
  1614. }
  1615. /*
  1616. * Debugfs
  1617. */
  1618. int radeon_debugfs_add_files(struct radeon_device *rdev,
  1619. struct drm_info_list *files,
  1620. unsigned nfiles)
  1621. {
  1622. unsigned i;
  1623. for (i = 0; i < rdev->debugfs_count; i++) {
  1624. if (rdev->debugfs[i].files == files) {
  1625. /* Already registered */
  1626. return 0;
  1627. }
  1628. }
  1629. i = rdev->debugfs_count + 1;
  1630. if (i > RADEON_DEBUGFS_MAX_COMPONENTS) {
  1631. DRM_ERROR("Reached maximum number of debugfs components.\n");
  1632. DRM_ERROR("Report so we increase "
  1633. "RADEON_DEBUGFS_MAX_COMPONENTS.\n");
  1634. return -EINVAL;
  1635. }
  1636. rdev->debugfs[rdev->debugfs_count].files = files;
  1637. rdev->debugfs[rdev->debugfs_count].num_files = nfiles;
  1638. rdev->debugfs_count = i;
  1639. #if defined(CONFIG_DEBUG_FS)
  1640. drm_debugfs_create_files(files, nfiles,
  1641. rdev->ddev->control->debugfs_root,
  1642. rdev->ddev->control);
  1643. drm_debugfs_create_files(files, nfiles,
  1644. rdev->ddev->primary->debugfs_root,
  1645. rdev->ddev->primary);
  1646. #endif
  1647. return 0;
  1648. }
  1649. static void radeon_debugfs_remove_files(struct radeon_device *rdev)
  1650. {
  1651. #if defined(CONFIG_DEBUG_FS)
  1652. unsigned i;
  1653. for (i = 0; i < rdev->debugfs_count; i++) {
  1654. drm_debugfs_remove_files(rdev->debugfs[i].files,
  1655. rdev->debugfs[i].num_files,
  1656. rdev->ddev->control);
  1657. drm_debugfs_remove_files(rdev->debugfs[i].files,
  1658. rdev->debugfs[i].num_files,
  1659. rdev->ddev->primary);
  1660. }
  1661. #endif
  1662. }
  1663. #if defined(CONFIG_DEBUG_FS)
  1664. int radeon_debugfs_init(struct drm_minor *minor)
  1665. {
  1666. return 0;
  1667. }
  1668. void radeon_debugfs_cleanup(struct drm_minor *minor)
  1669. {
  1670. }
  1671. #endif