Home | History | Annotate | Line # | Download | only in pci
drm_pci.c revision 1.6.4.3
      1  1.6.4.2       tls /*	$NetBSD: drm_pci.c,v 1.6.4.3 2017/12/03 11:38:00 jdolecek Exp $	*/
      2  1.6.4.2       tls 
      3  1.6.4.2       tls /*-
      4  1.6.4.2       tls  * Copyright (c) 2013 The NetBSD Foundation, Inc.
      5  1.6.4.2       tls  * All rights reserved.
      6  1.6.4.2       tls  *
      7  1.6.4.2       tls  * This code is derived from software contributed to The NetBSD Foundation
      8  1.6.4.2       tls  * by Taylor R. Campbell.
      9  1.6.4.2       tls  *
     10  1.6.4.2       tls  * Redistribution and use in source and binary forms, with or without
     11  1.6.4.2       tls  * modification, are permitted provided that the following conditions
     12  1.6.4.2       tls  * are met:
     13  1.6.4.2       tls  * 1. Redistributions of source code must retain the above copyright
     14  1.6.4.2       tls  *    notice, this list of conditions and the following disclaimer.
     15  1.6.4.2       tls  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.6.4.2       tls  *    notice, this list of conditions and the following disclaimer in the
     17  1.6.4.2       tls  *    documentation and/or other materials provided with the distribution.
     18  1.6.4.2       tls  *
     19  1.6.4.2       tls  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.6.4.2       tls  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.6.4.2       tls  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.6.4.2       tls  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.6.4.2       tls  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.6.4.2       tls  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.6.4.2       tls  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.6.4.2       tls  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.6.4.2       tls  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.6.4.2       tls  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.6.4.2       tls  * POSSIBILITY OF SUCH DAMAGE.
     30  1.6.4.2       tls  */
     31  1.6.4.2       tls 
     32  1.6.4.2       tls #include <sys/cdefs.h>
     33  1.6.4.2       tls __KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.6.4.3 2017/12/03 11:38:00 jdolecek Exp $");
     34  1.6.4.2       tls 
     35  1.6.4.2       tls #include <sys/types.h>
     36  1.6.4.2       tls #include <sys/errno.h>
     37  1.6.4.2       tls #include <sys/systm.h>
     38  1.6.4.2       tls 
     39  1.6.4.2       tls #include <dev/pci/pcivar.h>
     40  1.6.4.2       tls 
     41  1.6.4.2       tls #include <drm/drmP.h>
     42  1.6.4.2       tls 
     43  1.6.4.3  jdolecek struct drm_bus_irq_cookie {
     44  1.6.4.3  jdolecek 	pci_intr_handle_t *intr_handles;
     45  1.6.4.3  jdolecek 	void *ih_cookie;
     46  1.6.4.3  jdolecek };
     47  1.6.4.3  jdolecek 
     48  1.6.4.2       tls static int	drm_pci_get_irq(struct drm_device *);
     49  1.6.4.2       tls static int	drm_pci_irq_install(struct drm_device *,
     50  1.6.4.2       tls 		    irqreturn_t (*)(void *), int, const char *, void *,
     51  1.6.4.2       tls 		    struct drm_bus_irq_cookie **);
     52  1.6.4.2       tls static void	drm_pci_irq_uninstall(struct drm_device *,
     53  1.6.4.2       tls 		    struct drm_bus_irq_cookie *);
     54  1.6.4.2       tls static const char *
     55  1.6.4.2       tls 		drm_pci_get_name(struct drm_device *);
     56  1.6.4.2       tls static int	drm_pci_set_busid(struct drm_device *, struct drm_master *);
     57  1.6.4.2       tls static int	drm_pci_set_unique(struct drm_device *, struct drm_master *,
     58  1.6.4.2       tls 		    struct drm_unique *);
     59  1.6.4.2       tls static int	drm_pci_irq_by_busid(struct drm_device *,
     60  1.6.4.2       tls 		    struct drm_irq_busid *);
     61  1.6.4.2       tls 
     62  1.6.4.2       tls const struct drm_bus drm_pci_bus = {
     63  1.6.4.2       tls 	.bus_type = DRIVER_BUS_PCI,
     64  1.6.4.2       tls 	.get_irq = drm_pci_get_irq,
     65  1.6.4.2       tls 	.irq_install = drm_pci_irq_install,
     66  1.6.4.2       tls 	.irq_uninstall = drm_pci_irq_uninstall,
     67  1.6.4.2       tls 	.get_name = drm_pci_get_name,
     68  1.6.4.2       tls 	.set_busid = drm_pci_set_busid,
     69  1.6.4.2       tls 	.set_unique = drm_pci_set_unique,
     70  1.6.4.2       tls 	.irq_by_busid = drm_pci_irq_by_busid,
     71  1.6.4.2       tls };
     72  1.6.4.2       tls 
     73  1.6.4.2       tls static const struct pci_attach_args *
     74  1.6.4.2       tls drm_pci_attach_args(struct drm_device *dev)
     75  1.6.4.2       tls {
     76  1.6.4.2       tls 	return &dev->pdev->pd_pa;
     77  1.6.4.2       tls }
     78  1.6.4.2       tls 
     79  1.6.4.2       tls int
     80  1.6.4.2       tls drm_pci_init(struct drm_driver *driver, struct pci_driver *pdriver __unused)
     81  1.6.4.2       tls {
     82  1.6.4.2       tls 
     83  1.6.4.2       tls 	driver->bus = &drm_pci_bus;
     84  1.6.4.2       tls 	return 0;
     85  1.6.4.2       tls }
     86  1.6.4.2       tls 
     87  1.6.4.2       tls void
     88  1.6.4.2       tls drm_pci_exit(struct drm_driver *driver __unused,
     89  1.6.4.2       tls     struct pci_driver *pdriver __unused)
     90  1.6.4.2       tls {
     91  1.6.4.2       tls }
     92  1.6.4.2       tls 
     93  1.6.4.2       tls int
     94  1.6.4.2       tls drm_pci_attach(device_t self, const struct pci_attach_args *pa,
     95  1.6.4.2       tls     struct pci_dev *pdev, struct drm_driver *driver, unsigned long cookie,
     96  1.6.4.2       tls     struct drm_device **devp)
     97  1.6.4.2       tls {
     98  1.6.4.2       tls 	struct drm_device *dev;
     99  1.6.4.2       tls 	unsigned int unit;
    100  1.6.4.2       tls 	int ret;
    101  1.6.4.2       tls 
    102  1.6.4.3  jdolecek 	/* Ensure the drm agp hooks are installed.  */
    103  1.6.4.3  jdolecek 	/* XXX errno NetBSD->Linux */
    104  1.6.4.3  jdolecek 	ret = -drmkms_pci_agp_guarantee_initialized();
    105  1.6.4.3  jdolecek 	if (ret)
    106  1.6.4.3  jdolecek 		goto fail0;
    107  1.6.4.3  jdolecek 
    108  1.6.4.2       tls 	/* Initialize the Linux PCI device descriptor.  */
    109  1.6.4.2       tls 	linux_pci_dev_init(pdev, self, pa, 0);
    110  1.6.4.2       tls 
    111  1.6.4.2       tls 	/* Create a DRM device.  */
    112  1.6.4.2       tls 	dev = drm_dev_alloc(driver, self);
    113  1.6.4.2       tls 	if (dev == NULL) {
    114  1.6.4.2       tls 		ret = -ENOMEM;
    115  1.6.4.2       tls 		goto fail0;
    116  1.6.4.2       tls 	}
    117  1.6.4.2       tls 
    118  1.6.4.2       tls 	dev->pdev = pdev;
    119  1.6.4.3  jdolecek 	pdev->pd_drm_dev = dev;	/* XXX Nouveau kludge.  */
    120  1.6.4.2       tls 
    121  1.6.4.2       tls 	/* XXX Set the power state to D0?  */
    122  1.6.4.2       tls 
    123  1.6.4.2       tls 	/* Set up the bus space and bus DMA tags.  */
    124  1.6.4.2       tls 	dev->bst = pa->pa_memt;
    125  1.6.4.2       tls 	/* XXX Let the driver say something about 32-bit vs 64-bit DMA?  */
    126  1.6.4.2       tls 	dev->bus_dmat = (pci_dma64_available(pa)? pa->pa_dmat64 : pa->pa_dmat);
    127  1.6.4.2       tls 	dev->dmat = dev->bus_dmat;
    128  1.6.4.2       tls 	dev->dmat_subregion_p = false;
    129  1.6.4.2       tls 
    130  1.6.4.2       tls 	/* Find all the memory maps.  */
    131  1.6.4.2       tls 	CTASSERT(PCI_NUM_RESOURCES < (SIZE_MAX / sizeof(dev->bus_maps[0])));
    132  1.6.4.2       tls 	dev->bus_maps = kmem_zalloc(PCI_NUM_RESOURCES *
    133  1.6.4.2       tls 	    sizeof(dev->bus_maps[0]), KM_SLEEP);
    134  1.6.4.2       tls 	dev->bus_nmaps = PCI_NUM_RESOURCES;
    135  1.6.4.2       tls 	for (unit = 0; unit < PCI_NUM_RESOURCES; unit++) {
    136  1.6.4.2       tls 		struct drm_bus_map *const bm = &dev->bus_maps[unit];
    137  1.6.4.2       tls 		const int reg = PCI_BAR(unit);
    138  1.6.4.2       tls 		const pcireg_t type =
    139  1.6.4.2       tls 		    pci_mapreg_type(pa->pa_pc, pa->pa_tag, reg);
    140  1.6.4.2       tls 
    141  1.6.4.2       tls 		/* Reject non-memory mappings.  */
    142  1.6.4.2       tls 		if ((type & PCI_MAPREG_TYPE_MEM) != PCI_MAPREG_TYPE_MEM) {
    143  1.6.4.2       tls 			aprint_debug_dev(self, "map %u has non-memory type:"
    144  1.6.4.2       tls 			    " 0x%"PRIxMAX"\n", unit, (uintmax_t)type);
    145  1.6.4.2       tls 			continue;
    146  1.6.4.2       tls 		}
    147  1.6.4.2       tls 
    148  1.6.4.3  jdolecek 		/* Inquire about it.  We'll map it in drm_core_ioremap.  */
    149  1.6.4.2       tls 		if (pci_mapreg_info(pa->pa_pc, pa->pa_tag, reg, type,
    150  1.6.4.2       tls 			&bm->bm_base, &bm->bm_size, &bm->bm_flags) != 0) {
    151  1.6.4.2       tls 			aprint_debug_dev(self, "map %u failed\n", unit);
    152  1.6.4.2       tls 			continue;
    153  1.6.4.2       tls 		}
    154  1.6.4.2       tls 
    155  1.6.4.2       tls 		/* Assume since it is a memory mapping it can be linear.  */
    156  1.6.4.2       tls 		bm->bm_flags |= BUS_SPACE_MAP_LINEAR;
    157  1.6.4.2       tls 	}
    158  1.6.4.2       tls 
    159  1.6.4.2       tls 	/* Set up AGP stuff if requested.  */
    160  1.6.4.2       tls 	if (drm_core_check_feature(dev, DRIVER_USE_AGP)) {
    161  1.6.4.2       tls 		if (drm_pci_device_is_agp(dev))
    162  1.6.4.2       tls 			dev->agp = drm_agp_init(dev);
    163  1.6.4.2       tls 		if (dev->agp)
    164  1.6.4.2       tls 			dev->agp->agp_mtrr = arch_phys_wc_add(dev->agp->base,
    165  1.6.4.2       tls 				dev->agp->agp_info.aki_info.ai_aperture_size);
    166  1.6.4.2       tls 	}
    167  1.6.4.2       tls 
    168  1.6.4.2       tls 	/* Register the DRM device and do driver-specific initialization.  */
    169  1.6.4.2       tls 	ret = drm_dev_register(dev, cookie);
    170  1.6.4.2       tls 	if (ret)
    171  1.6.4.2       tls 		goto fail1;
    172  1.6.4.2       tls 
    173  1.6.4.2       tls 	/* Success!  */
    174  1.6.4.2       tls 	*devp = dev;
    175  1.6.4.2       tls 	return 0;
    176  1.6.4.2       tls 
    177  1.6.4.2       tls fail2: __unused
    178  1.6.4.2       tls 	drm_dev_unregister(dev);
    179  1.6.4.2       tls fail1:	drm_pci_agp_destroy(dev);
    180  1.6.4.2       tls 	dev->bus_nmaps = 0;
    181  1.6.4.2       tls 	kmem_free(dev->bus_maps, PCI_NUM_RESOURCES * sizeof(dev->bus_maps[0]));
    182  1.6.4.2       tls 	if (dev->dmat_subregion_p)
    183  1.6.4.2       tls 		bus_dmatag_destroy(dev->dmat);
    184  1.6.4.2       tls 	drm_dev_unref(dev);
    185  1.6.4.2       tls fail0:	return ret;
    186  1.6.4.2       tls }
    187  1.6.4.2       tls 
    188  1.6.4.2       tls int
    189  1.6.4.2       tls drm_pci_detach(struct drm_device *dev, int flags __unused)
    190  1.6.4.2       tls {
    191  1.6.4.2       tls 
    192  1.6.4.2       tls 	/* Do driver-specific detachment and unregister the device.  */
    193  1.6.4.2       tls 	drm_dev_unregister(dev);
    194  1.6.4.2       tls 
    195  1.6.4.2       tls 	/* Tear down AGP stuff if necessary.  */
    196  1.6.4.3  jdolecek 	drm_pci_agp_destroy(dev);
    197  1.6.4.2       tls 
    198  1.6.4.2       tls 	/* Free the record of available bus space mappings.  */
    199  1.6.4.2       tls 	dev->bus_nmaps = 0;
    200  1.6.4.2       tls 	kmem_free(dev->bus_maps, PCI_NUM_RESOURCES * sizeof(dev->bus_maps[0]));
    201  1.6.4.2       tls 
    202  1.6.4.2       tls 	/* Tear down bus space and bus DMA tags.  */
    203  1.6.4.2       tls 	if (dev->dmat_subregion_p)
    204  1.6.4.2       tls 		bus_dmatag_destroy(dev->dmat);
    205  1.6.4.2       tls 
    206  1.6.4.2       tls 	drm_dev_unref(dev);
    207  1.6.4.2       tls 
    208  1.6.4.2       tls 	return 0;
    209  1.6.4.2       tls }
    210  1.6.4.2       tls 
    211  1.6.4.2       tls void
    212  1.6.4.2       tls drm_pci_agp_destroy(struct drm_device *dev)
    213  1.6.4.2       tls {
    214  1.6.4.2       tls 
    215  1.6.4.2       tls 	if (dev->agp) {
    216  1.6.4.2       tls 		arch_phys_wc_del(dev->agp->agp_mtrr);
    217  1.6.4.2       tls 		drm_agp_clear(dev);
    218  1.6.4.2       tls 		kfree(dev->agp); /* XXX Should go in drm_agp_clear...  */
    219  1.6.4.2       tls 		dev->agp = NULL;
    220  1.6.4.2       tls 	}
    221  1.6.4.2       tls }
    222  1.6.4.2       tls 
    223  1.6.4.2       tls static int
    224  1.6.4.2       tls drm_pci_get_irq(struct drm_device *dev)
    225  1.6.4.2       tls {
    226  1.6.4.2       tls 
    227  1.6.4.2       tls 	/*
    228  1.6.4.3  jdolecek 	 * Caller expects a nonzero int, and doesn't really use it for
    229  1.6.4.3  jdolecek 	 * anything, so no need to pci_intr_map here.
    230  1.6.4.2       tls 	 */
    231  1.6.4.3  jdolecek 	return dev->pdev->pd_pa.pa_intrpin;
    232  1.6.4.2       tls }
    233  1.6.4.2       tls 
    234  1.6.4.2       tls static int
    235  1.6.4.2       tls drm_pci_irq_install(struct drm_device *dev, irqreturn_t (*handler)(void *),
    236  1.6.4.3  jdolecek     int flags, const char *name, void *arg, struct drm_bus_irq_cookie **cookiep)
    237  1.6.4.2       tls {
    238  1.6.4.2       tls 	const struct pci_attach_args *const pa = drm_pci_attach_args(dev);
    239  1.6.4.2       tls 	const char *intrstr;
    240  1.6.4.2       tls 	char intrbuf[PCI_INTRSTR_LEN];
    241  1.6.4.3  jdolecek 	struct drm_bus_irq_cookie *irq_cookie;
    242  1.6.4.2       tls 
    243  1.6.4.3  jdolecek 	irq_cookie = kmem_alloc(sizeof(*irq_cookie), KM_SLEEP);
    244  1.6.4.2       tls 
    245  1.6.4.3  jdolecek 	if (dev->pdev->msi_enabled) {
    246  1.6.4.3  jdolecek 		if (dev->pdev->intr_handles == NULL) {
    247  1.6.4.3  jdolecek 			if (pci_msi_alloc_exact(pa, &irq_cookie->intr_handles,
    248  1.6.4.3  jdolecek 			    1)) {
    249  1.6.4.3  jdolecek 				aprint_error_dev(dev->dev,
    250  1.6.4.3  jdolecek 				    "couldn't allocate MSI (%s)\n", name);
    251  1.6.4.3  jdolecek 				goto error;
    252  1.6.4.3  jdolecek 			}
    253  1.6.4.3  jdolecek 		} else {
    254  1.6.4.3  jdolecek 			irq_cookie->intr_handles = dev->pdev->intr_handles;
    255  1.6.4.3  jdolecek 			dev->pdev->intr_handles = NULL;
    256  1.6.4.3  jdolecek 		}
    257  1.6.4.3  jdolecek 	} else {
    258  1.6.4.3  jdolecek 		if (pci_intx_alloc(pa, &irq_cookie->intr_handles)) {
    259  1.6.4.3  jdolecek 			aprint_error_dev(dev->dev,
    260  1.6.4.3  jdolecek 			    "couldn't allocate INTx interrupt (%s)\n", name);
    261  1.6.4.3  jdolecek 			goto error;
    262  1.6.4.3  jdolecek 		}
    263  1.6.4.3  jdolecek 	}
    264  1.6.4.3  jdolecek 
    265  1.6.4.3  jdolecek 	intrstr = pci_intr_string(pa->pa_pc, irq_cookie->intr_handles[0],
    266  1.6.4.3  jdolecek 	    intrbuf, sizeof(intrbuf));
    267  1.6.4.3  jdolecek 	irq_cookie->ih_cookie = pci_intr_establish_xname(pa->pa_pc,
    268  1.6.4.3  jdolecek 	    irq_cookie->intr_handles[0], IPL_DRM, handler, arg, name);
    269  1.6.4.3  jdolecek 	if (irq_cookie->ih_cookie == NULL) {
    270  1.6.4.2       tls 		aprint_error_dev(dev->dev,
    271  1.6.4.3  jdolecek 		    "couldn't establish interrupt at %s (%s)\n", intrstr, name);
    272  1.6.4.3  jdolecek 		pci_intr_release(pa->pa_pc, irq_cookie->intr_handles, 1);
    273  1.6.4.3  jdolecek 		goto error;
    274  1.6.4.2       tls 	}
    275  1.6.4.2       tls 
    276  1.6.4.3  jdolecek 	aprint_normal_dev(dev->dev, "interrupting at %s (%s)\n", intrstr, name);
    277  1.6.4.3  jdolecek 	*cookiep = irq_cookie;
    278  1.6.4.2       tls 	return 0;
    279  1.6.4.3  jdolecek 
    280  1.6.4.3  jdolecek error:
    281  1.6.4.3  jdolecek 	kmem_free(irq_cookie, sizeof(*irq_cookie));
    282  1.6.4.3  jdolecek 	return -ENOENT;
    283  1.6.4.2       tls }
    284  1.6.4.2       tls 
    285  1.6.4.2       tls static void
    286  1.6.4.3  jdolecek drm_pci_irq_uninstall(struct drm_device *dev, struct drm_bus_irq_cookie *cookie)
    287  1.6.4.2       tls {
    288  1.6.4.2       tls 	const struct pci_attach_args *pa = drm_pci_attach_args(dev);
    289  1.6.4.2       tls 
    290  1.6.4.3  jdolecek 	pci_intr_disestablish(pa->pa_pc, cookie->ih_cookie);
    291  1.6.4.3  jdolecek 	pci_intr_release(pa->pa_pc, cookie->intr_handles, 1);
    292  1.6.4.3  jdolecek 	kmem_free(cookie, sizeof(*cookie));
    293  1.6.4.2       tls }
    294  1.6.4.2       tls 
    295  1.6.4.2       tls static const char *
    296  1.6.4.2       tls drm_pci_get_name(struct drm_device *dev)
    297  1.6.4.2       tls {
    298  1.6.4.2       tls 	return "pci";		/* XXX PCI bus names?  */
    299  1.6.4.2       tls }
    300  1.6.4.2       tls 
    301  1.6.4.2       tls static int
    302  1.6.4.2       tls drm_pci_format_unique(struct drm_device *dev, char *buf, size_t size)
    303  1.6.4.2       tls {
    304  1.6.4.2       tls 	const unsigned int domain = device_unit(device_parent(dev->dev));
    305  1.6.4.2       tls 	const unsigned int bus = dev->pdev->pd_pa.pa_bus;
    306  1.6.4.2       tls 	const unsigned int device = dev->pdev->pd_pa.pa_device;
    307  1.6.4.2       tls 	const unsigned int function = dev->pdev->pd_pa.pa_function;
    308  1.6.4.2       tls 
    309  1.6.4.2       tls 	return snprintf(buf, size, "pci:%04x:%02x:%02x.%d",
    310  1.6.4.2       tls 	    domain, bus, device, function);
    311  1.6.4.2       tls }
    312  1.6.4.2       tls 
    313  1.6.4.2       tls static int
    314  1.6.4.2       tls drm_pci_format_devname(struct drm_device *dev, const char *unique,
    315  1.6.4.2       tls     char *buf, size_t size)
    316  1.6.4.2       tls {
    317  1.6.4.2       tls 
    318  1.6.4.2       tls 	return snprintf(buf, size, "%s@%s",
    319  1.6.4.2       tls 	    device_xname(device_parent(dev->dev)),
    320  1.6.4.2       tls 	    unique);
    321  1.6.4.2       tls }
    322  1.6.4.2       tls 
    323  1.6.4.2       tls static int
    324  1.6.4.2       tls drm_pci_set_busid(struct drm_device *dev, struct drm_master *master)
    325  1.6.4.2       tls {
    326  1.6.4.2       tls 	int n;
    327  1.6.4.2       tls 	char *buf;
    328  1.6.4.2       tls 
    329  1.6.4.2       tls 	n = drm_pci_format_unique(dev, NULL, 0);
    330  1.6.4.2       tls 	if (n < 0)
    331  1.6.4.2       tls 		return -ENOSPC;	/* XXX */
    332  1.6.4.2       tls 	if (0xff < n)
    333  1.6.4.2       tls 		n = 0xff;
    334  1.6.4.2       tls 
    335  1.6.4.2       tls 	buf = kzalloc(n + 1, GFP_KERNEL);
    336  1.6.4.2       tls 	(void)drm_pci_format_unique(dev, buf, n + 1);
    337  1.6.4.2       tls 
    338  1.6.4.2       tls 	if (master->unique)
    339  1.6.4.2       tls 		kfree(master->unique);
    340  1.6.4.2       tls 	master->unique = buf;
    341  1.6.4.2       tls 	master->unique_len = n;
    342  1.6.4.2       tls 	master->unique_size = n + 1;
    343  1.6.4.2       tls 
    344  1.6.4.2       tls 	n = drm_pci_format_devname(dev, master->unique, NULL, 0);
    345  1.6.4.2       tls 	if (n < 0)
    346  1.6.4.2       tls 		return -ENOSPC;	/* XXX back out? */
    347  1.6.4.2       tls 	if (0xff < n)
    348  1.6.4.2       tls 		n = 0xff;
    349  1.6.4.2       tls 
    350  1.6.4.2       tls 	buf = kzalloc(n + 1, GFP_KERNEL);
    351  1.6.4.2       tls 	(void)drm_pci_format_devname(dev, master->unique, buf, n + 1);
    352  1.6.4.2       tls 
    353  1.6.4.2       tls 	if (dev->devname)
    354  1.6.4.2       tls 		kfree(dev->devname);
    355  1.6.4.2       tls 	dev->devname = buf;
    356  1.6.4.2       tls 
    357  1.6.4.2       tls 	return 0;
    358  1.6.4.2       tls }
    359  1.6.4.2       tls 
    360  1.6.4.2       tls static int
    361  1.6.4.2       tls drm_pci_set_unique(struct drm_device *dev, struct drm_master *master,
    362  1.6.4.2       tls     struct drm_unique *unique __unused)
    363  1.6.4.2       tls {
    364  1.6.4.2       tls 
    365  1.6.4.2       tls 	/*
    366  1.6.4.2       tls 	 * XXX This is silly.  We're supposed to reject unique names
    367  1.6.4.2       tls 	 * that don't match the ones we would generate anyway.  For
    368  1.6.4.2       tls 	 * expedience, we'll just generate the one we would and ignore
    369  1.6.4.2       tls 	 * whatever userland threw at us...
    370  1.6.4.2       tls 	 */
    371  1.6.4.2       tls 	return drm_pci_set_busid(dev, master);
    372  1.6.4.2       tls }
    373  1.6.4.2       tls 
    374  1.6.4.2       tls static int
    375  1.6.4.2       tls drm_pci_irq_by_busid(struct drm_device *dev, struct drm_irq_busid *busid)
    376  1.6.4.2       tls {
    377  1.6.4.2       tls 	return -ENOSYS;		/* XXX */
    378  1.6.4.2       tls }
    379