Skip to content

Commit b8592b4

Browse files
leo-sunli1alexdeucher
authored andcommitted
drm/amd/display: Initial documentation for AMDgpu DC
[Why] Documentation is helpful for the community to understand our code. This change does some high-level documentation of some DM interfaces with DRM, and the amdgpu base driver. [How] An entry for AMDgpu DC has been added to Documentation/gpu/drivers.rst TOC. amdgpu-dc.rst is created to pull in inline doc-strings, which: - Provides an overview for "What is DM?" - Documents AMDgpu DM lifecyle - Documents IRQ management - Documents atomic_check and commit_tail interfaces Signed-off-by: Leo Li <sunpeng.li@amd.com> Reviewed-by: David Francis <David.Francis@amd.com> Acked-by: Leo Li <sunpeng.li@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 4f71291 commit b8592b4

5 files changed

Lines changed: 320 additions & 41 deletions

File tree

‎Documentation/gpu/amdgpu-dc.rst‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
===================================
2+
drm/amd/display - Display Core (DC)
3+
===================================
4+
5+
*placeholder - general description of supported platforms, what dc is, etc.*
6+
7+
Because it is partially shared with other operating systems, the Display Core
8+
Driver is divided in two pieces.
9+
10+
1. **Display Core (DC)** contains the OS-agnostic components. Things like
11+
hardware programming and resource management are handled here.
12+
2. **Display Manager (DM)** contains the OS-dependent components. Hooks to the
13+
amdgpu base driver and DRM are implemented here.
14+
15+
It doesn't help that the entire package is frequently referred to as DC. But
16+
with the context in mind, it should be clear.
17+
18+
When CONFIG_DRM_AMD_DC is enabled, DC will be initialized by default for
19+
supported ASICs. To force disable, set `amdgpu.dc=0` on kernel command line.
20+
Likewise, to force enable on unsupported ASICs, set `amdgpu.dc=1`.
21+
22+
To determine if DC is loaded, search dmesg for the following entry:
23+
24+
``Display Core initialized with <version number here>``
25+
26+
AMDgpu Display Manager
27+
======================
28+
29+
.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
30+
:doc: overview
31+
32+
.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
33+
:internal:
34+
35+
Lifecycle
36+
---------
37+
38+
.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
39+
:doc: DM Lifecycle
40+
41+
.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
42+
:functions: dm_hw_init dm_hw_fini
43+
44+
Interrupts
45+
----------
46+
47+
.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c
48+
:doc: overview
49+
50+
.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c
51+
:internal:
52+
53+
.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
54+
:functions: register_hpd_handlers dm_crtc_high_irq dm_pflip_high_irq
55+
56+
Atomic Implementation
57+
---------------------
58+
59+
.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
60+
:doc: atomic
61+
62+
.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
63+
:functions: amdgpu_dm_atomic_check amdgpu_dm_atomic_commit_tail
64+
65+
Display Core
66+
============
67+
68+
**WIP**

‎Documentation/gpu/drivers.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ GPU Driver Documentation
55
.. toctree::
66

77
amdgpu
8+
amdgpu-dc
89
i915
910
meson
1011
pl111

‎drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c‎

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@
7676
#define FIRMWARE_RAVEN_DMCU "amdgpu/raven_dmcu.bin"
7777
MODULE_FIRMWARE(FIRMWARE_RAVEN_DMCU);
7878

79+
/**
80+
* DOC: overview
81+
*
82+
* The AMDgpu display manager, **amdgpu_dm** (or even simpler,
83+
* **dm**) sits between DRM and DC. It acts as a liason, converting DRM
84+
* requests into DC requests, and DC responses into DRM responses.
85+
*
86+
* The root control structure is &struct amdgpu_display_manager.
87+
*/
88+
7989
/* basic init/fini API */
8090
static int amdgpu_dm_init(struct amdgpu_device *adev);
8191
static void amdgpu_dm_fini(struct amdgpu_device *adev);
@@ -379,11 +389,6 @@ static void amdgpu_dm_fbc_init(struct drm_connector *connector)
379389

380390
}
381391

382-
/*
383-
* Init display KMS
384-
*
385-
* Returns 0 on success
386-
*/
387392
static int amdgpu_dm_init(struct amdgpu_device *adev)
388393
{
389394
struct dc_init_data init_data;
@@ -660,6 +665,26 @@ static void s3_handle_mst(struct drm_device *dev, bool suspend)
660665
drm_modeset_unlock(&dev->mode_config.connection_mutex);
661666
}
662667

