amdgpu_atpx_handler.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * Copyright (c) 2010 Red Hat Inc.
  3. * Author : Dave Airlie <airlied@redhat.com>
  4. *
  5. * Licensed under GPLv2
  6. *
  7. * ATPX support for both Intel/ATI
  8. */
  9. #include <linux/vga_switcheroo.h>
  10. #include <linux/slab.h>
  11. #include <linux/acpi.h>
  12. #include <linux/pci.h>
  13. #include <linux/delay.h>
  14. #include "amd_acpi.h"
  15. #define AMDGPU_PX_QUIRK_FORCE_ATPX (1 << 0)
  16. struct amdgpu_px_quirk {
  17. u32 chip_vendor;
  18. u32 chip_device;
  19. u32 subsys_vendor;
  20. u32 subsys_device;
  21. u32 px_quirk_flags;
  22. };
  23. struct amdgpu_atpx_functions {
  24. bool px_params;
  25. bool power_cntl;
  26. bool disp_mux_cntl;
  27. bool i2c_mux_cntl;
  28. bool switch_start;
  29. bool switch_end;
  30. bool disp_connectors_mapping;
  31. bool disp_detetion_ports;
  32. };
  33. struct amdgpu_atpx {
  34. acpi_handle handle;
  35. struct amdgpu_atpx_functions functions;
  36. bool is_hybrid;
  37. bool dgpu_req_power_for_displays;
  38. };
  39. static struct amdgpu_atpx_priv {
  40. bool atpx_detected;
  41. bool bridge_pm_usable;
  42. unsigned int quirks;
  43. /* handle for device - and atpx */
  44. acpi_handle dhandle;
  45. acpi_handle other_handle;
  46. struct amdgpu_atpx atpx;
  47. } amdgpu_atpx_priv;
  48. struct atpx_verify_interface {
  49. u16 size; /* structure size in bytes (includes size field) */
  50. u16 version; /* version */
  51. u32 function_bits; /* supported functions bit vector */
  52. } __packed;
  53. struct atpx_px_params {
  54. u16 size; /* structure size in bytes (includes size field) */
  55. u32 valid_flags; /* which flags are valid */
  56. u32 flags; /* flags */
  57. } __packed;
  58. struct atpx_power_control {
  59. u16 size;
  60. u8 dgpu_state;
  61. } __packed;
  62. struct atpx_mux {
  63. u16 size;
  64. u16 mux;
  65. } __packed;
  66. bool amdgpu_has_atpx(void) {
  67. return amdgpu_atpx_priv.atpx_detected;
  68. }
  69. bool amdgpu_has_atpx_dgpu_power_cntl(void) {
  70. return amdgpu_atpx_priv.atpx.functions.power_cntl;
  71. }
  72. bool amdgpu_is_atpx_hybrid(void) {
  73. return amdgpu_atpx_priv.atpx.is_hybrid;
  74. }
  75. bool amdgpu_atpx_dgpu_req_power_for_displays(void) {
  76. return amdgpu_atpx_priv.atpx.dgpu_req_power_for_displays;
  77. }
  78. /**
  79. * amdgpu_atpx_call - call an ATPX method
  80. *
  81. * @handle: acpi handle
  82. * @function: the ATPX function to execute
  83. * @params: ATPX function params
  84. *
  85. * Executes the requested ATPX function (all asics).
  86. * Returns a pointer to the acpi output buffer.
  87. */
  88. static union acpi_object *amdgpu_atpx_call(acpi_handle handle, int function,
  89. struct acpi_buffer *params)
  90. {
  91. acpi_status status;
  92. union acpi_object atpx_arg_elements[2];
  93. struct acpi_object_list atpx_arg;
  94. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  95. atpx_arg.count = 2;
  96. atpx_arg.pointer = &atpx_arg_elements[0];
  97. atpx_arg_elements[0].type = ACPI_TYPE_INTEGER;
  98. atpx_arg_elements[0].integer.value = function;
  99. if (params) {
  100. atpx_arg_elements[1].type = ACPI_TYPE_BUFFER;
  101. atpx_arg_elements[1].buffer.length = params->length;
  102. atpx_arg_elements[1].buffer.pointer = params->pointer;
  103. } else {
  104. /* We need a second fake parameter */
  105. atpx_arg_elements[1].type = ACPI_TYPE_INTEGER;
  106. atpx_arg_elements[1].integer.value = 0;
  107. }
  108. status = acpi_evaluate_object(handle, NULL, &atpx_arg, &buffer);
  109. /* Fail only if calling the method fails and ATPX is supported */
  110. if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
  111. printk("failed to evaluate ATPX got %s\n",
  112. acpi_format_exception(status));
  113. kfree(buffer.pointer);
  114. return NULL;
  115. }
  116. return buffer.pointer;
  117. }
  118. /**
  119. * amdgpu_atpx_parse_functions - parse supported functions
  120. *
  121. * @f: supported functions struct
  122. * @mask: supported functions mask from ATPX
  123. *
  124. * Use the supported functions mask from ATPX function
  125. * ATPX_FUNCTION_VERIFY_INTERFACE to determine what functions
  126. * are supported (all asics).
  127. */
  128. static void amdgpu_atpx_parse_functions(struct amdgpu_atpx_functions *f, u32 mask)
  129. {
  130. f->px_params = mask & ATPX_GET_PX_PARAMETERS_SUPPORTED;
  131. f->power_cntl = mask & ATPX_POWER_CONTROL_SUPPORTED;
  132. f->disp_mux_cntl = mask & ATPX_DISPLAY_MUX_CONTROL_SUPPORTED;
  133. f->i2c_mux_cntl = mask & ATPX_I2C_MUX_CONTROL_SUPPORTED;
  134. f->switch_start = mask & ATPX_GRAPHICS_DEVICE_SWITCH_START_NOTIFICATION_SUPPORTED;
  135. f->switch_end = mask & ATPX_GRAPHICS_DEVICE_SWITCH_END_NOTIFICATION_SUPPORTED;
  136. f->disp_connectors_mapping = mask & ATPX_GET_DISPLAY_CONNECTORS_MAPPING_SUPPORTED;
  137. f->disp_detetion_ports = mask & ATPX_GET_DISPLAY_DETECTION_PORTS_SUPPORTED;
  138. }
  139. /**
  140. * amdgpu_atpx_validate_functions - validate ATPX functions
  141. *
  142. * @atpx: amdgpu atpx struct
  143. *
  144. * Validate that required functions are enabled (all asics).
  145. * returns 0 on success, error on failure.
  146. */
  147. static int amdgpu_atpx_validate(struct amdgpu_atpx *atpx)
  148. {
  149. u32 valid_bits = 0;
  150. if (atpx->functions.px_params) {
  151. union acpi_object *info;
  152. struct atpx_px_params output;
  153. size_t size;
  154. info = amdgpu_atpx_call(atpx->handle, ATPX_FUNCTION_GET_PX_PARAMETERS, NULL);
  155. if (!info)
  156. return -EIO;
  157. memset(&output, 0, sizeof(output));
  158. size = *(u16 *) info->buffer.pointer;
  159. if (size < 10) {
  160. printk("ATPX buffer is too small: %zu\n", size);
  161. kfree(info);
  162. return -EINVAL;
  163. }
  164. size = min(sizeof(output), size);
  165. memcpy(&output, info->buffer.pointer, size);
  166. valid_bits = output.flags & output.valid_flags;
  167. kfree(info);
  168. }
  169. /* if separate mux flag is set, mux controls are required */
  170. if (valid_bits & ATPX_SEPARATE_MUX_FOR_I2C) {
  171. atpx->functions.i2c_mux_cntl = true;
  172. atpx->functions.disp_mux_cntl = true;
  173. }
  174. /* if any outputs are muxed, mux controls are required */
  175. if (valid_bits & (ATPX_CRT1_RGB_SIGNAL_MUXED |
  176. ATPX_TV_SIGNAL_MUXED |
  177. ATPX_DFP_SIGNAL_MUXED))
  178. atpx->functions.disp_mux_cntl = true;
  179. /* some bioses set these bits rather than flagging power_cntl as supported */
  180. if (valid_bits & (ATPX_DYNAMIC_PX_SUPPORTED |
  181. ATPX_DYNAMIC_DGPU_POWER_OFF_SUPPORTED))
  182. atpx->functions.power_cntl = true;
  183. atpx->is_hybrid = false;
  184. if (valid_bits & ATPX_MS_HYBRID_GFX_SUPPORTED) {
  185. if (amdgpu_atpx_priv.quirks & AMDGPU_PX_QUIRK_FORCE_ATPX) {
  186. printk("ATPX Hybrid Graphics, forcing to ATPX\n");
  187. atpx->functions.power_cntl = true;
  188. atpx->is_hybrid = false;
  189. } else {
  190. printk("ATPX Hybrid Graphics\n");
  191. /*
  192. * Disable legacy PM methods only when pcie port PM is usable,
  193. * otherwise the device might fail to power off or power on.
  194. */
  195. atpx->functions.power_cntl = !amdgpu_atpx_priv.bridge_pm_usable;
  196. atpx->is_hybrid = true;
  197. }
  198. }
  199. atpx->dgpu_req_power_for_displays = false;
  200. if (valid_bits & ATPX_DGPU_REQ_POWER_FOR_DISPLAYS)
  201. atpx->dgpu_req_power_for_displays = true;
  202. return 0;
  203. }
  204. /**
  205. * amdgpu_atpx_verify_interface - verify ATPX
  206. *
  207. * @atpx: amdgpu atpx struct
  208. *
  209. * Execute the ATPX_FUNCTION_VERIFY_INTERFACE ATPX function
  210. * to initialize ATPX and determine what features are supported
  211. * (all asics).
  212. * returns 0 on success, error on failure.
  213. */
  214. static int amdgpu_atpx_verify_interface(struct amdgpu_atpx *atpx)
  215. {
  216. union acpi_object *info;
  217. struct atpx_verify_interface output;
  218. size_t size;
  219. int err = 0;
  220. info = amdgpu_atpx_call(atpx->handle, ATPX_FUNCTION_VERIFY_INTERFACE, NULL);
  221. if (!info)
  222. return -EIO;
  223. memset(&output, 0, sizeof(output));
  224. size = *(u16 *) info->buffer.pointer;
  225. if (size < 8) {
  226. printk("ATPX buffer is too small: %zu\n", size);
  227. err = -EINVAL;
  228. goto out;
  229. }
  230. size = min(sizeof(output), size);
  231. memcpy(&output, info->buffer.pointer, size);
  232. /* TODO: check version? */
  233. printk("ATPX version %u, functions 0x%08x\n",
  234. output.version, output.function_bits);
  235. amdgpu_atpx_parse_functions(&atpx->functions, output.function_bits);
  236. out:
  237. kfree(info);
  238. return err;
  239. }
  240. /**
  241. * amdgpu_atpx_set_discrete_state - power up/down discrete GPU
  242. *
  243. * @atpx: atpx info struct
  244. * @state: discrete GPU state (0 = power down, 1 = power up)
  245. *
  246. * Execute the ATPX_FUNCTION_POWER_CONTROL ATPX function to
  247. * power down/up the discrete GPU (all asics).
  248. * Returns 0 on success, error on failure.
  249. */
  250. static int amdgpu_atpx_set_discrete_state(struct amdgpu_atpx *atpx, u8 state)
  251. {
  252. struct acpi_buffer params;
  253. union acpi_object *info;
  254. struct atpx_power_control input;
  255. if (atpx->functions.power_cntl) {
  256. input.size = 3;
  257. input.dgpu_state = state;
  258. params.length = input.size;
  259. params.pointer = &input;
  260. info = amdgpu_atpx_call(atpx->handle,
  261. ATPX_FUNCTION_POWER_CONTROL,
  262. &params);
  263. if (!info)
  264. return -EIO;
  265. kfree(info);
  266. /* 200ms delay is required after off */
  267. if (state == 0)
  268. msleep(200);
  269. }
  270. return 0;
  271. }
  272. /**
  273. * amdgpu_atpx_switch_disp_mux - switch display mux
  274. *
  275. * @atpx: atpx info struct
  276. * @mux_id: mux state (0 = integrated GPU, 1 = discrete GPU)
  277. *
  278. * Execute the ATPX_FUNCTION_DISPLAY_MUX_CONTROL ATPX function to
  279. * switch the display mux between the discrete GPU and integrated GPU
  280. * (all asics).
  281. * Returns 0 on success, error on failure.
  282. */
  283. static int amdgpu_atpx_switch_disp_mux(struct amdgpu_atpx *atpx, u16 mux_id)
  284. {
  285. struct acpi_buffer params;
  286. union acpi_object *info;
  287. struct atpx_mux input;
  288. if (atpx->functions.disp_mux_cntl) {
  289. input.size = 4;
  290. input.mux = mux_id;
  291. params.length = input.size;
  292. params.pointer = &input;
  293. info = amdgpu_atpx_call(atpx->handle,
  294. ATPX_FUNCTION_DISPLAY_MUX_CONTROL,
  295. &params);
  296. if (!info)
  297. return -EIO;
  298. kfree(info);
  299. }
  300. return 0;
  301. }
  302. /**
  303. * amdgpu_atpx_switch_i2c_mux - switch i2c/hpd mux
  304. *
  305. * @atpx: atpx info struct
  306. * @mux_id: mux state (0 = integrated GPU, 1 = discrete GPU)
  307. *
  308. * Execute the ATPX_FUNCTION_I2C_MUX_CONTROL ATPX function to
  309. * switch the i2c/hpd mux between the discrete GPU and integrated GPU
  310. * (all asics).
  311. * Returns 0 on success, error on failure.
  312. */
  313. static int amdgpu_atpx_switch_i2c_mux(struct amdgpu_atpx *atpx, u16 mux_id)
  314. {
  315. struct acpi_buffer params;
  316. union acpi_object *info;
  317. struct atpx_mux input;
  318. if (atpx->functions.i2c_mux_cntl) {
  319. input.size = 4;
  320. input.mux = mux_id;
  321. params.length = input.size;
  322. params.pointer = &input;
  323. info = amdgpu_atpx_call(atpx->handle,
  324. ATPX_FUNCTION_I2C_MUX_CONTROL,
  325. &params);
  326. if (!info)
  327. return -EIO;
  328. kfree(info);
  329. }
  330. return 0;
  331. }
  332. /**
  333. * amdgpu_atpx_switch_start - notify the sbios of a GPU switch
  334. *
  335. * @atpx: atpx info struct
  336. * @mux_id: mux state (0 = integrated GPU, 1 = discrete GPU)
  337. *
  338. * Execute the ATPX_FUNCTION_GRAPHICS_DEVICE_SWITCH_START_NOTIFICATION ATPX
  339. * function to notify the sbios that a switch between the discrete GPU and
  340. * integrated GPU has begun (all asics).
  341. * Returns 0 on success, error on failure.
  342. */
  343. static int amdgpu_atpx_switch_start(struct amdgpu_atpx *atpx, u16 mux_id)
  344. {
  345. struct acpi_buffer params;
  346. union acpi_object *info;
  347. struct atpx_mux input;
  348. if (atpx->functions.switch_start) {
  349. input.size = 4;
  350. input.mux = mux_id;
  351. params.length = input.size;
  352. params.pointer = &input;
  353. info = amdgpu_atpx_call(atpx->handle,
  354. ATPX_FUNCTION_GRAPHICS_DEVICE_SWITCH_START_NOTIFICATION,
  355. &params);
  356. if (!info)
  357. return -EIO;
  358. kfree(info);
  359. }
  360. return 0;
  361. }
  362. /**
  363. * amdgpu_atpx_switch_end - notify the sbios of a GPU switch
  364. *
  365. * @atpx: atpx info struct
  366. * @mux_id: mux state (0 = integrated GPU, 1 = discrete GPU)
  367. *
  368. * Execute the ATPX_FUNCTION_GRAPHICS_DEVICE_SWITCH_END_NOTIFICATION ATPX
  369. * function to notify the sbios that a switch between the discrete GPU and
  370. * integrated GPU has ended (all asics).
  371. * Returns 0 on success, error on failure.
  372. */
  373. static int amdgpu_atpx_switch_end(struct amdgpu_atpx *atpx, u16 mux_id)
  374. {
  375. struct acpi_buffer params;
  376. union acpi_object *info;
  377. struct atpx_mux input;
  378. if (atpx->functions.switch_end) {
  379. input.size = 4;
  380. input.mux = mux_id;
  381. params.length = input.size;
  382. params.pointer = &input;
  383. info = amdgpu_atpx_call(atpx->handle,
  384. ATPX_FUNCTION_GRAPHICS_DEVICE_SWITCH_END_NOTIFICATION,
  385. &params);
  386. if (!info)
  387. return -EIO;
  388. kfree(info);
  389. }
  390. return 0;
  391. }
  392. /**
  393. * amdgpu_atpx_switchto - switch to the requested GPU
  394. *
  395. * @id: GPU to switch to
  396. *
  397. * Execute the necessary ATPX functions to switch between the discrete GPU and
  398. * integrated GPU (all asics).
  399. * Returns 0 on success, error on failure.
  400. */
  401. static int amdgpu_atpx_switchto(enum vga_switcheroo_client_id id)
  402. {
  403. u16 gpu_id;
  404. if (id == VGA_SWITCHEROO_IGD)
  405. gpu_id = ATPX_INTEGRATED_GPU;
  406. else
  407. gpu_id = ATPX_DISCRETE_GPU;
  408. amdgpu_atpx_switch_start(&amdgpu_atpx_priv.atpx, gpu_id);
  409. amdgpu_atpx_switch_disp_mux(&amdgpu_atpx_priv.atpx, gpu_id);
  410. amdgpu_atpx_switch_i2c_mux(&amdgpu_atpx_priv.atpx, gpu_id);
  411. amdgpu_atpx_switch_end(&amdgpu_atpx_priv.atpx, gpu_id);
  412. return 0;
  413. }
  414. /**
  415. * amdgpu_atpx_power_state - power down/up the requested GPU
  416. *
  417. * @id: GPU to power down/up
  418. * @state: requested power state (0 = off, 1 = on)
  419. *
  420. * Execute the necessary ATPX function to power down/up the discrete GPU
  421. * (all asics).
  422. * Returns 0 on success, error on failure.
  423. */
  424. static int amdgpu_atpx_power_state(enum vga_switcheroo_client_id id,
  425. enum vga_switcheroo_state state)
  426. {
  427. /* on w500 ACPI can't change intel gpu state */
  428. if (id == VGA_SWITCHEROO_IGD)
  429. return 0;
  430. amdgpu_atpx_set_discrete_state(&amdgpu_atpx_priv.atpx, state);
  431. return 0;
  432. }
  433. /**
  434. * amdgpu_atpx_pci_probe_handle - look up the ATPX handle
  435. *
  436. * @pdev: pci device
  437. *
  438. * Look up the ATPX handles (all asics).
  439. * Returns true if the handles are found, false if not.
  440. */
  441. static bool amdgpu_atpx_pci_probe_handle(struct pci_dev *pdev)
  442. {
  443. acpi_handle dhandle, atpx_handle;
  444. acpi_status status;
  445. dhandle = ACPI_HANDLE(&pdev->dev);
  446. if (!dhandle)
  447. return false;
  448. status = acpi_get_handle(dhandle, "ATPX", &atpx_handle);
  449. if (ACPI_FAILURE(status)) {
  450. amdgpu_atpx_priv.other_handle = dhandle;
  451. return false;
  452. }
  453. amdgpu_atpx_priv.dhandle = dhandle;
  454. amdgpu_atpx_priv.atpx.handle = atpx_handle;
  455. return true;
  456. }
  457. /**
  458. * amdgpu_atpx_init - verify the ATPX interface
  459. *
  460. * Verify the ATPX interface (all asics).
  461. * Returns 0 on success, error on failure.
  462. */
  463. static int amdgpu_atpx_init(void)
  464. {
  465. int r;
  466. /* set up the ATPX handle */
  467. r = amdgpu_atpx_verify_interface(&amdgpu_atpx_priv.atpx);
  468. if (r)
  469. return r;
  470. /* validate the atpx setup */
  471. r = amdgpu_atpx_validate(&amdgpu_atpx_priv.atpx);
  472. if (r)
  473. return r;
  474. return 0;
  475. }
  476. /**
  477. * amdgpu_atpx_get_client_id - get the client id
  478. *
  479. * @pdev: pci device
  480. *
  481. * look up whether we are the integrated or discrete GPU (all asics).
  482. * Returns the client id.
  483. */
  484. static int amdgpu_atpx_get_client_id(struct pci_dev *pdev)
  485. {
  486. if (amdgpu_atpx_priv.dhandle == ACPI_HANDLE(&pdev->dev))
  487. return VGA_SWITCHEROO_IGD;
  488. else
  489. return VGA_SWITCHEROO_DIS;
  490. }
  491. static const struct vga_switcheroo_handler amdgpu_atpx_handler = {
  492. .switchto = amdgpu_atpx_switchto,
  493. .power_state = amdgpu_atpx_power_state,
  494. .get_client_id = amdgpu_atpx_get_client_id,
  495. };
  496. static const struct amdgpu_px_quirk amdgpu_px_quirk_list[] = {
  497. /* HG _PR3 doesn't seem to work on this A+A weston board */
  498. { 0x1002, 0x6900, 0x1002, 0x0124, AMDGPU_PX_QUIRK_FORCE_ATPX },
  499. { 0x1002, 0x6900, 0x1028, 0x0812, AMDGPU_PX_QUIRK_FORCE_ATPX },
  500. { 0, 0, 0, 0, 0 },
  501. };
  502. static void amdgpu_atpx_get_quirks(struct pci_dev *pdev)
  503. {
  504. const struct amdgpu_px_quirk *p = amdgpu_px_quirk_list;
  505. /* Apply PX quirks */
  506. while (p && p->chip_device != 0) {
  507. if (pdev->vendor == p->chip_vendor &&
  508. pdev->device == p->chip_device &&
  509. pdev->subsystem_vendor == p->subsys_vendor &&
  510. pdev->subsystem_device == p->subsys_device) {
  511. amdgpu_atpx_priv.quirks |= p->px_quirk_flags;
  512. break;
  513. }
  514. ++p;
  515. }
  516. }
  517. /**
  518. * amdgpu_atpx_detect - detect whether we have PX
  519. *
  520. * Check if we have a PX system (all asics).
  521. * Returns true if we have a PX system, false if not.
  522. */
  523. static bool amdgpu_atpx_detect(void)
  524. {
  525. char acpi_method_name[255] = { 0 };
  526. struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
  527. struct pci_dev *pdev = NULL;
  528. bool has_atpx = false;
  529. int vga_count = 0;
  530. bool d3_supported = false;
  531. struct pci_dev *parent_pdev;
  532. while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
  533. vga_count++;
  534. has_atpx |= (amdgpu_atpx_pci_probe_handle(pdev) == true);
  535. parent_pdev = pci_upstream_bridge(pdev);
  536. d3_supported |= parent_pdev && parent_pdev->bridge_d3;
  537. amdgpu_atpx_get_quirks(pdev);
  538. }
  539. while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) {
  540. vga_count++;
  541. has_atpx |= (amdgpu_atpx_pci_probe_handle(pdev) == true);
  542. parent_pdev = pci_upstream_bridge(pdev);
  543. d3_supported |= parent_pdev && parent_pdev->bridge_d3;
  544. amdgpu_atpx_get_quirks(pdev);
  545. }
  546. if (has_atpx && vga_count == 2) {
  547. acpi_get_name(amdgpu_atpx_priv.atpx.handle, ACPI_FULL_PATHNAME, &buffer);
  548. pr_info("vga_switcheroo: detected switching method %s handle\n",
  549. acpi_method_name);
  550. amdgpu_atpx_priv.atpx_detected = true;
  551. amdgpu_atpx_priv.bridge_pm_usable = d3_supported;
  552. amdgpu_atpx_init();
  553. return true;
  554. }
  555. return false;
  556. }
  557. /**
  558. * amdgpu_register_atpx_handler - register with vga_switcheroo
  559. *
  560. * Register the PX callbacks with vga_switcheroo (all asics).
  561. */
  562. void amdgpu_register_atpx_handler(void)
  563. {
  564. bool r;
  565. enum vga_switcheroo_handler_flags_t handler_flags = 0;
  566. /* detect if we have any ATPX + 2 VGA in the system */
  567. r = amdgpu_atpx_detect();
  568. if (!r)
  569. return;
  570. vga_switcheroo_register_handler(&amdgpu_atpx_handler, handler_flags);
  571. }
  572. /**
  573. * amdgpu_unregister_atpx_handler - unregister with vga_switcheroo
  574. *
  575. * Unregister the PX callbacks with vga_switcheroo (all asics).
  576. */
  577. void amdgpu_unregister_atpx_handler(void)
  578. {
  579. vga_switcheroo_unregister_handler();
  580. }