xref: /openbsd/sys/dev/pci/drm/amd/amdxcp/amdgpu_xcp_drv.c (revision f005ef32)
1*f005ef32Sjsg /*
2*f005ef32Sjsg  * Copyright 2023 Advanced Micro Devices, Inc.
3*f005ef32Sjsg  *
4*f005ef32Sjsg  * Permission is hereby granted, free of charge, to any person obtaining a
5*f005ef32Sjsg  * copy of this software and associated documentation files (the "Software"),
6*f005ef32Sjsg  * to deal in the Software without restriction, including without limitation
7*f005ef32Sjsg  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*f005ef32Sjsg  * and/or sell copies of the Software, and to permit persons to whom the
9*f005ef32Sjsg  * Software is furnished to do so, subject to the following conditions:
10*f005ef32Sjsg  *
11*f005ef32Sjsg  * The above copyright notice and this permission notice shall be included in
12*f005ef32Sjsg  * all copies or substantial portions of the Software.
13*f005ef32Sjsg  *
14*f005ef32Sjsg  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*f005ef32Sjsg  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*f005ef32Sjsg  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17*f005ef32Sjsg  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18*f005ef32Sjsg  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19*f005ef32Sjsg  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20*f005ef32Sjsg  * OTHER DEALINGS IN THE SOFTWARE.
21*f005ef32Sjsg  *
22*f005ef32Sjsg  */
23*f005ef32Sjsg 
24*f005ef32Sjsg #include <linux/init.h>
25*f005ef32Sjsg #include <linux/module.h>
26*f005ef32Sjsg #include <linux/platform_device.h>
27*f005ef32Sjsg 
28*f005ef32Sjsg #include <drm/drm_drv.h>
29*f005ef32Sjsg 
30*f005ef32Sjsg #include "amdgpu_xcp_drv.h"
31*f005ef32Sjsg 
32*f005ef32Sjsg #define MAX_XCP_PLATFORM_DEVICE 64
33*f005ef32Sjsg 
34*f005ef32Sjsg struct xcp_device {
35*f005ef32Sjsg 	struct drm_device drm;
36*f005ef32Sjsg 	struct platform_device *pdev;
37*f005ef32Sjsg };
38*f005ef32Sjsg 
39*f005ef32Sjsg static const struct drm_driver amdgpu_xcp_driver = {
40*f005ef32Sjsg 	.driver_features = DRIVER_GEM | DRIVER_RENDER,
41*f005ef32Sjsg 	.name = "amdgpu_xcp_drv",
42*f005ef32Sjsg 	.major = 1,
43*f005ef32Sjsg 	.minor = 0,
44*f005ef32Sjsg };
45*f005ef32Sjsg 
46*f005ef32Sjsg static int pdev_num;
47*f005ef32Sjsg static struct xcp_device *xcp_dev[MAX_XCP_PLATFORM_DEVICE];
48*f005ef32Sjsg 
amdgpu_xcp_drm_dev_alloc(struct drm_device ** ddev)49*f005ef32Sjsg int amdgpu_xcp_drm_dev_alloc(struct drm_device **ddev)
50*f005ef32Sjsg {
51*f005ef32Sjsg 	struct platform_device *pdev;
52*f005ef32Sjsg 	struct xcp_device *pxcp_dev;
53*f005ef32Sjsg 	int ret;
54*f005ef32Sjsg 
55*f005ef32Sjsg 	if (pdev_num >= MAX_XCP_PLATFORM_DEVICE)
56*f005ef32Sjsg 		return -ENODEV;
57*f005ef32Sjsg 
58*f005ef32Sjsg 	STUB();
59*f005ef32Sjsg 	return -ENOSYS;
60*f005ef32Sjsg #ifdef notyet
61*f005ef32Sjsg 
62*f005ef32Sjsg 	pdev = platform_device_register_simple("amdgpu_xcp", pdev_num, NULL, 0);
63*f005ef32Sjsg 	if (IS_ERR(pdev))
64*f005ef32Sjsg 		return PTR_ERR(pdev);
65*f005ef32Sjsg 
66*f005ef32Sjsg 	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {
67*f005ef32Sjsg 		ret = -ENOMEM;
68*f005ef32Sjsg 		goto out_unregister;
69*f005ef32Sjsg 	}
70*f005ef32Sjsg 
71*f005ef32Sjsg 	pxcp_dev = devm_drm_dev_alloc(&pdev->dev, &amdgpu_xcp_driver, struct xcp_device, drm);
72*f005ef32Sjsg 	if (IS_ERR(pxcp_dev)) {
73*f005ef32Sjsg 		ret = PTR_ERR(pxcp_dev);
74*f005ef32Sjsg 		goto out_devres;
75*f005ef32Sjsg 	}
76*f005ef32Sjsg 
77*f005ef32Sjsg 	xcp_dev[pdev_num] = pxcp_dev;
78*f005ef32Sjsg 	xcp_dev[pdev_num]->pdev = pdev;
79*f005ef32Sjsg 	*ddev = &pxcp_dev->drm;
80*f005ef32Sjsg 	pdev_num++;
81*f005ef32Sjsg 
82*f005ef32Sjsg 	return 0;
83*f005ef32Sjsg 
84*f005ef32Sjsg out_devres:
85*f005ef32Sjsg 	devres_release_group(&pdev->dev, NULL);
86*f005ef32Sjsg out_unregister:
87*f005ef32Sjsg 	platform_device_unregister(pdev);
88*f005ef32Sjsg 
89*f005ef32Sjsg 	return ret;
90*f005ef32Sjsg #endif
91*f005ef32Sjsg }
92*f005ef32Sjsg EXPORT_SYMBOL(amdgpu_xcp_drm_dev_alloc);
93*f005ef32Sjsg 
amdgpu_xcp_drv_release(void)94*f005ef32Sjsg void amdgpu_xcp_drv_release(void)
95*f005ef32Sjsg {
96*f005ef32Sjsg 	STUB();
97*f005ef32Sjsg #ifdef notyet
98*f005ef32Sjsg 	for (--pdev_num; pdev_num >= 0; --pdev_num) {
99*f005ef32Sjsg 		devres_release_group(&xcp_dev[pdev_num]->pdev->dev, NULL);
100*f005ef32Sjsg 		platform_device_unregister(xcp_dev[pdev_num]->pdev);
101*f005ef32Sjsg 		xcp_dev[pdev_num]->pdev = NULL;
102*f005ef32Sjsg 		xcp_dev[pdev_num] = NULL;
103*f005ef32Sjsg 	}
104*f005ef32Sjsg 	pdev_num = 0;
105*f005ef32Sjsg #endif
106*f005ef32Sjsg }
107*f005ef32Sjsg EXPORT_SYMBOL(amdgpu_xcp_drv_release);
108*f005ef32Sjsg 
amdgpu_xcp_drv_exit(void)109*f005ef32Sjsg static void __exit amdgpu_xcp_drv_exit(void)
110*f005ef32Sjsg {
111*f005ef32Sjsg 	amdgpu_xcp_drv_release();
112*f005ef32Sjsg }
113*f005ef32Sjsg 
114*f005ef32Sjsg module_exit(amdgpu_xcp_drv_exit);
115*f005ef32Sjsg 
116*f005ef32Sjsg MODULE_AUTHOR("AMD linux driver team");
117*f005ef32Sjsg MODULE_DESCRIPTION("AMD XCP PLATFORM DEVICES");
118*f005ef32Sjsg MODULE_LICENSE("GPL and additional rights");
119