668+
/**
669+
* dm_hw_init() - Initialize DC device
670+
* @handle: The base driver device containing the amdpgu_dm device.
671+
*
672+
* Initialize the &struct amdgpu_display_manager device. This involves calling
673+
* the initializers of each DM component, then populating the struct with them.
674+
*
675+
* Although the function implies hardware initialization, both hardware and
676+
* software are initialized here. Splitting them out to their relevant init
677+
* hooks is a future TODO item.
678+
*
679+
* Some notable things that are initialized here:
680+
*
681+
* - Display Core, both software and hardware
682+
* - DC modules that we need (freesync and color management)
683+
* - DRM software states
684+
* - Interrupt sources and handlers
685+
* - Vblank support
686+
* - Debug FS entries, if enabled
687+
*/
663688
static int dm_hw_init(void *handle)
664689
{
665690
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -670,6 +695,14 @@ static int dm_hw_init(void *handle)
670695
return 0;
671696
}
672697

698+
/**
699+
* dm_hw_fini() - Teardown DC device
700+
* @handle: The base driver device containing the amdpgu_dm device.
701+
*
702+
* Teardown components within &struct amdgpu_display_manager that require
703+
* cleanup. This involves cleaning up the DRM device, DC, and any modules that
704+
* were loaded. Also flush IRQ workqueues and disable them.
705+
*/
673706
static int dm_hw_fini(void *handle)
674707
{
675708
struct amdgpu_device *adev = (struct amdgpu_device *)handle;
@@ -895,6 +928,16 @@ static int dm_resume(void *handle)
895928
return ret;
896929
}
897930

931+
/**
932+
* DOC: DM Lifecycle
933+
*
934+
* DM (and consequently DC) is registered in the amdgpu base driver as a IP
935+
* block. When CONFIG_DRM_AMD_DC is enabled, the DM device IP block is added to
936+
* the base driver's device list to be initialized and torn down accordingly.
937+
*
938+
* The functions to do so are provided as hooks in &struct amd_ip_funcs.
939+
*/
940+
898941
static const struct amd_ip_funcs amdgpu_dm_funcs = {
899942
.name = "dm",
900943
.early_init = dm_early_init,
@@ -962,6 +1005,12 @@ dm_atomic_state_alloc_free(struct drm_atomic_state *state)
9621005
kfree(dm_state);
9631006
}
9641007

