drivers/gpu/drm/drm_color_mgmt.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_color_mgmt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_color_mgmt.c- Extension
.c- Size
- 28420 bytes
- Lines
- 920
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/uaccess.hdrm/drm_atomic.hdrm/drm_color_mgmt.hdrm/drm_crtc.hdrm/drm_device.hdrm/drm_drv.hdrm/drm_print.hkunit/visibility.hdrm_crtc_internal.h
Detected Declarations
function Copyrightfunction drm_crtc_enable_color_mgmtfunction drm_mode_crtc_set_gamma_sizefunction drm_crtc_supports_legacy_gammafunction drm_crtc_enable_color_mgmtfunction drm_mode_gamma_set_ioctlfunction drm_mode_gamma_get_ioctlfunction drm_plane_create_color_propertiesfunction drm_color_lut_checkfunction drm_crtc_load_gamma_888function drm_crtc_load_gamma_565_from_888function drm_crtc_load_gamma_555_from_888function fill_gamma_888function drm_crtc_fill_gamma_888function fill_gamma_565function drm_crtc_fill_gamma_565function fill_gamma_555function drm_crtc_fill_gamma_555function drm_crtc_load_palette_8function fill_palette_332function drm_crtc_fill_palette_332function fill_palette_8function drm_crtc_fill_palette_8function drm_color_lut32_checkexport drm_color_ctm_s31_32_to_qm_nexport drm_crtc_enable_color_mgmtexport drm_mode_crtc_set_gamma_sizeexport drm_plane_create_color_propertiesexport drm_color_lut_checkexport drm_crtc_load_gamma_888export drm_crtc_load_gamma_565_from_888export drm_crtc_load_gamma_555_from_888export drm_crtc_fill_gamma_888export drm_crtc_fill_gamma_565export drm_crtc_fill_gamma_555export drm_crtc_load_palette_8export drm_crtc_fill_palette_332export drm_crtc_fill_palette_8export drm_color_lut32_check
Annotated Snippet
if (tests & DRM_COLOR_LUT_EQUAL_CHANNELS) {
if (entry[i].red != entry[i].blue ||
entry[i].red != entry[i].green) {
DRM_DEBUG_KMS("All LUT entries must have equal r/g/b\n");
return -EINVAL;
}
}
if (i > 0 && tests & DRM_COLOR_LUT_NON_DECREASING) {
if (entry[i].red < entry[i - 1].red ||
entry[i].green < entry[i - 1].green ||
entry[i].blue < entry[i - 1].blue) {
DRM_DEBUG_KMS("LUT entries must never decrease.\n");
return -EINVAL;
}
}
}
return 0;
}
EXPORT_SYMBOL(drm_color_lut_check);
/*
* Gamma-LUT programming
*/
/**
* drm_crtc_load_gamma_888 - Programs gamma ramp for RGB888-like formats
* @crtc: The displaying CRTC
* @lut: The gamma ramp to program
* @set_gamma: Callback for programming the hardware gamma LUT
*
* Programs the gamma ramp specified in @lut to hardware. The input gamma
* ramp must have 256 entries per color component.
*/
void drm_crtc_load_gamma_888(struct drm_crtc *crtc, const struct drm_color_lut *lut,
drm_crtc_set_lut_func set_gamma)
{
unsigned int i;
for (i = 0; i < 256; ++i)
set_gamma(crtc, i, lut[i].red, lut[i].green, lut[i].blue);
}
EXPORT_SYMBOL(drm_crtc_load_gamma_888);
/**
* drm_crtc_load_gamma_565_from_888 - Programs gamma ramp for RGB565-like formats
* @crtc: The displaying CRTC
* @lut: The gamma ramp to program
* @set_gamma: Callback for programming the hardware gamma LUT
*
* Programs the gamma ramp specified in @lut to hardware. The input gamma
* ramp must have 256 entries per color component. The helper interpolates
* the individual color components to reduce the number of entries to 5/6/5.
*/
void drm_crtc_load_gamma_565_from_888(struct drm_crtc *crtc, const struct drm_color_lut *lut,
drm_crtc_set_lut_func set_gamma)
{
unsigned int i;
u16 r, g, b;
for (i = 0; i < 32; ++i) {
r = lut[i * 8 + i / 4].red;
g = lut[i * 4 + i / 16].green;
b = lut[i * 8 + i / 4].blue;
set_gamma(crtc, i, r, g, b);
}
/* Green has one more bit, so add padding with 0 for red and blue. */
for (i = 32; i < 64; ++i) {
g = lut[i * 4 + i / 16].green;
set_gamma(crtc, i, 0, g, 0);
}
}
EXPORT_SYMBOL(drm_crtc_load_gamma_565_from_888);
/**
* drm_crtc_load_gamma_555_from_888 - Programs gamma ramp for RGB555-like formats
* @crtc: The displaying CRTC
* @lut: The gamma ramp to program
* @set_gamma: Callback for programming the hardware gamma LUT
*
* Programs the gamma ramp specified in @lut to hardware. The input gamma
* ramp must have 256 entries per color component. The helper interpolates
* the individual color components to reduce the number of entries to 5/5/5.
*/
void drm_crtc_load_gamma_555_from_888(struct drm_crtc *crtc, const struct drm_color_lut *lut,
drm_crtc_set_lut_func set_gamma)
{
unsigned int i;
u16 r, g, b;
Annotation
- Immediate include surface: `linux/export.h`, `linux/uaccess.h`, `drm/drm_atomic.h`, `drm/drm_color_mgmt.h`, `drm/drm_crtc.h`, `drm/drm_device.h`, `drm/drm_drv.h`, `drm/drm_print.h`.
- Detected declarations: `function Copyright`, `function drm_crtc_enable_color_mgmt`, `function drm_mode_crtc_set_gamma_size`, `function drm_crtc_supports_legacy_gamma`, `function drm_crtc_enable_color_mgmt`, `function drm_mode_gamma_set_ioctl`, `function drm_mode_gamma_get_ioctl`, `function drm_plane_create_color_properties`, `function drm_color_lut_check`, `function drm_crtc_load_gamma_888`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.