Path: blob/master/drivers/gpu/drm/amd/amdxcp/amdgpu_xcp_drv.c
26517 views
/*1* Copyright 2023 Advanced Micro Devices, Inc.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice shall be included in11* all copies or substantial portions of the Software.12*13* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL16* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR17* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,18* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR19* OTHER DEALINGS IN THE SOFTWARE.20*21*/2223#include <linux/export.h>24#include <linux/init.h>25#include <linux/module.h>26#include <linux/platform_device.h>2728#include <drm/drm_drv.h>2930#include "amdgpu_xcp_drv.h"3132#define MAX_XCP_PLATFORM_DEVICE 643334struct xcp_device {35struct drm_device drm;36struct platform_device *pdev;37};3839static 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};4546static int8_t pdev_num;47static struct xcp_device *xcp_dev[MAX_XCP_PLATFORM_DEVICE];4849int amdgpu_xcp_drm_dev_alloc(struct drm_device **ddev)50{51struct platform_device *pdev;52struct xcp_device *pxcp_dev;53char dev_name[20];54int ret;5556if (pdev_num >= MAX_XCP_PLATFORM_DEVICE)57return -ENODEV;5859snprintf(dev_name, sizeof(dev_name), "amdgpu_xcp_%d", pdev_num);60pdev = platform_device_register_simple(dev_name, -1, NULL, 0);61if (IS_ERR(pdev))62return PTR_ERR(pdev);6364if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {65ret = -ENOMEM;66goto out_unregister;67}6869pxcp_dev = devm_drm_dev_alloc(&pdev->dev, &amdgpu_xcp_driver, struct xcp_device, drm);70if (IS_ERR(pxcp_dev)) {71ret = PTR_ERR(pxcp_dev);72goto out_devres;73}7475xcp_dev[pdev_num] = pxcp_dev;76xcp_dev[pdev_num]->pdev = pdev;77*ddev = &pxcp_dev->drm;78pdev_num++;7980return 0;8182out_devres:83devres_release_group(&pdev->dev, NULL);84out_unregister:85platform_device_unregister(pdev);8687return ret;88}89EXPORT_SYMBOL(amdgpu_xcp_drm_dev_alloc);9091void amdgpu_xcp_drv_release(void)92{93for (--pdev_num; pdev_num >= 0; --pdev_num) {94struct platform_device *pdev = xcp_dev[pdev_num]->pdev;9596devres_release_group(&pdev->dev, NULL);97platform_device_unregister(pdev);98xcp_dev[pdev_num] = NULL;99}100pdev_num = 0;101}102EXPORT_SYMBOL(amdgpu_xcp_drv_release);103104static void __exit amdgpu_xcp_drv_exit(void)105{106amdgpu_xcp_drv_release();107}108109module_exit(amdgpu_xcp_drv_exit);110111MODULE_AUTHOR("AMD linux driver team");112MODULE_DESCRIPTION("AMD XCP PLATFORM DEVICES");113MODULE_LICENSE("GPL and additional rights");114115116