Home | History | Annotate | Line # | Download | only in drm
      1  1.7  riastrad /*	$NetBSD: drm_agp_netbsd.h,v 1.8 2018/08/28 03:41:39 riastradh Exp $	*/
      2  1.2  riastrad 
      3  1.2  riastrad /*-
      4  1.2  riastrad  * Copyright (c) 2013 The NetBSD Foundation, Inc.
      5  1.2  riastrad  * All rights reserved.
      6  1.2  riastrad  *
      7  1.2  riastrad  * This code is derived from software contributed to The NetBSD Foundation
      8  1.2  riastrad  * by Taylor R. Campbell.
      9  1.2  riastrad  *
     10  1.2  riastrad  * Redistribution and use in source and binary forms, with or without
     11  1.2  riastrad  * modification, are permitted provided that the following conditions
     12  1.2  riastrad  * are met:
     13  1.2  riastrad  * 1. Redistributions of source code must retain the above copyright
     14  1.2  riastrad  *    notice, this list of conditions and the following disclaimer.
     15  1.2  riastrad  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.2  riastrad  *    notice, this list of conditions and the following disclaimer in the
     17  1.2  riastrad  *    documentation and/or other materials provided with the distribution.
     18  1.2  riastrad  *
     19  1.2  riastrad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.2  riastrad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.2  riastrad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.2  riastrad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.2  riastrad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.2  riastrad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.2  riastrad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.2  riastrad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.2  riastrad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.2  riastrad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.2  riastrad  * POSSIBILITY OF SUCH DAMAGE.
     30  1.2  riastrad  */
     31  1.2  riastrad 
     32  1.2  riastrad #ifndef _DRM_DRM_AGP_NETBSD_H_
     33  1.2  riastrad #define _DRM_DRM_AGP_NETBSD_H_
     34  1.2  riastrad 
     35  1.2  riastrad /*
     36  1.2  riastrad  * XXX XXX XXX BEWARE!  This file is full of abstraction violations
     37  1.2  riastrad  * that are ruthlessly exploited for their value as happy accidents!
     38  1.2  riastrad  * You have been warned!
     39  1.2  riastrad  */
     40  1.2  riastrad 
     41  1.2  riastrad #include <sys/agpio.h>
     42  1.2  riastrad 
     43  1.2  riastrad #include <dev/pci/pcivar.h>	/* XXX include order botch */
     44  1.4  riastrad #include <dev/pci/agpreg.h>
     45  1.2  riastrad #include <dev/pci/agpvar.h>
     46  1.2  riastrad 
     47  1.2  riastrad #include <linux/kernel.h>
     48  1.2  riastrad #include <linux/pci.h>
     49  1.2  riastrad 
     50  1.4  riastrad #define	PCI_AGP_COMMAND_FW	AGPCMD_FWEN
     51  1.4  riastrad 
     52  1.7  riastrad #define	CONFIG_AGP	1
     53  1.2  riastrad 
     54  1.3  riastrad struct agp_kern_info {
     55  1.3  riastrad 	struct agp_info aki_info;
     56  1.3  riastrad };
     57  1.2  riastrad 
     58  1.2  riastrad struct agp_bridge_data {
     59  1.2  riastrad 	struct agp_softc abd_sc; /* XXX Abstraction violation! */
     60  1.2  riastrad };
     61  1.2  riastrad 
     62  1.2  riastrad /*
     63  1.2  riastrad  * We already have a struct agp_memory, but fortunately it looks like
     64  1.2  riastrad  * it may accidentally work out.
     65  1.2  riastrad  */
     66  1.2  riastrad 
     67  1.2  riastrad #if 0
     68  1.2  riastrad struct agp_memory {
     69  1.2  riastrad 	void *am_cookie;
     70  1.2  riastrad };
     71  1.2  riastrad #endif
     72  1.2  riastrad 
     73  1.2  riastrad static inline struct agp_bridge_data *
     74  1.2  riastrad agp_find_bridge(struct pci_dev *pdev __unused)
     75  1.2  riastrad {
     76  1.2  riastrad 	/*
     77  1.2  riastrad 	 * XXX How do we find the agp bridge attached to this
     78  1.2  riastrad 	 * particular PCI device?
     79  1.2  riastrad 	 */
     80  1.2  riastrad 	return container_of((struct agp_softc *)agp_find_device(0),
     81  1.2  riastrad 	    struct agp_bridge_data, abd_sc);
     82  1.2  riastrad }
     83  1.2  riastrad 
     84  1.2  riastrad static inline struct agp_bridge_data *
     85  1.2  riastrad agp_backend_acquire(struct pci_dev *pdev)
     86  1.2  riastrad {
     87  1.2  riastrad 	struct agp_bridge_data *const bridge = agp_find_bridge(pdev);
     88  1.2  riastrad 
     89  1.2  riastrad 	if (bridge == NULL)
     90  1.2  riastrad 		return NULL;
     91  1.2  riastrad 
     92  1.2  riastrad 	/* XXX We lose the error code here.  */
     93  1.2  riastrad 	if (agp_acquire(&bridge->abd_sc) != 0)
     94  1.2  riastrad 		return NULL;
     95  1.2  riastrad 
     96  1.2  riastrad 	return bridge;
     97  1.2  riastrad }
     98  1.2  riastrad 
     99  1.2  riastrad static inline void
    100  1.2  riastrad agp_backend_release(struct agp_bridge_data *bridge)
    101  1.2  riastrad {
    102  1.2  riastrad 
    103  1.2  riastrad 	/* XXX We lose the error code here.  */
    104  1.2  riastrad 	(void)agp_release(&bridge->abd_sc);
    105  1.2  riastrad }
    106  1.2  riastrad 
    107  1.2  riastrad /*
    108  1.2  riastrad  * Happily, agp_enable will accidentally DTRT as is in NetBSD in spite
    109  1.2  riastrad  * of the name collision, thanks to a curious `void *' argument in its
    110  1.2  riastrad  * declaration...
    111  1.2  riastrad  */
    112  1.2  riastrad 
    113  1.2  riastrad #if 0
    114  1.2  riastrad static inline void
    115  1.2  riastrad agp_enable(struct agp_bridge_data *bridge)
    116  1.2  riastrad {
    117  1.2  riastrad 	...
    118  1.2  riastrad }
    119  1.2  riastrad #endif
    120  1.2  riastrad 
    121  1.2  riastrad static inline struct agp_memory *
    122  1.2  riastrad agp_allocate_memory(struct agp_bridge_data *bridge, size_t npages,
    123  1.2  riastrad     uint32_t type)
    124  1.2  riastrad {
    125  1.2  riastrad 	return agp_alloc_memory(&bridge->abd_sc, (npages << AGP_PAGE_SHIFT),
    126  1.2  riastrad 	    type);
    127  1.2  riastrad }
    128  1.2  riastrad 
    129  1.2  riastrad /*
    130  1.2  riastrad  * Once again, a happy accident makes agp_free_memory work out.
    131  1.2  riastrad  */
    132  1.2  riastrad 
    133  1.2  riastrad #if 0
    134  1.2  riastrad static inline void
    135  1.2  riastrad agp_free_memory(struct agp_bridge_data *bridge, struct agp_memory *mem)
    136  1.2  riastrad {
    137  1.2  riastrad 	...
    138  1.2  riastrad }
    139  1.2  riastrad #endif
    140  1.2  riastrad 
    141  1.2  riastrad /*
    142  1.2  riastrad  * Unfortunately, Linux's agp_bind_memory doesn't require the agp
    143  1.2  riastrad  * device as an argument.  So we'll have to kludge that up as we go.
    144  1.2  riastrad  */
    145  1.2  riastrad #if 0
    146  1.2  riastrad static inline void
    147  1.2  riastrad agp_bind_memory(struct agp_memory *mem, size_t npages)
    148  1.2  riastrad {
    149  1.2  riastrad 	agp_bind_memory(???, mem, (npages << AGP_PAGE_SHIFT));
    150  1.2  riastrad }
    151  1.2  riastrad #endif
    152  1.2  riastrad 
    153  1.2  riastrad static inline void
    154  1.3  riastrad agp_copy_info(struct agp_bridge_data *bridge, struct agp_kern_info *info)
    155  1.2  riastrad {
    156  1.3  riastrad 	agp_get_info(bridge, &info->aki_info);
    157  1.2  riastrad }
    158  1.2  riastrad 
    159  1.2  riastrad static inline int
    160  1.3  riastrad drm_bind_agp(struct agp_bridge_data *bridge, struct agp_memory *mem,
    161  1.3  riastrad     unsigned npages)
    162  1.2  riastrad {
    163  1.3  riastrad 	return agp_bind_memory(&bridge->abd_sc, mem,
    164  1.3  riastrad 	    ((size_t)npages << AGP_PAGE_SHIFT));
    165  1.2  riastrad }
    166  1.2  riastrad 
    167  1.2  riastrad static inline int
    168  1.3  riastrad drm_unbind_agp(struct agp_bridge_data *bridge, struct agp_memory *mem)
    169  1.2  riastrad {
    170  1.2  riastrad 	return agp_unbind_memory(&bridge->abd_sc, mem);
    171  1.2  riastrad }
    172  1.2  riastrad 
    173  1.2  riastrad static inline void
    174  1.3  riastrad drm_free_agp(struct agp_bridge_data *bridge, struct agp_memory *mem,
    175  1.3  riastrad     int npages __unused)
    176  1.2  riastrad {
    177  1.2  riastrad 	agp_free_memory(&bridge->abd_sc, mem);
    178  1.2  riastrad }
    179  1.2  riastrad 
    180  1.2  riastrad #endif  /* _DRM_DRM_AGP_NETBSD_H_ */
    181