1 /* $NetBSD: drm_pci_module.c,v 1.4 2015/03/06 01:24:24 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 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: drm_pci_module.c,v 1.4 2015/03/06 01:24:24 riastradh Exp $"); 34 35 #include <sys/module.h> 36 #include <sys/once.h> 37 38 #include <drm/drmP.h> 39 40 MODULE(MODULE_CLASS_MISC, drmkms_pci, "drmkms,pci"); 41 42 const struct drm_agp_hooks drmkms_pci_agp_hooks = { 43 .agph_acquire_ioctl = &drm_agp_acquire_ioctl, 44 .agph_release_ioctl = &drm_agp_release_ioctl, 45 .agph_enable_ioctl = &drm_agp_enable_ioctl, 46 .agph_info_ioctl = &drm_agp_info_ioctl, 47 .agph_alloc_ioctl = &drm_agp_alloc_ioctl, 48 .agph_free_ioctl = &drm_agp_free_ioctl, 49 .agph_bind_ioctl = &drm_agp_bind_ioctl, 50 .agph_unbind_ioctl = &drm_agp_unbind_ioctl, 51 .agph_release = &drm_agp_release, 52 .agph_clear = &drm_agp_clear, 53 }; 54 55 static int 56 drmkms_pci_agp_init(void) 57 { 58 int error; 59 60 error = drm_agp_register(&drmkms_pci_agp_hooks); 61 if (error) 62 return error; 63 64 return 0; 65 } 66 67 int 68 drmkms_pci_agp_guarantee_initialized(void) 69 { 70 #ifdef _MODULE 71 return 0; 72 #else 73 static ONCE_DECL(drmkms_pci_agp_init_once); 74 75 return RUN_ONCE(&drmkms_pci_agp_init_once, &drmkms_pci_agp_init); 76 #endif 77 } 78 79 static void 80 drmkms_pci_agp_fini(void) 81 { 82 83 drm_agp_deregister(&drmkms_pci_agp_hooks); 84 } 85 86 static int 87 drmkms_pci_modcmd(modcmd_t cmd, void *arg __unused) 88 { 89 int error; 90 91 switch (cmd) { 92 case MODULE_CMD_INIT: 93 #ifdef _MODULE 94 error = drmkms_pci_agp_init(); 95 #else 96 error = drmkms_pci_agp_guarantee_initialized(); 97 #endif 98 if (error) 99 return error; 100 return 0; 101 102 case MODULE_CMD_FINI: 103 drmkms_pci_agp_fini(); 104 return 0; 105 106 default: 107 return ENOTTY; 108 } 109 } 110