1 /* $NetBSD: via_module.c,v 1.5 2021/12/19 10:33:00 riastradh Exp $ */ 2 3 /*- 4 * Copyright (c) 2015 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: via_module.c,v 1.5 2021/12/19 10:33:00 riastradh Exp $"); 34 35 #include <sys/types.h> 36 #include <sys/module.h> 37 #include <sys/once.h> 38 39 #include <drm/drm_device.h> 40 #include <drm/via_drm.h> 41 42 #include "via_drv.h" 43 44 MODULE(MODULE_CLASS_DRIVER, viadrmums, "drmkms,drmkms_pci"); 45 46 #ifdef _MODULE 47 #include "ioconf.c" 48 #endif 49 50 extern struct drm_driver *const via_drm_driver; /* XXX */ 51 52 static int 53 viadrm_init(void) 54 { 55 int error; 56 57 via_init_command_verifier(); /* idempotent, no unwind needed */ 58 59 error = drm_guarantee_initialized(); 60 if (error) 61 return error; 62 63 return 0; 64 } 65 66 int viadrm_guarantee_initialized(void); /* XXX */ 67 int 68 viadrm_guarantee_initialized(void) 69 { 70 #ifdef _MODULE 71 return 0; 72 #else 73 static ONCE_DECL(viadrm_init_once); 74 75 return RUN_ONCE(&viadrm_init_once, &viadrm_init); 76 #endif 77 } 78 79 static void 80 viadrm_fini(void) 81 { 82 } 83 84 static int 85 viadrmums_modcmd(modcmd_t cmd, void *arg __unused) 86 { 87 int error; 88 89 switch (cmd) { 90 case MODULE_CMD_INIT: 91 #ifdef _MODULE 92 error = viadrm_init(); 93 #else 94 error = viadrm_guarantee_initialized(); 95 #endif 96 if (error) { 97 aprint_error("viadrmums: failed to initialize: %d\n", 98 error); 99 return error; 100 } 101 #ifdef _MODULE 102 error = config_init_component(cfdriver_ioconf_viadrmums, 103 cfattach_ioconf_viadrmums, cfdata_ioconf_viadrmums); 104 if (error) { 105 aprint_error("viadrmums: failed to init component" 106 ": %d\n", error); 107 viadrm_fini(); 108 return error; 109 } 110 #endif 111 return 0; 112 113 case MODULE_CMD_FINI: 114 #ifdef _MODULE 115 error = config_fini_component(cfdriver_ioconf_viadrmums, 116 cfattach_ioconf_viadrmums, cfdata_ioconf_viadrmums); 117 if (error) { 118 aprint_error("viadrmums: failed to fini component" 119 ": %d\n", error); 120 return error; 121 } 122 #endif 123 viadrm_fini(); 124 return 0; 125 126 default: 127 return ENOTTY; 128 } 129 } 130