Skip to content

Commit 9ac4883

Browse files
committed
Merge tag 'drm-misc-fixes-2023-12-07' of git://anongit.freedesktop.org/drm/drm-misc into drm-fixes
drm-misc-fixes for v6.7-rc5: - Document nouveau's GSP-RM. - Flush vmm harder on nouveau tu102. - Panfrost fix for imported dma-buf objects, and device frequency. - Kconfig Build fix for tc358768. - Call end_fb_access after atomic commit. Signed-off-by: Dave Airlie <[email protected]> From: Maarten Lankhorst <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
2 parents abd0211 + e0f04e4 commit 9ac4883

File tree

10 files changed

+207
-32
lines changed

10 files changed

+207
-32
lines changed

drivers/gpu/drm/bridge/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ config DRM_TOSHIBA_TC358768
313313
select REGMAP_I2C
314314
select DRM_PANEL
315315
select DRM_MIPI_DSI
316+
select VIDEOMODE_HELPERS
316317
help
317318
Toshiba TC358768AXBG/TC358778XBG DSI bridge chip driver.
318319

drivers/gpu/drm/drm_atomic_helper.c

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,7 @@ int drm_atomic_helper_commit(struct drm_device *dev,
20122012
return ret;
20132013

20142014
drm_atomic_helper_async_commit(dev, state);
2015-
drm_atomic_helper_cleanup_planes(dev, state);
2015+
drm_atomic_helper_unprepare_planes(dev, state);
20162016

20172017
return 0;
20182018
}
@@ -2072,7 +2072,7 @@ int drm_atomic_helper_commit(struct drm_device *dev,
20722072
return 0;
20732073

20742074
err:
2075-
drm_atomic_helper_cleanup_planes(dev, state);
2075+
drm_atomic_helper_unprepare_planes(dev, state);
20762076
return ret;
20772077
}
20782078
EXPORT_SYMBOL(drm_atomic_helper_commit);
@@ -2650,6 +2650,39 @@ int drm_atomic_helper_prepare_planes(struct drm_device *dev,
26502650
}
26512651
EXPORT_SYMBOL(drm_atomic_helper_prepare_planes);
26522652

2653+
/**
2654+
* drm_atomic_helper_unprepare_planes - release plane resources on aborts
2655+
* @dev: DRM device
2656+
* @state: atomic state object with old state structures
2657+
*
2658+
* This function cleans up plane state, specifically framebuffers, from the
2659+
* atomic state. It undoes the effects of drm_atomic_helper_prepare_planes()
2660+
* when aborting an atomic commit. For cleaning up after a successful commit
2661+
* use drm_atomic_helper_cleanup_planes().
2662+
*/
2663+
void drm_atomic_helper_unprepare_planes(struct drm_device *dev,
2664+
struct drm_atomic_state *state)
2665+
{
2666+
struct drm_plane *plane;
2667+
struct drm_plane_state *new_plane_state;
2668+
int i;
2669+
2670+
for_each_new_plane_in_state(state, plane, new_plane_state, i) {
2671+
const struct drm_plane_helper_funcs *funcs = plane->helper_private;
2672+
2673+
if (funcs->end_fb_access)
2674+
funcs->end_fb_access(plane, new_plane_state);
2675+
}
2676+
2677+
for_each_new_plane_in_state(state, plane, new_plane_state, i) {
2678+
const struct drm_plane_helper_funcs *funcs = plane->helper_private;
2679+
2680+
if (funcs->cleanup_fb)
2681+
funcs->cleanup_fb(plane, new_plane_state);
2682+
}
2683+
}
2684+
EXPORT_SYMBOL(drm_atomic_helper_unprepare_planes);
2685+
26532686
static bool plane_crtc_active(const struct drm_plane_state *state)
26542687
{
26552688
return state->crtc && state->crtc->state->active;
@@ -2784,6 +2817,17 @@ void drm_atomic_helper_commit_planes(struct drm_device *dev,
27842817

27852818
funcs->atomic_flush(crtc, old_state);
27862819
}
2820+
2821+
/*
2822+
* Signal end of framebuffer access here before hw_done. After hw_done,
2823+
* a later commit might have already released the plane state.
2824+
*/
2825+
for_each_old_plane_in_state(old_state, plane, old_plane_state, i) {
2826+
const struct drm_plane_helper_funcs *funcs = plane->helper_private;
2827+
2828+
if (funcs->end_fb_access)
2829+
funcs->end_fb_access(plane, old_plane_state);
2830+
}
27872831
}
27882832
EXPORT_SYMBOL(drm_atomic_helper_commit_planes);
27892833

