Fri Mar 6 01:24:24 2015 UTC ()
Adapt drmkms_pci module initialization to work as builtin, for agp.


(riastradh)
diff -r1.9 -r1.10 src/sys/external/bsd/drm2/dist/include/drm/drmP.h
diff -r1.9 -r1.10 src/sys/external/bsd/drm2/pci/drm_pci.c
diff -r1.3 -r1.4 src/sys/external/bsd/drm2/pci/drm_pci_module.c

cvs diff -r1.9 -r1.10 src/sys/external/bsd/drm2/dist/include/drm/Attic/drmP.h (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/dist/include/drm/Attic/drmP.h 2014/12/02 21:49:36 1.9
+++ src/sys/external/bsd/drm2/dist/include/drm/Attic/drmP.h 2015/03/06 01:24:24 1.10
@@ -1741,26 +1741,27 @@ extern int drm_sg_free(struct drm_device @@ -1741,26 +1741,27 @@ extern int drm_sg_free(struct drm_device
1741 struct drm_file *file_priv); 1741 struct drm_file *file_priv);
1742 1742
1743 /* ATI PCIGART support (ati_pcigart.h) */ 1743 /* ATI PCIGART support (ati_pcigart.h) */
1744extern int drm_ati_pcigart_init(struct drm_device *dev, 1744extern int drm_ati_pcigart_init(struct drm_device *dev,
1745 struct drm_ati_pcigart_info * gart_info); 1745 struct drm_ati_pcigart_info * gart_info);
1746extern int drm_ati_pcigart_cleanup(struct drm_device *dev, 1746extern int drm_ati_pcigart_cleanup(struct drm_device *dev,
1747 struct drm_ati_pcigart_info * gart_info); 1747 struct drm_ati_pcigart_info * gart_info);
1748 1748
1749extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size, 1749extern drm_dma_handle_t *drm_pci_alloc(struct drm_device *dev, size_t size,
1750 size_t align); 1750 size_t align);
1751extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah); 1751extern void __drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1752extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah); 1752extern void drm_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
1753#ifdef __NetBSD__ 1753#ifdef __NetBSD__
 1754extern int drmkms_pci_agp_guarantee_initialized(void);
1754extern int drm_pci_attach(device_t, const struct pci_attach_args *, 1755extern int drm_pci_attach(device_t, const struct pci_attach_args *,
1755 struct pci_dev *, struct drm_driver *, unsigned long, 1756 struct pci_dev *, struct drm_driver *, unsigned long,
1756 struct drm_device **); 1757 struct drm_device **);
1757extern int drm_pci_detach(struct drm_device *, int); 1758extern int drm_pci_detach(struct drm_device *, int);
1758#endif 1759#endif
1759 1760
1760 /* sysfs support (drm_sysfs.c) */ 1761 /* sysfs support (drm_sysfs.c) */
1761struct drm_sysfs_class; 1762struct drm_sysfs_class;
1762extern struct class *drm_sysfs_create(struct module *owner, char *name); 1763extern struct class *drm_sysfs_create(struct module *owner, char *name);
1763extern void drm_sysfs_destroy(void); 1764extern void drm_sysfs_destroy(void);
1764extern int drm_sysfs_device_add(struct drm_minor *minor); 1765extern int drm_sysfs_device_add(struct drm_minor *minor);
1765extern void drm_sysfs_hotplug_event(struct drm_device *dev); 1766extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1766extern void drm_sysfs_device_remove(struct drm_minor *minor); 1767extern void drm_sysfs_device_remove(struct drm_minor *minor);

