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