3434#include "amd_acpi.h"
3535#include "atom.h"
3636
37+ struct amdgpu_atif_notification_cfg {
38+ bool enabled ;
39+ int command_code ;
40+ };
41+
42+ struct amdgpu_atif_notifications {
43+ bool display_switch ;
44+ bool expansion_mode_change ;
45+ bool thermal_state ;
46+ bool forced_power_state ;
47+ bool system_power_state ;
48+ bool display_conf_change ;
49+ bool px_gfx_switch ;
50+ bool brightness_change ;
51+ bool dgpu_display_event ;
52+ };
53+
54+ struct amdgpu_atif_functions {
55+ bool system_params ;
56+ bool sbios_requests ;
57+ bool select_active_disp ;
58+ bool lid_state ;
59+ bool get_tv_standard ;
60+ bool set_tv_standard ;
61+ bool get_panel_expansion_mode ;
62+ bool set_panel_expansion_mode ;
63+ bool temperature_change ;
64+ bool graphics_device_types ;
65+ };
66+
67+ struct amdgpu_atif {
68+ acpi_handle handle ;
69+
70+ struct amdgpu_atif_notifications notifications ;
71+ struct amdgpu_atif_functions functions ;
72+ struct amdgpu_atif_notification_cfg notification_cfg ;
73+ struct amdgpu_encoder * encoder_for_bl ;
74+ };
75+
3776/* Call the ATIF method
3877 */
3978/**
4685 * Executes the requested ATIF function (all asics).
4786 * Returns a pointer to the acpi output buffer.
4887 */
49- static union acpi_object * amdgpu_atif_call (acpi_handle handle , int function ,
50- struct acpi_buffer * params )
88+ static union acpi_object * amdgpu_atif_call (struct amdgpu_atif * atif ,
89+ int function ,
90+ struct acpi_buffer * params )
5191{
5292 acpi_status status ;
5393 union acpi_object atif_arg_elements [2 ];
@@ -70,7 +110,8 @@ static union acpi_object *amdgpu_atif_call(acpi_handle handle, int function,
70110 atif_arg_elements [1 ].integer .value = 0 ;
71111 }
72112
73- status = acpi_evaluate_object (handle , "ATIF" , & atif_arg , & buffer );
113+ status = acpi_evaluate_object (atif -> handle , NULL , & atif_arg ,
114+ & buffer );
74115
75116 /* Fail only if calling the method fails and ATIF is supported */
76117 if (ACPI_FAILURE (status ) && status != AE_NOT_FOUND ) {
@@ -141,15 +182,14 @@ static void amdgpu_atif_parse_functions(struct amdgpu_atif_functions *f, u32 mas
141182 * (all asics).
142183 * returns 0 on success, error on failure.
143184 */
144- static int amdgpu_atif_verify_interface (acpi_handle handle ,
145- struct amdgpu_atif * atif )
185+ static int amdgpu_atif_verify_interface (struct amdgpu_atif * atif )
146186{
147187 union acpi_object * info ;
148188 struct atif_verify_interface output ;
149189 size_t size ;
150190 int err = 0 ;
151191
152- info = amdgpu_atif_call (handle , ATIF_FUNCTION_VERIFY_INTERFACE , NULL );
192+ info = amdgpu_atif_call (atif , ATIF_FUNCTION_VERIFY_INTERFACE , NULL );
153193 if (!info )
154194 return - EIO ;
155195
@@ -176,6 +216,35 @@ static int amdgpu_atif_verify_interface(acpi_handle handle,
176216 return err ;
177217}
178218
219+ static acpi_handle amdgpu_atif_probe_handle (acpi_handle dhandle )
220+ {
221+ acpi_handle handle = NULL ;
222+ char acpi_method_name [255 ] = { 0 };
223+ struct acpi_buffer buffer = { sizeof (acpi_method_name ), acpi_method_name };
224+ acpi_status status ;
225+
226+ /* For PX/HG systems, ATIF and ATPX are in the iGPU's namespace, on dGPU only
227+ * systems, ATIF is in the dGPU's namespace.
228+ */
229+ status = acpi_get_handle (dhandle , "ATIF" , & handle );
230+ if (ACPI_SUCCESS (status ))
231+ goto out ;
232+
233+ if (amdgpu_has_atpx ()) {
234+ status = acpi_get_handle (amdgpu_atpx_get_dhandle (), "ATIF" ,
235+ & handle );
236+ if (ACPI_SUCCESS (status ))
237+ goto out ;
238+ }
239+
240+ DRM_DEBUG_DRIVER ("No ATIF handle found\n" );
241+ return NULL ;
242+ out :
243+ acpi_get_name (handle , ACPI_FULL_PATHNAME , & buffer );
244+ DRM_DEBUG_DRIVER ("Found ATIF handle %s\n" , acpi_method_name );
245+ return handle ;
246+ }
247+
179248/**
180249 * amdgpu_atif_get_notification_params - determine notify configuration
181250 *
@@ -188,15 +257,16 @@ static int amdgpu_atif_verify_interface(acpi_handle handle,
188257 * where n is specified in the result if a notifier is used.
189258 * Returns 0 on success, error on failure.
190259 */
191- static int amdgpu_atif_get_notification_params (acpi_handle handle ,
192- struct amdgpu_atif_notification_cfg * n )
260+ static int amdgpu_atif_get_notification_params (struct amdgpu_atif * atif )
193261{
194262 union acpi_object * info ;
263+ struct amdgpu_atif_notification_cfg * n = & atif -> notification_cfg ;
195264 struct atif_system_params params ;
196265 size_t size ;
197266 int err = 0 ;
198267
199- info = amdgpu_atif_call (handle , ATIF_FUNCTION_GET_SYSTEM_PARAMETERS , NULL );
268+ info = amdgpu_atif_call (atif , ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ,
269+ NULL );
200270 if (!info ) {
201271 err = - EIO ;
202272 goto out ;
@@ -250,14 +320,15 @@ static int amdgpu_atif_get_notification_params(acpi_handle handle,
250320 * (all asics).
251321 * Returns 0 on success, error on failure.
252322 */
253- static int amdgpu_atif_get_sbios_requests (acpi_handle handle ,
254- struct atif_sbios_requests * req )
323+ static int amdgpu_atif_get_sbios_requests (struct amdgpu_atif * atif ,
324+ struct atif_sbios_requests * req )
255325{
256326 union acpi_object * info ;
257327 size_t size ;
258328 int count = 0 ;
259329
260- info = amdgpu_atif_call (handle , ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS , NULL );
330+ info = amdgpu_atif_call (atif , ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ,
331+ NULL );
261332 if (!info )
262333 return - EIO ;
263334
@@ -290,11 +361,10 @@ static int amdgpu_atif_get_sbios_requests(acpi_handle handle,
290361 * Returns NOTIFY code
291362 */
292363static int amdgpu_atif_handler (struct amdgpu_device * adev ,
293- struct acpi_bus_event * event )
364+ struct acpi_bus_event * event )
294365{
295- struct amdgpu_atif * atif = & adev -> atif ;
366+ struct amdgpu_atif * atif = adev -> atif ;
296367 struct atif_sbios_requests req ;
297- acpi_handle handle ;
298368 int count ;
299369
300370 DRM_DEBUG_DRIVER ("event, device_class = %s, type = %#x\n" ,
@@ -303,14 +373,14 @@ static int amdgpu_atif_handler(struct amdgpu_device *adev,
303373 if (strcmp (event -> device_class , ACPI_VIDEO_CLASS ) != 0 )
304374 return NOTIFY_DONE ;
305375
306- if (!atif -> notification_cfg .enabled ||
376+ if (!atif ||
377+ !atif -> notification_cfg .enabled ||
307378 event -> type != atif -> notification_cfg .command_code )
308379 /* Not our event */
309380 return NOTIFY_DONE ;
310381
311382 /* Check pending SBIOS requests */
312- handle = ACPI_HANDLE (& adev -> pdev -> dev );
313- count = amdgpu_atif_get_sbios_requests (handle , & req );
383+ count = amdgpu_atif_get_sbios_requests (atif , & req );
314384
315385 if (count <= 0 )
316386 return NOTIFY_DONE ;
@@ -641,8 +711,8 @@ static int amdgpu_acpi_event(struct notifier_block *nb,
641711 */
642712int amdgpu_acpi_init (struct amdgpu_device * adev )
643713{
644- acpi_handle handle ;
645- struct amdgpu_atif * atif = & adev -> atif ;
714+ acpi_handle handle , atif_handle ;
715+ struct amdgpu_atif * atif ;
646716 struct amdgpu_atcs * atcs = & adev -> atcs ;
647717 int ret ;
648718
@@ -658,12 +728,26 @@ int amdgpu_acpi_init(struct amdgpu_device *adev)
658728 DRM_DEBUG_DRIVER ("Call to ATCS verify_interface failed: %d\n" , ret );
659729 }
660730
731+ /* Probe for ATIF, and initialize it if found */
732+ atif_handle = amdgpu_atif_probe_handle (handle );
733+ if (!atif_handle )
734+ goto out ;
735+
736+ atif = kzalloc (sizeof (* atif ), GFP_KERNEL );
737+ if (!atif ) {
738+ DRM_WARN ("Not enough memory to initialize ATIF\n" );
739+ goto out ;
740+ }
741+ atif -> handle = atif_handle ;
742+
661743 /* Call the ATIF method */
662- ret = amdgpu_atif_verify_interface (handle , atif );
744+ ret = amdgpu_atif_verify_interface (atif );
663745 if (ret ) {
664746 DRM_DEBUG_DRIVER ("Call to ATIF verify_interface failed: %d\n" , ret );
747+ kfree (atif );
665748 goto out ;
666749 }
750+ adev -> atif = atif ;
667751
668752 if (atif -> notifications .brightness_change ) {
669753 struct drm_encoder * tmp ;
@@ -693,8 +777,7 @@ int amdgpu_acpi_init(struct amdgpu_device *adev)
693777 }
694778
695779 if (atif -> functions .system_params ) {
696- ret = amdgpu_atif_get_notification_params (handle ,
697- & atif -> notification_cfg );
780+ ret = amdgpu_atif_get_notification_params (atif );
698781 if (ret ) {
699782 DRM_DEBUG_DRIVER ("Call to GET_SYSTEM_PARAMS failed: %d\n" ,
700783 ret );
@@ -720,4 +803,6 @@ int amdgpu_acpi_init(struct amdgpu_device *adev)
720803void amdgpu_acpi_fini (struct amdgpu_device * adev )
721804{
722805 unregister_acpi_notifier (& adev -> acpi_nb );
806+ if (adev -> atif )
807+ kfree (adev -> atif );
723808}
0 commit comments