@@ -2911,40 +2955,22 @@ EXPORT_SYMBOL(drm_atomic_helper_disable_planes_on_crtc);
29112955
* configuration. Hence the old configuration must be perserved in @old_state to
29122956
* be able to call this function.
29132957
*
2914-
* This function must also be called on the new state when the atomic update
2915-
* fails at any point after calling drm_atomic_helper_prepare_planes().
2958+
* This function may not be called on the new state when the atomic update
2959+
* fails at any point after calling drm_atomic_helper_prepare_planes(). Use
2960+
* drm_atomic_helper_unprepare_planes() in this case.
29162961
*/
29172962
void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
29182963
struct drm_atomic_state *old_state)
29192964
{
29202965
struct drm_plane *plane;
2921-
struct drm_plane_state *old_plane_state, *new_plane_state;
2966+
struct drm_plane_state *old_plane_state;
29222967
int i;
29232968

2924-
for_each_oldnew_plane_in_state(old_state, plane, old_plane_state, new_plane_state, i) {
2969+
for_each_old_plane_in_state(old_state, plane, old_plane_state, i) {
29252970
const struct drm_plane_helper_funcs *funcs = plane->helper_private;
29262971

2927-
if (funcs->end_fb_access)
2928-
funcs->end_fb_access(plane, new_plane_state);
2929-
}
2930-
2931-
for_each_oldnew_plane_in_state(old_state, plane, old_plane_state, new_plane_state, i) {
2932-
const struct drm_plane_helper_funcs *funcs;
2933-
struct drm_plane_state *plane_state;
2934-
2935-
/*
2936-
* This might be called before swapping when commit is aborted,
2937-
* in which case we have to cleanup the new state.
2938-
*/
2939-
if (old_plane_state == plane->state)
2940-
plane_state = new_plane_state;
2941-
else
2942-
plane_state = old_plane_state;
2943-
2944-
funcs = plane->helper_private;
2945-
29462972
if (funcs->cleanup_fb)
2947-
funcs->cleanup_fb(plane, plane_state);
2973+
funcs->cleanup_fb(plane, old_plane_state);
29482974
}
29492975
}
29502976
EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes);

drivers/gpu/drm/i915/display/intel_display.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7488,7 +7488,7 @@ int intel_atomic_commit(struct drm_device *dev, struct drm_atomic_state *_state,
74887488
for_each_new_intel_crtc_in_state(state, crtc, new_crtc_state, i)
74897489
intel_color_cleanup_commit(new_crtc_state);
74907490

7491-
drm_atomic_helper_cleanup_planes(dev, &state->base);
7491+
drm_atomic_helper_unprepare_planes(dev, &state->base);
74927492
intel_runtime_pm_put(&dev_priv->runtime_pm, state->wakeref);
74937493
return ret;
74947494
}

