xref: /linux/drivers/gpu/drm/xe/xe_sysctrl.c (revision 02eca6edcb324bc37495930c344e235a90f42d72)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright © 2026 Intel Corporation
4  */
5 
6 #include <linux/device.h>
7 #include <linux/mutex.h>
8 
9 #include <drm/drm_managed.h>
10 
11 #include "regs/xe_sysctrl_regs.h"
12 #include "xe_device.h"
13 #include "xe_mmio.h"
14 #include "xe_soc_remapper.h"
15 #include "xe_sysctrl.h"
16 #include "xe_sysctrl_mailbox.h"
17 #include "xe_sysctrl_types.h"
18 
19 /**
20  * DOC: System Controller (sysctrl)
21  *
22  * System Controller (sysctrl) is a firmware-managed entity on Intel dGPUs
23  * responsible for selected low-level platform management functions.
24  * Communication between driver and System Controller is performed
25  * via a mailbox interface, enabling command and response exchange.
26  *
27  * This module provides initialization and support code for interacting
28  * with System Controller through the mailbox interface.
29  */
30 static void sysctrl_fini(void *arg)
31 {
32 	struct xe_device *xe = arg;
33 
34 	xe->soc_remapper.set_sysctrl_region(xe, 0);
35 }
36 
37 /**
38  * xe_sysctrl_init() - Initialize System Controller subsystem
39  * @xe: xe device instance
40  *
41  * Entry point for System Controller initialization, called from xe_device_probe.
42  * This function checks platform support and initializes the system controller.
43  *
44  * Return: 0 on success, error code on failure
45  */
46 int xe_sysctrl_init(struct xe_device *xe)
47 {
48 	struct xe_tile *tile = xe_device_get_root_tile(xe);
49 	struct xe_sysctrl *sc = &xe->sc;
50 	int ret;
51 
52 	if (!xe->info.has_soc_remapper_sysctrl)
53 		return 0;
54 
55 	if (!xe->info.has_sysctrl)
56 		return 0;
57 
58 	xe->soc_remapper.set_sysctrl_region(xe, SYSCTRL_MAILBOX_INDEX);
59 
60 	ret = devm_add_action_or_reset(xe->drm.dev, sysctrl_fini, xe);
61 	if (ret)
62 		return ret;
63 
64 	sc->mmio = devm_kzalloc(xe->drm.dev, sizeof(*sc->mmio), GFP_KERNEL);
65 	if (!sc->mmio)
66 		return -ENOMEM;
67 
68 	xe_mmio_init(sc->mmio, tile, tile->mmio.regs, tile->mmio.regs_size);
69 	sc->mmio->adj_offset = SYSCTRL_BASE;
70 	sc->mmio->adj_limit = U32_MAX;
71 
72 	ret = devm_mutex_init(xe->drm.dev, &sc->cmd_lock);
73 	if (ret)
74 		return ret;
75 
76 	xe_sysctrl_mailbox_init(sc);
77 
78 	return 0;
79 }
80 
81 /**
82  * xe_sysctrl_pm_resume() - System Controller resume handler
83  * @xe: xe device instance
84  *
85  * Invoked during system resume (S3/S4 to S0) and runtime resume from D3cold.
86  * Restores SoC remapper configuration and reinitializes mailbox interface.
87  */
88 void xe_sysctrl_pm_resume(struct xe_device *xe)
89 {
90 	struct xe_sysctrl *sc = &xe->sc;
91 
92 	if (!xe->info.has_soc_remapper_sysctrl)
93 		return;
94 
95 	if (!xe->info.has_sysctrl)
96 		return;
97 
98 	xe->soc_remapper.set_sysctrl_region(xe, SYSCTRL_MAILBOX_INDEX);
99 
100 	xe_sysctrl_mailbox_init(sc);
101 }
102