1008+
/**
1009+
* DOC: atomic
1010+
*
1011+
* *WIP*
1012+
*/
1013+
9651014
static const struct drm_mode_config_funcs amdgpu_dm_mode_funcs = {
9661015
.fb_create = amdgpu_display_user_framebuffer_create,
9671016
.output_poll_changed = drm_fb_helper_output_poll_changed,
@@ -4542,6 +4591,14 @@ static int amdgpu_dm_atomic_commit(struct drm_device *dev,
45424591
/*TODO Handle EINTR, reenable IRQ*/
45434592
}
45444593

4594+
/**
4595+
* amdgpu_dm_atomic_commit_tail() - AMDgpu DM's commit tail implementation.
4596+
* @state: The atomic state to commit
4597+
*
4598+
* This will tell DC to commit the constructed DC state from atomic_check,
4599+
* programming the hardware. Any failures here implies a hardware failure, since
4600+
* atomic check should have filtered anything non-kosher.
4601+
*/
45454602
static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state)
45464603
{
45474604
struct drm_device *dev = state->dev;
@@ -5394,6 +5451,31 @@ enum surface_update_type dm_determine_update_type_for_commit(struct dc *dc, stru
53945451
return update_type;
53955452
}
53965453

5454+
/**
5455+
* amdgpu_dm_atomic_check() - Atomic check implementation for AMDgpu DM.
5456+
* @dev: The DRM device
5457+
* @state: The atomic state to commit
5458+
*
5459+
* Validate that the given atomic state is programmable by DC into hardware.
5460+
* This involves constructing a &struct dc_state reflecting the new hardware
5461+
* state we wish to commit, then querying DC to see if it is programmable. It's
5462+
* important not to modify the existing DC state. Otherwise, atomic_check
5463+
* may unexpectedly commit hardware changes.
5464+
*
5465+
* When validating the DC state, it's important that the right locks are
5466+
* acquired. For full updates case which removes/adds/updates streams on one
5467+
* CRTC while flipping on another CRTC, acquiring global lock will guarantee
5468+
* that any such full update commit will wait for completion of any outstanding
5469+
* flip using DRMs synchronization events. See
5470+
* dm_determine_update_type_for_commit()
5471+
*
5472+
* Note that DM adds the affected connectors for all CRTCs in state, when that
5473+
* might not seem necessary. This is because DC stream creation requires the
5474+
* DC sink, which is tied to the DRM connector state. Cleaning this up should
5475+
* be possible but non-trivial - a possible TODO item.
5476+
*
5477+
* Return: -Error code if validation failed.
5478+
*/
53975479
static int amdgpu_dm_atomic_check(struct drm_device *dev,
53985480
struct drm_atomic_state *state)
53995481
{
@@ -5496,15 +5578,6 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
54965578
lock_and_validation_needed = true;
54975579
}
54985580

5499-
/*
5500-
* For full updates case when
5501-
* removing/adding/updating streams on one CRTC while flipping
5502-
* on another CRTC,
5503-
* acquiring global lock will guarantee that any such full
5504-
* update commit
5505-
* will wait for completion of any outstanding flip using DRMs
5506-
* synchronization events.
5507-
*/
55085581
update_type = dm_determine_update_type_for_commit(dc, state);
55095582

55105583
if (overall_update_type < update_type)

‎drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h‎

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,49 +59,100 @@ struct common_irq_params {
5959
enum dc_irq_source irq_src;
6060
};
6161

62+
/**
63+
* struct irq_list_head - Linked-list for low context IRQ handlers.
64+
*
65+
* @head: The list_head within &struct handler_data
66+
* @work: A work_struct containing the deferred handler work
67+
*/
6268
struct irq_list_head {
6369
struct list_head head;
6470
/* In case this interrupt needs post-processing, 'work' will be queued*/
6571
struct work_struct work;
6672
};
6773

74+
/**
75+
* struct dm_compressor_info - Buffer info used by frame buffer compression
76+
* @cpu_addr: MMIO cpu addr
77+
* @bo_ptr: Pointer to the buffer object
78+
* @gpu_addr: MMIO gpu addr
79+
*/
6880
struct dm_comressor_info {
6981
void *cpu_addr;
7082
struct amdgpu_bo *bo_ptr;
7183
uint64_t gpu_addr;
7284
};
7385

86+
/**
87+
* struct amdgpu_display_manager - Central amdgpu display manager device
88+
*
89+
* @dc: Display Core control structure
90+
* @adev: AMDGPU base driver structure
91+
* @ddev: DRM base driver structure
92+
* @display_indexes_num: Max number of display streams supported
93+
* @irq_handler_list_table_lock: Synchronizes access to IRQ tables
94+
* @backlight_dev: Backlight control device
95+
* @cached_state: Caches device atomic state for suspend/resume
96+
* @compressor: Frame buffer compression buffer. See &struct dm_comressor_info
97+
*/
7498
struct amdgpu_display_manager {
99+
75100
struct dc *dc;
101+
102+
/**
103+
* @cgs_device:
104+
*
105+
* The Common Graphics Services device. It provides an interface for
106+
* accessing registers.
107+
*/
76108
struct cgs_device *cgs_device;
77109

78-
struct amdgpu_device *adev; /*AMD base driver*/
79-
struct drm_device *ddev; /*DRM base driver*/
110+
struct amdgpu_device *adev;
111+
struct drm_device *ddev;
80112
u16 display_indexes_num;
81113

82-
/*
83-
* 'irq_source_handler_table' holds a list of handlers
84-
* per (DAL) IRQ source.
114+
/**
115+
* @irq_handler_list_low_tab:
116+
*
117+
* Low priority IRQ handler table.
85118
*
86-
* Each IRQ source may need to be handled at different contexts.
87-
* By 'context' we mean, for example:
88-
* - The ISR context, which is the direct interrupt handler.
89-
* - The 'deferred' context - this is the post-processing of the
90-
* interrupt, but at a lower priority.
119+
* It is a n*m table consisting of n IRQ sources, and m handlers per IRQ
120+
* source. Low priority IRQ handlers are deferred to a workqueue to be
121+
* processed. Hence, they can sleep.
91122
*
92123
* Note that handlers are called in the same order as they were
93124
* registered (FIFO).
94125
*/
95126
struct irq_list_head irq_handler_list_low_tab[DAL_IRQ_SOURCES_NUMBER];
127+
128+
/**
129+
* @irq_handler_list_high_tab:
130+
*
131+
* High priority IRQ handler table.
132+
*
133+
* It is a n*m table, same as &irq_handler_list_low_tab. However,
134+
* handlers in this table are not deferred and are called immediately.
135+
*/
96136
struct list_head irq_handler_list_high_tab[DAL_IRQ_SOURCES_NUMBER];
97137

138+
/**
139+
* @pflip_params:
140+
*
141+
* Page flip IRQ parameters, passed to registered handlers when
142+
* triggered.
143+
*/
98144
struct common_irq_params
99145
pflip_params[DC_IRQ_SOURCE_PFLIP_LAST - DC_IRQ_SOURCE_PFLIP_FIRST + 1];
100146

147+
/**
148+
* @vblank_params:
149+
*
150+
* Vertical blanking IRQ parameters, passed to registered handlers when
151+
* triggered.
152+
*/
101153
struct common_irq_params
102154
vblank_params[DC_IRQ_SOURCE_VBLANK6 - DC_IRQ_SOURCE_VBLANK1 + 1];
103155

104-
/* this spin lock synchronizes access to 'irq_handler_list_table' */
105156
spinlock_t irq_handler_list_table_lock;
106157

107158
struct backlight_device *backlight_dev;
@@ -110,9 +161,6 @@ struct amdgpu_display_manager {
110161

111162
struct mod_freesync *freesync_module;
112163

113-
/**
114-
* Caches device atomic state for suspend/resume
115-
*/
116164
struct drm_atomic_state *cached_state;
117165

118166
struct dm_comressor_info compressor;

0 commit comments

Comments
 (0)