Module Name: src Committed By: riastradh Date: Wed Jul 24 02:35:07 UTC 2013
Added Files: src/sys/external/bsd/drm2/pci [riastradh-drm2]: drm_pci.c Log Message: First draft of a local drm_pci.c. To generate a diff of this commit: cvs rdiff -u -r0 -r1.1.2.1 src/sys/external/bsd/drm2/pci/drm_pci.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Added files: Index: src/sys/external/bsd/drm2/pci/drm_pci.c diff -u /dev/null src/sys/external/bsd/drm2/pci/drm_pci.c:1.1.2.1 --- /dev/null Wed Jul 24 02:35:07 2013 +++ src/sys/external/bsd/drm2/pci/drm_pci.c Wed Jul 24 02:35:07 2013 @@ -0,0 +1,162 @@ +/* $NetBSD: drm_pci.c,v 1.1.2.1 2013/07/24 02:35:07 riastradh Exp $ */ + +/*- + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Taylor R. Campbell. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.1.2.1 2013/07/24 02:35:07 riastradh Exp $"); + +#include <sys/types.h> +#include <sys/errno.h> +#include <sys/systm.h> + +#include <dev/pci/pcivar.h> + +#include <drm/drmP.h> + +static int drm_pci_get_irq(struct drm_device *); +static int drm_pci_irq_install(struct drm_device *, + irqreturn_t (*)(void *), int, const char *, void *, + struct drm_bus_irq_cookie **); +static void drm_pci_irq_uninstall(struct drm_device *, + struct drm_bus_irq_cookie *); +static const char * + drm_pci_get_name(struct drm_device *); +static int drm_pci_set_busid(struct drm_device *, struct drm_master *); +static int drm_pci_set_unique(struct drm_device *, struct drm_master *, + struct drm_unique *); +static int drm_pci_irq_by_busid(struct drm_device *, + struct drm_irq_busid *); +static int drm_pci_agp_init(struct drm_device *); + +const struct drm_bus drm_pci_bus = { + .bus_type = DRIVER_BUS_PCI, + .get_irq = drm_pci_get_irq, + .irq_install = drm_pci_irq_install, + .irq_uninstall = drm_pci_irq_uninstall, + .get_name = drm_pci_get_name, + .set_busid = drm_pci_set_busid, + .set_unique = drm_pci_set_unique, + .irq_by_busid = drm_pci_irq_by_busid, + .agp_init = drm_pci_agp_init, +}; + +static const struct pci_attach_args * +drm_pci_attach_args(struct drm_device *dev) +{ + return &dev->pdev->pd_pa; +} + +static int +drm_pci_get_irq(struct drm_device *dev) +{ + pci_intr_handle_t ih_pih; + int ih_int; + + /* + * This is a compile-time assertion that the types match. If + * this fails, we have to change a bunch of drm code that uses + * int for intr handles. + */ + KASSERT(&ih_pih != &ih_int); + + if (pci_intr_map(drm_pci_attach_args(dev), &ih_pih)) + return -1; /* XXX Hope -1 is an invalid intr handle. */ + + ih_int = ih_pih; + return ih_int; +} + +static int +drm_pci_irq_install(struct drm_device *dev, irqreturn_t (*handler)(void *), + int flags, const char *name, void *arg, + struct drm_bus_irq_cookie **cookiep) +{ + const struct pci_attach_args *const pa = drm_pci_attach_args(dev); + pci_intr_handle_t ih; + const char *intrstr; + void *ih_cookie; + + if (pci_intr_map(pa, &ih)) + return -ENOENT; + + intrstr = pci_intr_string(pa->pa_pc, ih); + ih_cookie = pci_intr_establish(pa->pa_pc, ih, IPL_DRM, handler, arg); + if (ih_cookie == NULL) { + aprint_error_dev(dev->dev, + "couldn't establish interrupt at %s (%s)\n", + intrstr, name); + return -ENOENT; + } + + aprint_normal_dev(dev->dev, "interrupting at %s (%s)\n", + intrstr, name); + *cookiep = (struct drm_bus_irq_cookie *)ih_cookie; + return 0; +} + +static void +drm_pci_irq_uninstall(struct drm_device *dev, + struct drm_bus_irq_cookie *cookie) +{ + const struct pci_attach_args *pa = drm_pci_attach_args(dev); + + pci_intr_disestablish(pa->pa_pc, (void *)cookie); +} + +static const char * +drm_pci_get_name(struct drm_device *dev) +{ + return "pci"; /* XXX PCI bus names? */ +} + +static int +drm_pci_set_busid(struct drm_device *dev, struct drm_master *master) +{ + return -ENOSYS; /* XXX PCI bus ids? */ +} + +static int +drm_pci_set_unique(struct drm_device *dev, struct drm_master *master, + struct drm_unique *unique) +{ + return -ENOSYS; /* XXX */ +} + +static int +drm_pci_irq_by_busid(struct drm_device *dev, struct drm_irq_busid *busid) +{ + return -ENOSYS; /* XXX */ +} + +static int +drm_pci_agp_init(struct drm_device *dev) +{ + return -ENOSYS; /* XXX */ +}