cvs diff -r1.9 -r1.10 src/sys/external/bsd/drm2/pci/drm_pci.c (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/pci/drm_pci.c 2015/01/01 01:15:43 1.9
+++ src/sys/external/bsd/drm2/pci/drm_pci.c 2015/03/06 01:24:24 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: drm_pci.c,v 1.9 2015/01/01 01:15:43 mrg Exp $ */ 1/* $NetBSD: drm_pci.c,v 1.10 2015/03/06 01:24:24 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell. 8 * by Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 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 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.9 2015/01/01 01:15:43 mrg Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: drm_pci.c,v 1.10 2015/03/06 01:24:24 riastradh Exp $");
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36#include <sys/errno.h> 36#include <sys/errno.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38 38
39#include <dev/pci/pcivar.h> 39#include <dev/pci/pcivar.h>
40 40
41#include <drm/drmP.h> 41#include <drm/drmP.h>
42 42
43static int drm_pci_get_irq(struct drm_device *); 43static int drm_pci_get_irq(struct drm_device *);
44static int drm_pci_irq_install(struct drm_device *, 44static int drm_pci_irq_install(struct drm_device *,
45 irqreturn_t (*)(void *), int, const char *, void *, 45 irqreturn_t (*)(void *), int, const char *, void *,
46 struct drm_bus_irq_cookie **); 46 struct drm_bus_irq_cookie **);
@@ -84,26 +84,32 @@ drm_pci_exit(struct drm_driver *driver _ @@ -84,26 +84,32 @@ drm_pci_exit(struct drm_driver *driver _
84 struct pci_driver *pdriver __unused) 84 struct pci_driver *pdriver __unused)
85{ 85{
86} 86}
87 87
88int 88int
89drm_pci_attach(device_t self, const struct pci_attach_args *pa, 89drm_pci_attach(device_t self, const struct pci_attach_args *pa,
90 struct pci_dev *pdev, struct drm_driver *driver, unsigned long cookie, 90 struct pci_dev *pdev, struct drm_driver *driver, unsigned long cookie,
91 struct drm_device **devp) 91 struct drm_device **devp)
92{ 92{
93 struct drm_device *dev; 93 struct drm_device *dev;
94 unsigned int unit; 94 unsigned int unit;
95 int ret; 95 int ret;
96 96
 97 /* Ensure the drm agp hooks are installed. */
 98 /* XXX errno NetBSD->Linux */
 99 ret = -drmkms_pci_agp_guarantee_initialized();
 100 if (ret)
 101 goto fail0;
 102
97 /* Initialize the Linux PCI device descriptor. */ 103 /* Initialize the Linux PCI device descriptor. */
98 linux_pci_dev_init(pdev, self, pa, 0); 104 linux_pci_dev_init(pdev, self, pa, 0);
99 105
100 /* Create a DRM device. */ 106 /* Create a DRM device. */
101 dev = drm_dev_alloc(driver, self); 107 dev = drm_dev_alloc(driver, self);
102 if (dev == NULL) { 108 if (dev == NULL) {
103 ret = -ENOMEM; 109 ret = -ENOMEM;
104 goto fail0; 110 goto fail0;
105 } 111 }
106 112
107 dev->pdev = pdev; 113 dev->pdev = pdev;
108 114
109 /* XXX Set the power state to D0? */ 115 /* XXX Set the power state to D0? */

cvs diff -r1.3 -r1.4 src/sys/external/bsd/drm2/pci/drm_pci_module.c (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/pci/drm_pci_module.c 2014/11/22 19:18:07 1.3
+++ src/sys/external/bsd/drm2/pci/drm_pci_module.c 2015/03/06 01:24:24 1.4
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: drm_pci_module.c,v 1.3 2014/11/22 19:18:07 riastradh Exp $ */ 1/* $NetBSD: drm_pci_module.c,v 1.4 2015/03/06 01:24:24 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell. 8 * by Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,54 +20,90 @@ @@ -20,54 +20,90 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 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 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: drm_pci_module.c,v 1.3 2014/11/22 19:18:07 riastradh Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: drm_pci_module.c,v 1.4 2015/03/06 01:24:24 riastradh Exp $");
34 34
35#include <sys/module.h> 35#include <sys/module.h>
 36#include <sys/once.h>
36 37
37#include <drm/drmP.h> 38#include <drm/drmP.h>
38 39
39MODULE(MODULE_CLASS_MISC, drmkms_pci, "drmkms,pci"); 40MODULE(MODULE_CLASS_MISC, drmkms_pci, "drmkms,pci");
40 41
41const struct drm_agp_hooks drmkms_pci_agp_hooks = { 42const struct drm_agp_hooks drmkms_pci_agp_hooks = {
42 .agph_acquire_ioctl = &drm_agp_acquire_ioctl, 43 .agph_acquire_ioctl = &drm_agp_acquire_ioctl,
43 .agph_release_ioctl = &drm_agp_release_ioctl, 44 .agph_release_ioctl = &drm_agp_release_ioctl,
44 .agph_enable_ioctl = &drm_agp_enable_ioctl, 45 .agph_enable_ioctl = &drm_agp_enable_ioctl,
45 .agph_info_ioctl = &drm_agp_info_ioctl, 46 .agph_info_ioctl = &drm_agp_info_ioctl,
46 .agph_alloc_ioctl = &drm_agp_alloc_ioctl, 47 .agph_alloc_ioctl = &drm_agp_alloc_ioctl,
47 .agph_free_ioctl = &drm_agp_free_ioctl, 48 .agph_free_ioctl = &drm_agp_free_ioctl,
48 .agph_bind_ioctl = &drm_agp_bind_ioctl, 49 .agph_bind_ioctl = &drm_agp_bind_ioctl,
49 .agph_unbind_ioctl = &drm_agp_unbind_ioctl, 50 .agph_unbind_ioctl = &drm_agp_unbind_ioctl,
50 .agph_release = &drm_agp_release, 51 .agph_release = &drm_agp_release,
51 .agph_clear = &drm_agp_clear, 52 .agph_clear = &drm_agp_clear,
52}; 53};
53 54
54static int 55static int
 56drmkms_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
 67int
 68drmkms_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
 79static void
 80drmkms_pci_agp_fini(void)
 81{
 82
 83 drm_agp_deregister(&drmkms_pci_agp_hooks);
 84}
 85
 86static int
55drmkms_pci_modcmd(modcmd_t cmd, void *arg __unused) 87drmkms_pci_modcmd(modcmd_t cmd, void *arg __unused)
56{ 88{
57 int error; 89 int error;
58 90
59 switch (cmd) { 91 switch (cmd) {
60 case MODULE_CMD_INIT: 92 case MODULE_CMD_INIT:
61 error = drm_agp_register(&drmkms_pci_agp_hooks); 93#ifdef _MODULE
 94 error = drmkms_pci_agp_init();
 95#else
 96 error = drmkms_pci_agp_guarantee_initialized();
 97#endif
62 if (error) 98 if (error)
63 return error; 99 return error;
64 return 0; 100 return 0;
65 101
66 case MODULE_CMD_FINI: 102 case MODULE_CMD_FINI:
67 drm_agp_deregister(&drmkms_pci_agp_hooks); 103 drmkms_pci_agp_fini();
68 return 0; 104 return 0;
69 105
70 default: 106 default:
71 return ENOTTY; 107 return ENOTTY;
72 } 108 }
73} 109}