Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: MIT
2/* Copyright © 2025 Intel Corporation */
3
4#include <drm/drm_cache.h>
5#include <drm/drm_panic.h>
6
7#include "intel_display_types.h"
8#include "intel_fb.h"
9#include "intel_panic.h"
10#include "xe_bo.h"
11
12struct intel_panic {
13 struct page **pages;
14 int page;
15 void *vaddr;
16};
17
18static void xe_panic_kunmap(struct intel_panic *panic)
19{
20 if (panic->vaddr) {
21 drm_clflush_virt_range(panic->vaddr, PAGE_SIZE);
22 kunmap_local(panic->vaddr);
23 panic->vaddr = NULL;
24 }
25}
26
27/*
28 * The scanout buffer pages are not mapped, so for each pixel,
29 * use kmap_local_page_try_from_panic() to map the page, and write the pixel.
30 * Try to keep the map from the previous pixel, to avoid too much map/unmap.
31 */
32static void xe_panic_page_set_pixel(struct drm_scanout_buffer *sb, unsigned int x,
33 unsigned int y, u32 color)
34{
35 struct intel_framebuffer *fb = (struct intel_framebuffer *)sb->private;
36 struct intel_panic *panic = fb->panic;
37 struct xe_bo *bo = gem_to_xe_bo(intel_fb_bo(&fb->base));
38 unsigned int new_page;
39 unsigned int offset;
40
41 if (fb->panic_tiling)
42 offset = fb->panic_tiling(sb->width, x, y);
43 else
44 offset = y * sb->pitch[0] + x * sb->format->cpp[0];
45
46 new_page = offset >> PAGE_SHIFT;
47 offset = offset % PAGE_SIZE;
48 if (new_page != panic->page) {
49 xe_panic_kunmap(panic);
50 panic->page = new_page;
51 panic->vaddr = ttm_bo_kmap_try_from_panic(&bo->ttm,
52 panic->page);
53 }
54 if (panic->vaddr) {
55 u32 *pix = panic->vaddr + offset;
56 *pix = color;
57 }
58}
59
60struct intel_panic *intel_panic_alloc(void)
61{
62 struct intel_panic *panic;
63
64 panic = kzalloc(sizeof(*panic), GFP_KERNEL);
65
66 return panic;
67}
68
69int intel_panic_setup(struct intel_panic *panic, struct drm_scanout_buffer *sb)
70{
71 panic->page = -1;
72 sb->set_pixel = xe_panic_page_set_pixel;
73 return 0;
74}
75
76void intel_panic_finish(struct intel_panic *panic)
77{
78 xe_panic_kunmap(panic);
79 panic->page = -1;
80}