11.3Sriastrad/* $NetBSD: drm_pci_busid.c,v 1.3 2022/07/23 08:45:03 riastradh Exp $ */ 21.1Sriastrad 31.1Sriastrad/*- 41.1Sriastrad * Copyright (c) 2020 The NetBSD Foundation, Inc. 51.1Sriastrad * All rights reserved. 61.1Sriastrad * 71.1Sriastrad * Redistribution and use in source and binary forms, with or without 81.1Sriastrad * modification, are permitted provided that the following conditions 91.1Sriastrad * are met: 101.1Sriastrad * 1. Redistributions of source code must retain the above copyright 111.1Sriastrad * notice, this list of conditions and the following disclaimer. 121.1Sriastrad * 2. Redistributions in binary form must reproduce the above copyright 131.1Sriastrad * notice, this list of conditions and the following disclaimer in the 141.1Sriastrad * documentation and/or other materials provided with the distribution. 151.1Sriastrad * 161.1Sriastrad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 171.1Sriastrad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 181.1Sriastrad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 191.1Sriastrad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 201.1Sriastrad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 211.1Sriastrad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 221.1Sriastrad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 231.1Sriastrad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 241.1Sriastrad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 251.1Sriastrad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 261.1Sriastrad * POSSIBILITY OF SUCH DAMAGE. 271.1Sriastrad */ 281.1Sriastrad 291.1Sriastrad#include <sys/cdefs.h> 301.3Sriastrad__KERNEL_RCSID(0, "$NetBSD: drm_pci_busid.c,v 1.3 2022/07/23 08:45:03 riastradh Exp $"); 311.1Sriastrad 321.1Sriastrad#include <sys/types.h> 331.1Sriastrad#include <sys/device.h> 341.1Sriastrad#include <sys/errno.h> 351.1Sriastrad 361.1Sriastrad#include <lib/libkern/libkern.h> 371.1Sriastrad 381.1Sriastrad#include <dev/pci/pcivar.h> 391.1Sriastrad 401.1Sriastrad#include <linux/kernel.h> 411.1Sriastrad#include <linux/pci.h> 421.1Sriastrad 431.1Sriastrad#include <drm/drm_auth.h> 441.1Sriastrad#include <drm/drm_device.h> 451.1Sriastrad#include "../dist/drm/drm_internal.h" 461.1Sriastrad 471.1Sriastradint 481.1Sriastraddrm_pci_set_busid(struct drm_device *dev, struct drm_master *master) 491.1Sriastrad{ 501.1Sriastrad const struct pci_attach_args *const pa = &dev->pdev->pd_pa; 511.1Sriastrad 521.1Sriastrad KASSERT(dev_is_pci(dev->dev)); 531.1Sriastrad 541.1Sriastrad master->unique = kasprintf(GFP_KERNEL, "pci:%04x:%02x:%02x.%d", 551.3Sriastrad device_unit(device_parent(dev->dev)), 561.1Sriastrad pa->pa_bus, pa->pa_device, pa->pa_function); 571.1Sriastrad if (master->unique == NULL) 581.1Sriastrad return -ENOMEM; 591.1Sriastrad master->unique_len = strlen(master->unique); 601.1Sriastrad 611.1Sriastrad return 0; 621.1Sriastrad} 63