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