drm_pci_module.c revision 1.5
11.5Sriastrad/* $NetBSD: drm_pci_module.c,v 1.5 2018/08/27 15:10:12 riastradh Exp $ */ 21.2Sriastrad 31.2Sriastrad/*- 41.2Sriastrad * Copyright (c) 2013 The NetBSD Foundation, Inc. 51.2Sriastrad * All rights reserved. 61.2Sriastrad * 71.2Sriastrad * This code is derived from software contributed to The NetBSD Foundation 81.2Sriastrad * by Taylor R. Campbell. 91.2Sriastrad * 101.2Sriastrad * Redistribution and use in source and binary forms, with or without 111.2Sriastrad * modification, are permitted provided that the following conditions 121.2Sriastrad * are met: 131.2Sriastrad * 1. Redistributions of source code must retain the above copyright 141.2Sriastrad * notice, this list of conditions and the following disclaimer. 151.2Sriastrad * 2. Redistributions in binary form must reproduce the above copyright 161.2Sriastrad * notice, this list of conditions and the following disclaimer in the 171.2Sriastrad * documentation and/or other materials provided with the distribution. 181.2Sriastrad * 191.2Sriastrad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.2Sriastrad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.2Sriastrad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.2Sriastrad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.2Sriastrad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.2Sriastrad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.2Sriastrad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.2Sriastrad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.2Sriastrad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.2Sriastrad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.2Sriastrad * POSSIBILITY OF SUCH DAMAGE. 301.2Sriastrad */ 311.2Sriastrad 321.2Sriastrad#include <sys/cdefs.h> 331.5Sriastrad__KERNEL_RCSID(0, "$NetBSD: drm_pci_module.c,v 1.5 2018/08/27 15:10:12 riastradh Exp $"); 341.2Sriastrad 351.2Sriastrad#include <sys/module.h> 361.4Sriastrad#include <sys/once.h> 371.2Sriastrad 381.2Sriastrad#include <drm/drmP.h> 391.2Sriastrad 401.2SriastradMODULE(MODULE_CLASS_MISC, drmkms_pci, "drmkms,pci"); 411.2Sriastrad 421.5Sriastrad#ifdef CONFIG_AGP 431.2Sriastradconst struct drm_agp_hooks drmkms_pci_agp_hooks = { 441.2Sriastrad .agph_acquire_ioctl = &drm_agp_acquire_ioctl, 451.2Sriastrad .agph_release_ioctl = &drm_agp_release_ioctl, 461.2Sriastrad .agph_enable_ioctl = &drm_agp_enable_ioctl, 471.2Sriastrad .agph_info_ioctl = &drm_agp_info_ioctl, 481.2Sriastrad .agph_alloc_ioctl = &drm_agp_alloc_ioctl, 491.2Sriastrad .agph_free_ioctl = &drm_agp_free_ioctl, 501.2Sriastrad .agph_bind_ioctl = &drm_agp_bind_ioctl, 511.2Sriastrad .agph_unbind_ioctl = &drm_agp_unbind_ioctl, 521.2Sriastrad .agph_release = &drm_agp_release, 531.3Sriastrad .agph_clear = &drm_agp_clear, 541.2Sriastrad}; 551.5Sriastrad#endif 561.2Sriastrad 571.2Sriastradstatic int 581.4Sriastraddrmkms_pci_agp_init(void) 591.4Sriastrad{ 601.5Sriastrad#ifdef CONFIG_AGP 611.4Sriastrad int error; 621.4Sriastrad 631.4Sriastrad error = drm_agp_register(&drmkms_pci_agp_hooks); 641.4Sriastrad if (error) 651.4Sriastrad return error; 661.5Sriastrad#endif 671.4Sriastrad 681.4Sriastrad return 0; 691.4Sriastrad} 701.4Sriastrad 711.4Sriastradint 721.4Sriastraddrmkms_pci_agp_guarantee_initialized(void) 731.4Sriastrad{ 741.4Sriastrad#ifdef _MODULE 751.4Sriastrad return 0; 761.4Sriastrad#else 771.4Sriastrad static ONCE_DECL(drmkms_pci_agp_init_once); 781.4Sriastrad 791.4Sriastrad return RUN_ONCE(&drmkms_pci_agp_init_once, &drmkms_pci_agp_init); 801.4Sriastrad#endif 811.4Sriastrad} 821.4Sriastrad 831.4Sriastradstatic void 841.4Sriastraddrmkms_pci_agp_fini(void) 851.4Sriastrad{ 861.4Sriastrad 871.5Sriastrad#ifdef CONFIG_AGP 881.4Sriastrad drm_agp_deregister(&drmkms_pci_agp_hooks); 891.5Sriastrad#endif 901.4Sriastrad} 911.4Sriastrad 921.4Sriastradstatic int 931.2Sriastraddrmkms_pci_modcmd(modcmd_t cmd, void *arg __unused) 941.2Sriastrad{ 951.2Sriastrad int error; 961.2Sriastrad 971.2Sriastrad switch (cmd) { 981.2Sriastrad case MODULE_CMD_INIT: 991.4Sriastrad#ifdef _MODULE 1001.4Sriastrad error = drmkms_pci_agp_init(); 1011.4Sriastrad#else 1021.4Sriastrad error = drmkms_pci_agp_guarantee_initialized(); 1031.4Sriastrad#endif 1041.2Sriastrad if (error) 1051.2Sriastrad return error; 1061.2Sriastrad return 0; 1071.2Sriastrad 1081.2Sriastrad case MODULE_CMD_FINI: 1091.4Sriastrad drmkms_pci_agp_fini(); 1101.2Sriastrad return 0; 1111.2Sriastrad 1121.2Sriastrad default: 1131.2Sriastrad return ENOTTY; 1141.2Sriastrad } 1151.2Sriastrad} 116