Home | History | Annotate | Line # | Download | only in pci
drm_pci.c revision 1.1.2.3
      1  1.1.2.1  riastrad /*	$NetBSD: drm_pci.c,v 1.1.2.3 2013/07/24 03:32:19 riastradh Exp $	*/
      2  1.1.2.1  riastrad 
      3  1.1.2.1  riastrad /*-
      4  1.1.2.1  riastrad  * Copyright (c) 2013 The NetBSD Foundation, Inc.
      5  1.1.2.1  riastrad  * All rights reserved.
      6  1.1.2.1  riastrad  *
      7  1.1.2.1  riastrad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.2.1  riastrad  * by Taylor R. Campbell.
      9  1.1.2.1  riastrad  *
     10  1.1.2.1  riastrad  * Redistribution and use in source and binary forms, with or without
     11  1.1.2.1  riastrad  * modification, are permitted provided that the following conditions
     12  1.1.2.1  riastrad  * are met:
     13  1.1.2.1  riastrad  * 1. Redistributions of source code must retain the above copyright
     14  1.1.2.1  riastrad  *    notice, this list of conditions and the following disclaimer.
     15  1.1.2.1  riastrad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.2.1  riastrad  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.2.1  riastrad  *    documentation and/or other materials provided with the distribution.
     18  1.1.2.1  riastrad  *
     19  1.1.2.1  riastrad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1.2.1  riastrad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1.2.1  riastrad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1.2.1  riastrad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1.2.1  riastrad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1.2.1  riastrad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1.2.1  riastrad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1.2.1  riastrad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1.2.1  riastrad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1.2.1  riastrad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1.2.1  riastrad  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1.2.1  riastrad  */
     31  1.1.2.1  riastrad 
     32  1.1.2.1  riastrad #include <sys/cdefs.h>
     33  1.1.2.1  riastrad __KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.3 2013/07/24 03:32:19 riastradh Exp $");
     34  1.1.2.1  riastrad 
     35  1.1.2.1  riastrad #include <sys/types.h>
     36  1.1.2.1  riastrad #include <sys/errno.h>
     37  1.1.2.1  riastrad #include <sys/systm.h>
     38  1.1.2.1  riastrad 
     39  1.1.2.1  riastrad #include <dev/pci/pcivar.h>
     40  1.1.2.1  riastrad 
     41  1.1.2.1  riastrad #include <drm/drmP.h>
     42  1.1.2.1  riastrad 
     43  1.1.2.1  riastrad static int	drm_pci_get_irq(struct drm_device *);
     44  1.1.2.1  riastrad static int	drm_pci_irq_install(struct drm_device *,
     45  1.1.2.1  riastrad 		    irqreturn_t (*)(void *), int, const char *, void *,
     46  1.1.2.1  riastrad 		    struct drm_bus_irq_cookie **);
     47  1.1.2.1  riastrad static void	drm_pci_irq_uninstall(struct drm_device *,
     48  1.1.2.1  riastrad 		    struct drm_bus_irq_cookie *);
     49  1.1.2.1  riastrad static const char *
     50  1.1.2.1  riastrad 		drm_pci_get_name(struct drm_device *);
     51  1.1.2.1  riastrad static int	drm_pci_set_busid(struct drm_device *, struct drm_master *);
     52  1.1.2.1  riastrad static int	drm_pci_set_unique(struct drm_device *, struct drm_master *,
     53  1.1.2.1  riastrad 		    struct drm_unique *);
     54  1.1.2.1  riastrad static int	drm_pci_irq_by_busid(struct drm_device *,
     55  1.1.2.1  riastrad 		    struct drm_irq_busid *);
     56  1.1.2.1  riastrad static int	drm_pci_agp_init(struct drm_device *);
     57  1.1.2.1  riastrad 
     58  1.1.2.1  riastrad const struct drm_bus drm_pci_bus = {
     59  1.1.2.1  riastrad 	.bus_type = DRIVER_BUS_PCI,
     60  1.1.2.1  riastrad 	.get_irq = drm_pci_get_irq,
     61  1.1.2.1  riastrad 	.irq_install = drm_pci_irq_install,
     62  1.1.2.1  riastrad 	.irq_uninstall = drm_pci_irq_uninstall,
     63  1.1.2.1  riastrad 	.get_name = drm_pci_get_name,
     64  1.1.2.1  riastrad 	.set_busid = drm_pci_set_busid,
     65  1.1.2.1  riastrad 	.set_unique = drm_pci_set_unique,
     66  1.1.2.1  riastrad 	.irq_by_busid = drm_pci_irq_by_busid,
     67  1.1.2.1  riastrad 	.agp_init = drm_pci_agp_init,
     68  1.1.2.1  riastrad };
     69  1.1.2.1  riastrad 
     70  1.1.2.1  riastrad static const struct pci_attach_args *
     71  1.1.2.1  riastrad drm_pci_attach_args(struct drm_device *dev)
     72  1.1.2.1  riastrad {
     73  1.1.2.1  riastrad 	return &dev->pdev->pd_pa;
     74  1.1.2.1  riastrad }
     75  1.1.2.1  riastrad 
     76  1.1.2.2  riastrad void
     77  1.1.2.2  riastrad drm_pci_attach(device_t self, const struct pci_attach_args *pa,
     78  1.1.2.2  riastrad     struct pci_dev *pdev, struct drm_device *dev)
     79  1.1.2.2  riastrad {
     80  1.1.2.2  riastrad 
     81  1.1.2.3  riastrad 	linux_pci_dev_init(pdev, self, pa, 0);
     82  1.1.2.2  riastrad 
     83  1.1.2.2  riastrad 	dev->pdev = pdev;
     84  1.1.2.2  riastrad 	dev->pci_vendor = pdev->vendor;
     85  1.1.2.2  riastrad 	dev->pci_device = pdev->device;
     86  1.1.2.2  riastrad 
     87  1.1.2.2  riastrad 	/* XXX Set the power state to D0?  */
     88  1.1.2.2  riastrad }
     89  1.1.2.2  riastrad 
     90  1.1.2.2  riastrad int
     91  1.1.2.2  riastrad drm_pci_detach(struct drm_device *dev __unused, int flags __unused)
     92  1.1.2.2  riastrad {
     93  1.1.2.2  riastrad 
     94  1.1.2.2  riastrad 	/* XXX Disestablish irqs or anything?  */
     95  1.1.2.2  riastrad 	return 0;
     96  1.1.2.2  riastrad }
     97  1.1.2.2  riastrad 
     98  1.1.2.1  riastrad static int
     99  1.1.2.1  riastrad drm_pci_get_irq(struct drm_device *dev)
    100  1.1.2.1  riastrad {
    101  1.1.2.1  riastrad 	pci_intr_handle_t ih_pih;
    102  1.1.2.1  riastrad 	int ih_int;
    103  1.1.2.1  riastrad 
    104  1.1.2.1  riastrad 	/*
    105  1.1.2.1  riastrad 	 * This is a compile-time assertion that the types match.  If
    106  1.1.2.1  riastrad 	 * this fails, we have to change a bunch of drm code that uses
    107  1.1.2.1  riastrad 	 * int for intr handles.
    108  1.1.2.1  riastrad 	 */
    109  1.1.2.1  riastrad 	KASSERT(&ih_pih != &ih_int);
    110  1.1.2.1  riastrad 
    111  1.1.2.1  riastrad 	if (pci_intr_map(drm_pci_attach_args(dev), &ih_pih))
    112  1.1.2.1  riastrad 		return -1;	/* XXX Hope -1 is an invalid intr handle.  */
    113  1.1.2.1  riastrad 
    114  1.1.2.1  riastrad 	ih_int = ih_pih;
    115  1.1.2.1  riastrad 	return ih_int;
    116  1.1.2.1  riastrad }
    117  1.1.2.1  riastrad 
    118  1.1.2.1  riastrad static int
    119  1.1.2.1  riastrad drm_pci_irq_install(struct drm_device *dev, irqreturn_t (*handler)(void *),
    120  1.1.2.1  riastrad     int flags, const char *name, void *arg,
    121  1.1.2.1  riastrad     struct drm_bus_irq_cookie **cookiep)
    122  1.1.2.1  riastrad {
    123  1.1.2.1  riastrad 	const struct pci_attach_args *const pa = drm_pci_attach_args(dev);
    124  1.1.2.1  riastrad 	pci_intr_handle_t ih;
    125  1.1.2.1  riastrad 	const char *intrstr;
    126  1.1.2.1  riastrad 	void *ih_cookie;
    127  1.1.2.1  riastrad 
    128  1.1.2.1  riastrad 	if (pci_intr_map(pa, &ih))
    129  1.1.2.1  riastrad 		return -ENOENT;
    130  1.1.2.1  riastrad 
    131  1.1.2.1  riastrad 	intrstr = pci_intr_string(pa->pa_pc, ih);
    132  1.1.2.1  riastrad 	ih_cookie = pci_intr_establish(pa->pa_pc, ih, IPL_DRM, handler, arg);
    133  1.1.2.1  riastrad 	if (ih_cookie == NULL) {
    134  1.1.2.1  riastrad 		aprint_error_dev(dev->dev,
    135  1.1.2.1  riastrad 		    "couldn't establish interrupt at %s (%s)\n",
    136  1.1.2.1  riastrad 		    intrstr, name);
    137  1.1.2.1  riastrad 		return -ENOENT;
    138  1.1.2.1  riastrad 	}
    139  1.1.2.1  riastrad 
    140  1.1.2.1  riastrad 	aprint_normal_dev(dev->dev, "interrupting at %s (%s)\n",
    141  1.1.2.1  riastrad 	    intrstr, name);
    142  1.1.2.1  riastrad 	*cookiep = (struct drm_bus_irq_cookie *)ih_cookie;
    143  1.1.2.1  riastrad 	return 0;
    144  1.1.2.1  riastrad }
    145  1.1.2.1  riastrad 
    146  1.1.2.1  riastrad static void
    147  1.1.2.1  riastrad drm_pci_irq_uninstall(struct drm_device *dev,
    148  1.1.2.1  riastrad     struct drm_bus_irq_cookie *cookie)
    149  1.1.2.1  riastrad {
    150  1.1.2.1  riastrad 	const struct pci_attach_args *pa = drm_pci_attach_args(dev);
    151  1.1.2.1  riastrad 
    152  1.1.2.1  riastrad 	pci_intr_disestablish(pa->pa_pc, (void *)cookie);
    153  1.1.2.1  riastrad }
    154  1.1.2.1  riastrad 
    155  1.1.2.1  riastrad static const char *
    156  1.1.2.1  riastrad drm_pci_get_name(struct drm_device *dev)
    157  1.1.2.1  riastrad {
    158  1.1.2.1  riastrad 	return "pci";		/* XXX PCI bus names?  */
    159  1.1.2.1  riastrad }
    160  1.1.2.1  riastrad 
    161  1.1.2.1  riastrad static int
    162  1.1.2.1  riastrad drm_pci_set_busid(struct drm_device *dev, struct drm_master *master)
    163  1.1.2.1  riastrad {
    164  1.1.2.1  riastrad 	return -ENOSYS;		/* XXX PCI bus ids?  */
    165  1.1.2.1  riastrad }
    166  1.1.2.1  riastrad 
    167  1.1.2.1  riastrad static int
    168  1.1.2.1  riastrad drm_pci_set_unique(struct drm_device *dev, struct drm_master *master,
    169  1.1.2.1  riastrad     struct drm_unique *unique)
    170  1.1.2.1  riastrad {
    171  1.1.2.1  riastrad 	return -ENOSYS;		/* XXX */
    172  1.1.2.1  riastrad }
    173  1.1.2.1  riastrad 
    174  1.1.2.1  riastrad static int
    175  1.1.2.1  riastrad drm_pci_irq_by_busid(struct drm_device *dev, struct drm_irq_busid *busid)
    176  1.1.2.1  riastrad {
    177  1.1.2.1  riastrad 	return -ENOSYS;		/* XXX */
    178  1.1.2.1  riastrad }
    179  1.1.2.1  riastrad 
    180  1.1.2.1  riastrad static int
    181  1.1.2.1  riastrad drm_pci_agp_init(struct drm_device *dev)
    182  1.1.2.1  riastrad {
    183  1.1.2.1  riastrad 	return -ENOSYS;		/* XXX */
    184  1.1.2.1  riastrad }
    185