projects/linux·blob master · refs

151 lines · 4.3 KiB

1//SPDX-License-Identifier: MIT
2/*
3 * Copyright 2015 Advanced Micro Devices, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Authors: AMD
24 *
25 */
26
27#include <linux/string.h>
28#include <linux/acpi.h>
29
30#include <drm/drm_probe_helper.h>
31#include <drm/amdgpu_drm.h>
32#include "dm_services.h"
33#include "amdgpu.h"
34#include "amdgpu_dm.h"
35#include "amdgpu_dm_backlight.h"
36#include "amdgpu_dm_irq.h"
37#include "amdgpu_pm.h"
38#include "amdgpu_dm_trace.h"
39#include "dm_helpers.h"
40
41 unsigned long long
42 dm_get_elapse_time_in_ns(struct dc_context *ctx,
43 unsigned long long current_time_stamp,
44 unsigned long long last_time_stamp)
45{
46 return current_time_stamp - last_time_stamp;
47}
48EXPORT_IF_KUNIT(dm_get_elapse_time_in_ns);
49
50void dm_perf_trace_timestamp(const char *func_name, unsigned int line, struct dc_context *ctx)
51{
52 trace_amdgpu_dc_performance(ctx->perf_trace->read_count,
53 ctx->perf_trace->write_count,
54 &ctx->perf_trace->last_entry_read,
55 &ctx->perf_trace->last_entry_write,
56 func_name, line);
57}
58EXPORT_IF_KUNIT(dm_perf_trace_timestamp);
59
60void dm_trace_smu_enter(uint32_t msg_id, uint32_t param_in, unsigned int delay, struct dc_context *ctx)
61{
62}
63EXPORT_IF_KUNIT(dm_trace_smu_enter);
64
65void dm_trace_smu_exit(bool success, uint32_t response, struct dc_context *ctx)
66{
67}
68EXPORT_IF_KUNIT(dm_trace_smu_exit);
69
70/**** power component interfaces ****/
71
72bool dm_query_extended_brightness_caps(struct dc_context *ctx,
73 enum dm_acpi_display_type display, struct dm_acpi_atif_backlight_caps *pCaps)
74{
75 struct amdgpu_device *adev;
76 struct amdgpu_display_manager *dm;
77 int bl_index = (display == AcpiDisplayType_LCD1) ? 0 : 1;
78
79 if (!ctx || !pCaps || !ctx->driver_context)
80 return false;
81
82 adev = (struct amdgpu_device *)ctx->driver_context;
83 dm = &adev->dm;
84
85 amdgpu_dm_update_backlight_caps(dm, bl_index);
86
87 pCaps->num_data_points = dm->backlight_caps[bl_index].data_points;
88 pCaps->max_input_signal = dm->backlight_caps[bl_index].max_input_signal;
89 pCaps->min_input_signal = dm->backlight_caps[bl_index].min_input_signal;
90 pCaps->ac_level_percentage = dm->backlight_caps[bl_index].ac_level;
91 pCaps->dc_level_percentage = dm->backlight_caps[bl_index].dc_level;
92
93 if (pCaps->num_data_points > 0)
94 memcpy(pCaps->data_points, dm->backlight_caps[bl_index].luminance_data,
95 sizeof(struct dm_bl_data_point) * pCaps->num_data_points);
96 return true;
97}
98EXPORT_IF_KUNIT(dm_query_extended_brightness_caps);
99
100void*
101dm_allocate_gpu_mem(
102 struct amdgpu_device *adev,
103 enum dc_gpu_mem_alloc_type type,
104 size_t size,
105 long long *addr)
106{
107 struct dal_allocation *da;
108 u32 domain = (type == DC_MEM_ALLOC_TYPE_GART) ?
109 AMDGPU_GEM_DOMAIN_GTT : AMDGPU_GEM_DOMAIN_VRAM;
110 int ret;
111
112 da = kzalloc_obj(*da);
113 if (!da)
114 return NULL;
115
116 ret = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
117 domain, &da->bo,
118 &da->gpu_addr, &da->cpu_ptr);
119
120 *addr = da->gpu_addr;
121
122 if (ret) {
123 kfree(da);
124 return NULL;
125 }
126
127 /* add da to list in dm */
128 list_add(&da->list, &adev->dm.da_list);
129
130 return da->cpu_ptr;
131}
132
133void
134dm_free_gpu_mem(
135 struct amdgpu_device *adev,
136 enum dc_gpu_mem_alloc_type type,
137 void *pvMem)
138{
139 struct dal_allocation *da;
140
141 /* walk the da list in DM */
142 list_for_each_entry(da, &adev->dm.da_list, list) {
143 if (pvMem == da->cpu_ptr) {
144 amdgpu_bo_free_kernel(&da->bo, &da->gpu_addr, &da->cpu_ptr);
145 list_del(&da->list);
146 kfree(da);
147 break;
148 }
149 }
150
151}