Skip to content

Commit 74e1697

Browse files
committed
Merge branch 'drm-next-3.9' of git://people.freedesktop.org/~agd5f/linux into drm-next
More drm-next bits for radeon. Just bug fixes. * 'drm-next-3.9' of git://people.freedesktop.org/~agd5f/linux: drm/radeon: properly validate the atpx interface drm/radeon: switch get_gpu_clock() to a callback (v2) drm/radeon: add a asic callback to get the xclk drm/radeon: Avoid NULL pointer dereference from atom_index_iio() allocation failure drm/radeon: remove overzealous warning in hdmi handling drm/radeon: fix multi-head power profile stability on BTC+ asics
2 parents e9f211a + 43a23aa commit 74e1697

15 files changed

Lines changed: 212 additions & 19 deletions

File tree

‎drivers/gpu/drm/radeon/atom.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,8 @@ static int atom_iio_len[] = { 1, 2, 3, 3, 3, 3, 4, 4, 4, 3 };
12381238
static void atom_index_iio(struct atom_context *ctx, int base)
12391239
{
12401240
ctx->iio = kzalloc(2 * 256, GFP_KERNEL);
1241+
if (!ctx->iio)
1242+
return;
12411243
while (CU8(base) == ATOM_IIO_START) {
12421244
ctx->iio[CU8(base + 1)] = base + 2;
12431245
base += 2;
@@ -1287,6 +1289,10 @@ struct atom_context *atom_parse(struct card_info *card, void *bios)
12871289
ctx->cmd_table = CU16(base + ATOM_ROM_CMD_PTR);
12881290
ctx->data_table = CU16(base + ATOM_ROM_DATA_PTR);
12891291
atom_index_iio(ctx, CU16(ctx->data_table + ATOM_DATA_IIO_PTR) + 4);
1292+
if (!ctx->iio) {
1293+
atom_destroy(ctx);
1294+
return NULL;
1295+
}
12901296

12911297
str = CSTR(CU16(base + ATOM_ROM_MSG_PTR));
12921298
while (*str && ((*str == '\n') || (*str == '\r')))
@@ -1335,8 +1341,7 @@ int atom_asic_init(struct atom_context *ctx)
13351341

13361342
void atom_destroy(struct atom_context *ctx)
13371343
{
1338-
if (ctx->iio)
1339-
kfree(ctx->iio);
1344+
kfree(ctx->iio);
13401345
kfree(ctx);
13411346
}
13421347

‎drivers/gpu/drm/radeon/evergreen.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,19 @@ void evergreen_pm_misc(struct radeon_device *rdev)
403403
rdev->pm.current_vddc = voltage->voltage;
404404
DRM_DEBUG("Setting: vddc: %d\n", voltage->voltage);
405405
}
406+
407+
/* starting with BTC, there is one state that is used for both
408+
* MH and SH. Difference is that we always use the high clock index for
409+
* mclk and vddci.
410+
*/
411+
if ((rdev->pm.pm_method == PM_METHOD_PROFILE) &&
412+
(rdev->family >= CHIP_BARTS) &&
413+
rdev->pm.active_crtc_count &&
414+
((rdev->pm.profile_index == PM_PROFILE_MID_MH_IDX) ||
415+
(rdev->pm.profile_index == PM_PROFILE_LOW_MH_IDX)))
416+
voltage = &rdev->pm.power_state[req_ps_idx].
417+
clock_info[rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx].voltage;
418+
406419
/* 0xff01 is a flag rather then an actual voltage */
407420
if (voltage->vddci == 0xff01)
408421
return;

‎drivers/gpu/drm/radeon/r600.c‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ void r600_fini(struct radeon_device *rdev);
109109
void r600_irq_disable(struct radeon_device *rdev);
110110
static void r600_pcie_gen2_enable(struct radeon_device *rdev);
111111

112+
/**
113+
* r600_get_xclk - get the xclk
114+
*
115+
* @rdev: radeon_device pointer
116+
*
117+
* Returns the reference clock used by the gfx engine
118+
* (r6xx, IGPs, APUs).
119+
*/
120+
u32 r600_get_xclk(struct radeon_device *rdev)
121+
{
122+
return rdev->clock.spll.reference_freq;
123+
}
124+
112125
/* get temperature in millidegrees */
113126
int rv6xx_get_temp(struct radeon_device *rdev)
114127
{
@@ -4448,14 +4461,14 @@ static void r600_pcie_gen2_enable(struct radeon_device *rdev)
44484461
}
44494462

44504463
/**
4451-
* r600_get_gpu_clock - return GPU clock counter snapshot
4464+
* r600_get_gpu_clock_counter - return GPU clock counter snapshot
44524465
*
44534466
* @rdev: radeon_device pointer
44544467
*
44554468
* Fetches a GPU clock counter snapshot (R6xx-cayman).
44564469
* Returns the 64 bit clock counter snapshot.
44574470
*/
4458-
uint64_t r600_get_gpu_clock(struct radeon_device *rdev)
4471+
uint64_t r600_get_gpu_clock_counter(struct radeon_device *rdev)
44594472
{
44604473
uint64_t clock;
44614474

‎drivers/gpu/drm/radeon/r600_hdmi.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@ void r600_hdmi_disable(struct drm_encoder *encoder)
544544

545545
/* Called for ATOM_ENCODER_MODE_HDMI only */
546546
if (!dig || !dig->afmt) {
547-
WARN_ON(1);
548547
return;
549548
}
550549
if (!dig->afmt->enabled)

‎drivers/gpu/drm/radeon/radeon.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,10 @@ struct radeon_asic {
11781178
bool (*gui_idle)(struct radeon_device *rdev);
11791179
/* wait for mc_idle */
11801180
int (*mc_wait_for_idle)(struct radeon_device *rdev);
1181+
/* get the reference clock */
1182+
u32 (*get_xclk)(struct radeon_device *rdev);
1183+
/* get the gpu clock counter */
1184+
uint64_t (*get_gpu_clock_counter)(struct radeon_device *rdev);
11811185
/* gart */
11821186
struct {
11831187
void (*tlb_flush)(struct radeon_device *rdev);
@@ -1859,6 +1863,8 @@ void radeon_ring_write(struct radeon_ring *ring, uint32_t v);
18591863
#define radeon_post_page_flip(rdev, crtc) (rdev)->asic->pflip.post_page_flip((rdev), (crtc))
18601864
#define radeon_wait_for_vblank(rdev, crtc) (rdev)->asic->display.wait_for_vblank((rdev), (crtc))
18611865
#define radeon_mc_wait_for_idle(rdev) (rdev)->asic->mc_wait_for_idle((rdev))
1866+
#define radeon_get_xclk(rdev) (rdev)->asic->get_xclk((rdev))
1867+
#define radeon_get_gpu_clock_counter(rdev) (rdev)->asic->get_gpu_clock_counter((rdev))
18621868

18631869
/* Common functions */
18641870
/* AGP */

‎drivers/gpu/drm/radeon/radeon_asic.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,8 @@ static struct radeon_asic r600_asic = {
934934
.ioctl_wait_idle = r600_ioctl_wait_idle,
935935
.gui_idle = &r600_gui_idle,
936936
.mc_wait_for_idle = &r600_mc_wait_for_idle,
937+
.get_xclk = &r600_get_xclk,
938+
.get_gpu_clock_counter = &r600_get_gpu_clock_counter,
937939
.gart = {
938940
.tlb_flush = &r600_pcie_gart_tlb_flush,
939941
.set_page = &rs600_gart_set_page,
@@ -1018,6 +1020,8 @@ static struct radeon_asic rs780_asic = {
10181020
.ioctl_wait_idle = r600_ioctl_wait_idle,
10191021
.gui_idle = &r600_gui_idle,
10201022
.mc_wait_for_idle = &r600_mc_wait_for_idle,
1023+
.get_xclk = &r600_get_xclk,
1024+
.get_gpu_clock_counter = &r600_get_gpu_clock_counter,
10211025
.gart = {
10221026
.tlb_flush = &r600_pcie_gart_tlb_flush,
10231027
.set_page = &rs600_gart_set_page,
@@ -1102,6 +1106,8 @@ static struct radeon_asic rv770_asic = {
11021106
.ioctl_wait_idle = r600_ioctl_wait_idle,
11031107
.gui_idle = &r600_gui_idle,
11041108
.mc_wait_for_idle = &r600_mc_wait_for_idle,
1109+
.get_xclk = &rv770_get_xclk,
1110+
.get_gpu_clock_counter = &r600_get_gpu_clock_counter,
11051111
.gart = {
11061112
.tlb_flush = &r600_pcie_gart_tlb_flush,
11071113
.set_page = &rs600_gart_set_page,
@@ -1186,6 +1192,8 @@ static struct radeon_asic evergreen_asic = {
11861192
.ioctl_wait_idle = r600_ioctl_wait_idle,
11871193
.gui_idle = &r600_gui_idle,
11881194
.mc_wait_for_idle = &evergreen_mc_wait_for_idle,
1195+
.get_xclk = &rv770_get_xclk,
1196+
.get_gpu_clock_counter = &r600_get_gpu_clock_counter,
11891197
.gart = {
11901198
.tlb_flush = &evergreen_pcie_gart_tlb_flush,
11911199
.set_page = &rs600_gart_set_page,
@@ -1270,6 +1278,8 @@ static struct radeon_asic sumo_asic = {
12701278
.ioctl_wait_idle = r600_ioctl_wait_idle,
12711279
.gui_idle = &r600_gui_idle,
12721280
.mc_wait_for_idle = &evergreen_mc_wait_for_idle,
1281+
.get_xclk = &r600_get_xclk,
1282+
.get_gpu_clock_counter = &r600_get_gpu_clock_counter,
12731283
.gart = {
12741284
.tlb_flush = &evergreen_pcie_gart_tlb_flush,
12751285
.set_page = &rs600_gart_set_page,
@@ -1354,6 +1364,8 @@ static struct radeon_asic btc_asic = {
13541364
.ioctl_wait_idle = r600_ioctl_wait_idle,
13551365
.gui_idle = &r600_gui_idle,
13561366
.mc_wait_for_idle = &evergreen_mc_wait_for_idle,
1367+
.get_xclk = &rv770_get_xclk,
1368+
.get_gpu_clock_counter = &r600_get_gpu_clock_counter,
13571369
.gart = {
13581370
.tlb_flush = &evergreen_pcie_gart_tlb_flush,
13591371
.set_page = &rs600_gart_set_page,
@@ -1438,6 +1450,8 @@ static struct radeon_asic cayman_asic = {
14381450
.ioctl_wait_idle = r600_ioctl_wait_idle,
14391451
.gui_idle = &r600_gui_idle,
14401452
.mc_wait_for_idle = &evergreen_mc_wait_for_idle,
1453+
.get_xclk = &rv770_get_xclk,
1454+
.get_gpu_clock_counter = &r600_get_gpu_clock_counter,
14411455
.gart = {
14421456
.tlb_flush = &cayman_pcie_gart_tlb_flush,
14431457
.set_page = &rs600_gart_set_page,
@@ -1565,6 +1579,8 @@ static struct radeon_asic trinity_asic = {
15651579
.ioctl_wait_idle = r600_ioctl_wait_idle,
15661580
.gui_idle = &r600_gui_idle,
15671581
.mc_wait_for_idle = &evergreen_mc_wait_for_idle,
1582+
.get_xclk = &r600_get_xclk,
1583+
.get_gpu_clock_counter = &r600_get_gpu_clock_counter,
15681584
.gart = {
15691585
.tlb_flush = &cayman_pcie_gart_tlb_flush,
15701586
.set_page = &rs600_gart_set_page,
@@ -1692,6 +1708,8 @@ static struct radeon_asic si_asic = {
16921708
.ioctl_wait_idle = r600_ioctl_wait_idle,
16931709
.gui_idle = &r600_gui_idle,
16941710
.mc_wait_for_idle = &evergreen_mc_wait_for_idle,
1711+
.get_xclk = &si_get_xclk,
1712+
.get_gpu_clock_counter = &si_get_gpu_clock_counter,
16951713
.gart = {
16961714
.tlb_flush = &si_pcie_gart_tlb_flush,
16971715
.set_page = &rs600_gart_set_page,

‎drivers/gpu/drm/radeon/radeon_asic.h‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ void r600_kms_blit_copy(struct radeon_device *rdev,
389389
unsigned num_gpu_pages,
390390
struct radeon_sa_bo *vb);
391391
int r600_mc_wait_for_idle(struct radeon_device *rdev);
392-
uint64_t r600_get_gpu_clock(struct radeon_device *rdev);
392+
u32 r600_get_xclk(struct radeon_device *rdev);
393+
uint64_t r600_get_gpu_clock_counter(struct radeon_device *rdev);
393394

394395
/*
395396
* rv770,rv730,rv710,rv740
@@ -407,6 +408,7 @@ int rv770_copy_dma(struct radeon_device *rdev,
407408
uint64_t src_offset, uint64_t dst_offset,
408409
unsigned num_gpu_pages,
409410
struct radeon_fence **fence);
411+
u32 rv770_get_xclk(struct radeon_device *rdev);
410412

411413
/*
412414
* evergreen
@@ -515,11 +517,12 @@ void si_vm_set_page(struct radeon_device *rdev,
515517
uint32_t incr, uint32_t flags);
516518
void si_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm);
517519
int si_ib_parse(struct radeon_device *rdev, struct radeon_ib *ib);
518-
uint64_t si_get_gpu_clock(struct radeon_device *rdev);
519520
int si_copy_dma(struct radeon_device *rdev,
520521
uint64_t src_offset, uint64_t dst_offset,
521522
unsigned num_gpu_pages,
522523
struct radeon_fence **fence);
523524
void si_dma_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm);
525+
u32 si_get_xclk(struct radeon_device *rdev);
526+
uint64_t si_get_gpu_clock_counter(struct radeon_device *rdev);
524527

525528
#endif

‎drivers/gpu/drm/radeon/radeon_atpx_handler.c‎

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ struct atpx_verify_interface {
4343
u32 function_bits; /* supported functions bit vector */
4444
} __packed;
4545

46+
struct atpx_px_params {
47+
u16 size; /* structure size in bytes (includes size field) */
48+
u32 valid_flags; /* which flags are valid */
49+
u32 flags; /* flags */
50+
} __packed;
51+
4652
struct atpx_power_control {
4753
u16 size;
4854
u8 dgpu_state;
@@ -122,10 +128,62 @@ static void radeon_atpx_parse_functions(struct radeon_atpx_functions *f, u32 mas
122128
f->disp_detetion_ports = mask & ATPX_GET_DISPLAY_DETECTION_PORTS_SUPPORTED;
123129
}
124130

131+
/**
132+
* radeon_atpx_validate_functions - validate ATPX functions
133+
*
134+
* @atpx: radeon atpx struct
135+
*
136+
* Validate that required functions are enabled (all asics).
137+
* returns 0 on success, error on failure.
138+
*/
139+
static int radeon_atpx_validate(struct radeon_atpx *atpx)
140+
{
141+
/* make sure required functions are enabled */
142+
/* dGPU power control is required */
143+
atpx->functions.power_cntl = true;
144+
145+
if (atpx->functions.px_params) {
146+
union acpi_object *info;
147+
struct atpx_px_params output;
148+
size_t size;
149+
u32 valid_bits;
150+
151+
info = radeon_atpx_call(atpx->handle, ATPX_FUNCTION_GET_PX_PARAMETERS, NULL);
152+
if (!info)
153+
return -EIO;
154+
155+
memset(&output, 0, sizeof(output));
156+
157+
size = *(u16 *) info->buffer.pointer;
158+
if (size < 10) {
159+
printk("ATPX buffer is too small: %zu\n", size);
160+
kfree(info);
161+
return -EINVAL;
162+
}
163+
size = min(sizeof(output), size);
164+
165+
memcpy(&output, info->buffer.pointer, size);
166+
167+
valid_bits = output.flags & output.valid_flags;
168+
/* if separate mux flag is set, mux controls are required */
169+
if (valid_bits & ATPX_SEPARATE_MUX_FOR_I2C) {
170+
atpx->functions.i2c_mux_cntl = true;
171+
atpx->functions.disp_mux_cntl = true;
172+
}
173+
/* if any outputs are muxed, mux controls are required */
174+
if (valid_bits & (ATPX_CRT1_RGB_SIGNAL_MUXED |
175+
ATPX_TV_SIGNAL_MUXED |
176+
ATPX_DFP_SIGNAL_MUXED))
177+
atpx->functions.disp_mux_cntl = true;
178+
179+
kfree(info);
180+
}
181+
return 0;
182+
}
183+
125184
/**
126185
* radeon_atpx_verify_interface - verify ATPX
127186
*
128-
* @handle: acpi handle
129187
* @atpx: radeon atpx struct
130188
*
131189
* Execute the ATPX_FUNCTION_VERIFY_INTERFACE ATPX function
@@ -406,8 +464,19 @@ static bool radeon_atpx_pci_probe_handle(struct pci_dev *pdev)
406464
*/
407465
static int radeon_atpx_init(void)
408466
{
467+
int r;
468+
409469
/* set up the ATPX handle */
410-
return radeon_atpx_verify_interface(&radeon_atpx_priv.atpx);
470+
r = radeon_atpx_verify_interface(&radeon_atpx_priv.atpx);
471+
if (r)
472+
return r;
473+
474+
/* validate the atpx setup */
475+
r = radeon_atpx_validate(&radeon_atpx_priv.atpx);
476+
if (r)
477+
return r;
478+
479+
return 0;
411480
}
412481

413482
/**

‎drivers/gpu/drm/radeon/radeon_device.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,11 @@ int radeon_atombios_init(struct radeon_device *rdev)
759759
atom_card_info->pll_write = cail_pll_write;
760760

761761
rdev->mode_info.atom_context = atom_parse(atom_card_info, rdev->bios);
762+
if (!rdev->mode_info.atom_context) {
763+
radeon_atombios_fini(rdev);
764+
return -ENOMEM;
765+
}
766+
762767
mutex_init(&rdev->mode_info.atom_context->mutex);
763768
radeon_atom_initialize_bios_scratch_regs(rdev->ddev);
764769
atom_allocate_fb_scratch(rdev->mode_info.atom_context);
@@ -778,9 +783,11 @@ void radeon_atombios_fini(struct radeon_device *rdev)
778783
{
779784
if (rdev->mode_info.atom_context) {
780785
kfree(rdev->mode_info.atom_context->scratch);
781-
kfree(rdev->mode_info.atom_context);
782786
}
787+
kfree(rdev->mode_info.atom_context);
788+
rdev->mode_info.atom_context = NULL;
783789
kfree(rdev->mode_info.atom_card_info);
790+
rdev->mode_info.atom_card_info = NULL;
784791
}
785792

786793
/* COMBIOS */

‎drivers/gpu/drm/radeon/radeon_kms.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,7 @@ int radeon_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
185185
if (info->request == RADEON_INFO_TIMESTAMP) {
186186
if (rdev->family >= CHIP_R600) {
187187
value_ptr64 = (uint64_t*)((unsigned long)info->value);
188-
if (rdev->family >= CHIP_TAHITI) {
189-
value64 = si_get_gpu_clock(rdev);
190-
} else {
191-
value64 = r600_get_gpu_clock(rdev);
192-
}
188+
value64 = radeon_get_gpu_clock_counter(rdev);
193189

194190
if (DRM_COPY_TO_USER(value_ptr64, &value64, sizeof(value64))) {
195191
DRM_ERROR("copy_to_user %s:%u\n", __func__, __LINE__);
@@ -282,7 +278,10 @@ int radeon_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
282278
break;
283279
case RADEON_INFO_CLOCK_CRYSTAL_FREQ:
284280
/* return clock value in KHz */
285-
value = rdev->clock.spll.reference_freq * 10;
281+
if (rdev->asic->get_xclk)
282+
value = radeon_get_xclk(rdev) * 10;
283+
else
284+
value = rdev->clock.spll.reference_freq * 10;
286285
break;
287286
case RADEON_INFO_NUM_BACKENDS:
288287
if (rdev->family >= CHIP_TAHITI)

0 commit comments

Comments
 (0)