drivers/gpu/drm/nouveau/dispnv50/disp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,7 @@ nv50_disp_atomic_commit(struct drm_device *dev,
24742474

24752475
err_cleanup:
24762476
if (ret)
2477-
drm_atomic_helper_cleanup_planes(dev, state);
2477+
drm_atomic_helper_unprepare_planes(dev, state);
24782478
done:
24792479
pm_runtime_put_autosuspend(dev->dev);
24802480
return ret;

drivers/gpu/drm/nouveau/include/nvrm/535.113.01/common/shared/msgq/inc/msgq/msgq_priv.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,49 @@
2626
* DEALINGS IN THE SOFTWARE.
2727
*/
2828

29+
/**
30+
* msgqTxHeader -- TX queue data structure
31+
* @version: the version of this structure, must be 0
32+
* @size: the size of the entire queue, including this header
33+
* @msgSize: the padded size of queue element, 16 is minimum
34+
* @msgCount: the number of elements in this queue
35+
* @writePtr: head index of this queue
36+
* @flags: 1 = swap the RX pointers
37+
* @rxHdrOff: offset of readPtr in this structure
38+
* @entryOff: offset of beginning of queue (msgqRxHeader), relative to
39+
* beginning of this structure
40+
*
41+
* The command queue is a queue of RPCs that are sent from the driver to the
42+
* GSP. The status queue is a queue of messages/responses from GSP-RM to the
43+
* driver. Although the driver allocates memory for both queues, the command
44+
* queue is owned by the driver and the status queue is owned by GSP-RM. In
45+
* addition, the headers of the two queues must not share the same 4K page.
46+
*
47+
* Each queue is prefixed with this data structure. The idea is that a queue
48+
* and its header are written to only by their owner. That is, only the
49+
* driver writes to the command queue and command queue header, and only the
50+
* GSP writes to the status (receive) queue and its header.
51+
*
52+
* This is enforced by the concept of "swapping" the RX pointers. This is
53+
* why the 'flags' field must be set to 1. 'rxHdrOff' is how the GSP knows
54+
* where the where the tail pointer of its status queue.
55+
*
56+
* When the driver writes a new RPC to the command queue, it updates writePtr.
57+
* When it reads a new message from the status queue, it updates readPtr. In
58+
* this way, the GSP knows when a new command is in the queue (it polls
59+
* writePtr) and it knows how much free space is in the status queue (it
60+
* checks readPtr). The driver never cares about how much free space is in
61+
* the status queue.
62+
*
63+
* As usual, producers write to the head pointer, and consumers read from the
64+
* tail pointer. When head == tail, the queue is empty.
65+
*
66+
* So to summarize:
67+
* command.writePtr = head of command queue
68+
* command.readPtr = tail of status queue
69+
* status.writePtr = head of status queue
70+
* status.readPtr = tail of command queue
71+
*/
2972
typedef struct
3073
{
3174
NvU32 version; // queue version
@@ -38,6 +81,14 @@ typedef struct
3881
NvU32 entryOff; // Offset of entries from start of backing store.
3982
} msgqTxHeader;
4083

84+
/**
85+
* msgqRxHeader - RX queue data structure
86+
* @readPtr: tail index of the other queue
87+
*
88+
* Although this is a separate struct, it could easily be merged into
89+
* msgqTxHeader. msgqTxHeader.rxHdrOff is simply the offset of readPtr
90+
* from the beginning of msgqTxHeader.
91+
*/
4192
typedef struct
4293
{
4394
NvU32 readPtr; // message id of last message read

drivers/gpu/drm/nouveau/nvkm/subdev/gsp/r535.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,13 @@ r535_gsp_msg_post_event(void *priv, u32 fn, void *repv, u32 repc)
13771377
return 0;
13781378
}
13791379

1380+
/**
1381+
* r535_gsp_msg_run_cpu_sequencer() -- process I/O commands from the GSP
1382+
*
1383+
* The GSP sequencer is a list of I/O commands that the GSP can send to
1384+
* the driver to perform for various purposes. The most common usage is to
1385+
* perform a special mid-initialization reset.
1386+
*/
13801387
static int
13811388
r535_gsp_msg_run_cpu_sequencer(void *priv, u32 fn, void *repv, u32 repc)
13821389
{
@@ -1716,6 +1723,23 @@ r535_gsp_libos_id8(const char *name)
17161723
return id;
17171724
}
17181725

1726+
/**
1727+
* create_pte_array() - creates a PTE array of a physically contiguous buffer
1728+
* @ptes: pointer to the array
1729+
* @addr: base address of physically contiguous buffer (GSP_PAGE_SIZE aligned)
1730+
* @size: size of the buffer
1731+
*
1732+
* GSP-RM sometimes expects physically-contiguous buffers to have an array of
1733+
* "PTEs" for each page in that buffer. Although in theory that allows for
1734+
* the buffer to be physically discontiguous, GSP-RM does not currently
1735+
* support that.
1736+
*
1737+
* In this case, the PTEs are DMA addresses of each page of the buffer. Since
1738+
* the buffer is physically contiguous, calculating all the PTEs is simple
1739+
* math.
1740+
*
1741+
* See memdescGetPhysAddrsForGpu()
1742+
*/
17191743
static void create_pte_array(u64 *ptes, dma_addr_t addr, size_t size)
17201744
{
17211745
unsigned int num_pages = DIV_ROUND_UP_ULL(size, GSP_PAGE_SIZE);
@@ -1725,6 +1749,35 @@ static void create_pte_array(u64 *ptes, dma_addr_t addr, size_t size)
17251749
ptes[i] = (u64)addr + (i << GSP_PAGE_SHIFT);
17261750
}
17271751

1752+
/**
1753+
* r535_gsp_libos_init() -- create the libos arguments structure
1754+
*
1755+
* The logging buffers are byte queues that contain encoded printf-like
1756+
* messages from GSP-RM. They need to be decoded by a special application
1757+
* that can parse the buffers.
1758+
*
1759+
* The 'loginit' buffer contains logs from early GSP-RM init and
1760+
* exception dumps. The 'logrm' buffer contains the subsequent logs. Both are
1761+
* written to directly by GSP-RM and can be any multiple of GSP_PAGE_SIZE.
1762+
*
1763+
* The physical address map for the log buffer is stored in the buffer
1764+
* itself, starting with offset 1. Offset 0 contains the "put" pointer.
1765+
*
1766+
* The GSP only understands 4K pages (GSP_PAGE_SIZE), so even if the kernel is
1767+
* configured for a larger page size (e.g. 64K pages), we need to give
1768+
* the GSP an array of 4K pages. Fortunately, since the buffer is
1769+
* physically contiguous, it's simple math to calculate the addresses.
1770+
*
1771+
* The buffers must be a multiple of GSP_PAGE_SIZE. GSP-RM also currently
1772+
* ignores the @kind field for LOGINIT, LOGINTR, and LOGRM, but expects the
1773+
* buffers to be physically contiguous anyway.
1774+
*
1775+
* The memory allocated for the arguments must remain until the GSP sends the
1776+
* init_done RPC.
1777+
*
1778+
* See _kgspInitLibosLoggingStructures (allocates memory for buffers)
1779+
* See kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array)
1780+
*/
17281781
static int
17291782
r535_gsp_libos_init(struct nvkm_gsp *gsp)
17301783
{
@@ -1835,6 +1888,35 @@ nvkm_gsp_radix3_dtor(struct nvkm_gsp *gsp, struct nvkm_gsp_radix3 *rx3)
18351888
nvkm_gsp_mem_dtor(gsp, &rx3->mem[i]);
18361889
}
18371890

1891+
/**
1892+
* nvkm_gsp_radix3_sg - build a radix3 table from a S/G list
1893+
*
1894+
* The GSP uses a three-level page table, called radix3, to map the firmware.
1895+
* Each 64-bit "pointer" in the table is either the bus address of an entry in
1896+
* the next table (for levels 0 and 1) or the bus address of the next page in
1897+
* the GSP firmware image itself.
1898+
*
1899+
* Level 0 contains a single entry in one page that points to the first page
1900+
* of level 1.
1901+
*
1902+
* Level 1, since it's also only one page in size, contains up to 512 entries,
1903+
* one for each page in Level 2.
1904+
*
1905+
* Level 2 can be up to 512 pages in size, and each of those entries points to
1906+
* the next page of the firmware image. Since there can be up to 512*512
1907+
* pages, that limits the size of the firmware to 512*512*GSP_PAGE_SIZE = 1GB.
1908+
*
1909+
* Internally, the GSP has its window into system memory, but the base
1910+
* physical address of the aperture is not 0. In fact, it varies depending on
1911+
* the GPU architecture. Since the GPU is a PCI device, this window is
1912+
* accessed via DMA and is therefore bound by IOMMU translation. The end
1913+
* result is that GSP-RM must translate the bus addresses in the table to GSP
1914+
* physical addresses. All this should happen transparently.
1915+
*
1916+
* Returns 0 on success, or negative error code
1917+
*
1918+
* See kgspCreateRadix3_IMPL
1919+
*/
18381920
static int
18391921
nvkm_gsp_radix3_sg(struct nvkm_device *device, struct sg_table *sgt, u64 size,
18401922
struct nvkm_gsp_radix3 *rx3)

drivers/gpu/drm/nouveau/nvkm/subdev/mmu/vmmtu102.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ tu102_vmm_flush(struct nvkm_vmm *vmm, int depth)
3131

3232
type |= 0x00000001; /* PAGE_ALL */
3333
if (atomic_read(&vmm->engref[NVKM_SUBDEV_BAR]))
34-
type |= 0x00000004; /* HUB_ONLY */
34+
type |= 0x00000006; /* HUB_ONLY | ALL PDB (hack) */
3535

3636
mutex_lock(&vmm->mmu->mutex);
3737

drivers/gpu/drm/panfrost/panfrost_devfreq.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,20 @@ static void panfrost_devfreq_update_utilization(struct panfrost_devfreq *pfdevfr
2929
static int panfrost_devfreq_target(struct device *dev, unsigned long *freq,
3030
u32 flags)
3131
{
32+
struct panfrost_device *ptdev = dev_get_drvdata(dev);
3233
struct dev_pm_opp *opp;
34+
int err;
3335

3436
opp = devfreq_recommended_opp(dev, freq, flags);
3537
if (IS_ERR(opp))
3638
return PTR_ERR(opp);
3739
dev_pm_opp_put(opp);
3840

39-
return dev_pm_opp_set_rate(dev, *freq);
41+
err = dev_pm_opp_set_rate(dev, *freq);
42+
if (!err)
43+
ptdev->pfdevfreq.current_frequency = *freq;
44+
45+
return err;
4046
}
4147

4248
static void panfrost_devfreq_reset(struct panfrost_devfreq *pfdevfreq)
@@ -58,7 +64,6 @@ static int panfrost_devfreq_get_dev_status(struct device *dev,
5864
spin_lock_irqsave(&pfdevfreq->lock, irqflags);
5965

6066
panfrost_devfreq_update_utilization(pfdevfreq);
61-
pfdevfreq->current_frequency = status->current_frequency;
6267

6368
status->total_time = ktime_to_ns(ktime_add(pfdevfreq->busy_time,
6469
pfdevfreq->idle_time));
@@ -164,6 +169,14 @@ int panfrost_devfreq_init(struct panfrost_device *pfdev)
164169

165170
panfrost_devfreq_profile.initial_freq = cur_freq;
166171

172+
/*
173+
* We could wait until panfrost_devfreq_target() to set this value, but
174+
* since the simple_ondemand governor works asynchronously, there's a
175+
* chance by the time someone opens the device's fdinfo file, current
176+
* frequency hasn't been updated yet, so let's just do an early set.
177+
*/
178+
pfdevfreq->current_frequency = cur_freq;
179+
167180
/*
168181
* Set the recommend OPP this will enable and configure the regulator
169182
* if any and will avoid a switch off by regulator_late_cleanup()

drivers/gpu/drm/panfrost/panfrost_gem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static enum drm_gem_object_status panfrost_gem_status(struct drm_gem_object *obj
200200
struct panfrost_gem_object *bo = to_panfrost_bo(obj);
201201
enum drm_gem_object_status res = 0;
202202

203-
if (bo->base.pages)
203+
if (bo->base.base.import_attach || bo->base.pages)
204204
res |= DRM_GEM_OBJECT_RESIDENT;
205205

206206
if (bo->base.madv == PANFROST_MADV_DONTNEED)

include/drm/drm_atomic_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
9797

9898
int drm_atomic_helper_prepare_planes(struct drm_device *dev,
9999
struct drm_atomic_state *state);
100+
void drm_atomic_helper_unprepare_planes(struct drm_device *dev,
101+
struct drm_atomic_state *state);
100102

101103
#define DRM_PLANE_COMMIT_ACTIVE_ONLY BIT(0)
102104
#define DRM_PLANE_COMMIT_NO_DISABLE_AFTER_MODESET BIT(1)

0 commit comments

Comments
 (0)