Linux Audio

Check our new training course

Loading...
v6.9.4
  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	pdev = platform_device_register_simple("amdgpu_xcp", pdev_num, NULL, 0);
 
 59	if (IS_ERR(pdev))
 60		return PTR_ERR(pdev);
 61
 62	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {
 63		ret = -ENOMEM;
 64		goto out_unregister;
 65	}
 66
 67	pxcp_dev = devm_drm_dev_alloc(&pdev->dev, &amdgpu_xcp_driver, struct xcp_device, drm);
 68	if (IS_ERR(pxcp_dev)) {
 69		ret = PTR_ERR(pxcp_dev);
 70		goto out_devres;
 71	}
 72
 73	xcp_dev[pdev_num] = pxcp_dev;
 74	xcp_dev[pdev_num]->pdev = pdev;
 75	*ddev = &pxcp_dev->drm;
 76	pdev_num++;
 77
 78	return 0;
 79
 80out_devres:
 81	devres_release_group(&pdev->dev, NULL);
 82out_unregister:
 83	platform_device_unregister(pdev);
 84
 85	return ret;
 86}
 87EXPORT_SYMBOL(amdgpu_xcp_drm_dev_alloc);
 88
 89void amdgpu_xcp_drv_release(void)
 90{
 91	for (--pdev_num; pdev_num >= 0; --pdev_num) {
 92		struct platform_device *pdev = xcp_dev[pdev_num]->pdev;
 93
 94		devres_release_group(&pdev->dev, NULL);
 95		platform_device_unregister(pdev);
 96		xcp_dev[pdev_num] = NULL;
 97	}
 98	pdev_num = 0;
 99}
100EXPORT_SYMBOL(amdgpu_xcp_drv_release);
101
102static void __exit amdgpu_xcp_drv_exit(void)
103{
104	amdgpu_xcp_drv_release();
105}
106
107module_exit(amdgpu_xcp_drv_exit);
108
109MODULE_AUTHOR("AMD linux driver team");
110MODULE_DESCRIPTION("AMD XCP PLATFORM DEVICES");
111MODULE_LICENSE("GPL and additional rights");
v6.13.7
  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 int8_t 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	char dev_name[20];
 54	int ret;
 55
 56	if (pdev_num >= MAX_XCP_PLATFORM_DEVICE)
 57		return -ENODEV;
 58
 59	snprintf(dev_name, sizeof(dev_name), "amdgpu_xcp_%d", pdev_num);
 60	pdev = platform_device_register_simple(dev_name, -1, NULL, 0);
 61	if (IS_ERR(pdev))
 62		return PTR_ERR(pdev);
 63
 64	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {
 65		ret = -ENOMEM;
 66		goto out_unregister;
 67	}
 68
 69	pxcp_dev = devm_drm_dev_alloc(&pdev->dev, &amdgpu_xcp_driver, struct xcp_device, drm);
 70	if (IS_ERR(pxcp_dev)) {
 71		ret = PTR_ERR(pxcp_dev);
 72		goto out_devres;
 73	}
 74
 75	xcp_dev[pdev_num] = pxcp_dev;
 76	xcp_dev[pdev_num]->pdev = pdev;
 77	*ddev = &pxcp_dev->drm;
 78	pdev_num++;
 79
 80	return 0;
 81
 82out_devres:
 83	devres_release_group(&pdev->dev, NULL);
 84out_unregister:
 85	platform_device_unregister(pdev);
 86
 87	return ret;
 88}
 89EXPORT_SYMBOL(amdgpu_xcp_drm_dev_alloc);
 90
 91void amdgpu_xcp_drv_release(void)
 92{
 93	for (--pdev_num; pdev_num >= 0; --pdev_num) {
 94		struct platform_device *pdev = xcp_dev[pdev_num]->pdev;
 95
 96		devres_release_group(&pdev->dev, NULL);
 97		platform_device_unregister(pdev);
 98		xcp_dev[pdev_num] = NULL;
 99	}
100	pdev_num = 0;
101}
102EXPORT_SYMBOL(amdgpu_xcp_drv_release);
103
104static void __exit amdgpu_xcp_drv_exit(void)
105{
106	amdgpu_xcp_drv_release();
107}
108
109module_exit(amdgpu_xcp_drv_exit);
110
111MODULE_AUTHOR("AMD linux driver team");
112MODULE_DESCRIPTION("AMD XCP PLATFORM DEVICES");
113MODULE_LICENSE("GPL and additional rights");