Module Name:    src
Committed By:   jmcneill
Date:           Sat Oct 17 12:02:44 UTC 2015

Modified Files:
        src/sys/external/bsd/drm2/nouveau: files.nouveau nouveau_module.c
            nouveau_pci.c nouveau_pci.h nouveaufb.c

Log Message:
Split nouveau@pci from nouveau so we can attach it to other busses.
nouveaufb still depends on nouveau_pci, but it is not applicable to
non-PCI devices anyway.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/external/bsd/drm2/nouveau/files.nouveau
cvs rdiff -u -r1.3 -r1.4 src/sys/external/bsd/drm2/nouveau/nouveau_module.c \
    src/sys/external/bsd/drm2/nouveau/nouveau_pci.c
cvs rdiff -u -r1.1 -r1.2 src/sys/external/bsd/drm2/nouveau/nouveau_pci.h
cvs rdiff -u -r1.2 -r1.3 src/sys/external/bsd/drm2/nouveau/nouveaufb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/external/bsd/drm2/nouveau/files.nouveau
diff -u src/sys/external/bsd/drm2/nouveau/files.nouveau:1.8 src/sys/external/bsd/drm2/nouveau/files.nouveau:1.9
--- src/sys/external/bsd/drm2/nouveau/files.nouveau:1.8	Fri Mar  6 01:43:07 2015
+++ src/sys/external/bsd/drm2/nouveau/files.nouveau	Sat Oct 17 12:02:44 2015
@@ -1,14 +1,15 @@
-#	$NetBSD: files.nouveau,v 1.8 2015/03/06 01:43:07 riastradh Exp $
+#	$NetBSD: files.nouveau,v 1.9 2015/10/17 12:02:44 jmcneill Exp $
 
 define	nouveaufbbus	{ }
-device	nouveau: drmkms, drmkms_pci, drmkms_ttm, nouveaufbbus
-attach	nouveau at pci
+device	nouveau: drmkms, drmkms_ttm, nouveaufbbus
+
+attach	nouveau at pci with nouveau_pci: drmkms_pci
+file	external/bsd/drm2/nouveau/nouveau_pci.c			nouveau
 
 device	nouveaufb: nouveaufbbus, drmfb, drmfb_pci, wsemuldisplaydev
 attach	nouveaufb at nouveaufbbus
 
 # Local additions.  External sources are listd below.
-file	external/bsd/drm2/nouveau/nouveau_pci.c			nouveau
 file	external/bsd/drm2/nouveau/nouveau_sysfs.c		nouveau
 file	external/bsd/drm2/nouveau/nouveau_vga.c			nouveau
 file	external/bsd/drm2/nouveau/nouveaufb.c			nouveaufb

Index: src/sys/external/bsd/drm2/nouveau/nouveau_module.c
diff -u src/sys/external/bsd/drm2/nouveau/nouveau_module.c:1.3 src/sys/external/bsd/drm2/nouveau/nouveau_module.c:1.4
--- src/sys/external/bsd/drm2/nouveau/nouveau_module.c:1.3	Wed Nov 12 03:14:00 2014
+++ src/sys/external/bsd/drm2/nouveau/nouveau_module.c	Sat Oct 17 12:02:44 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_module.c,v 1.3 2014/11/12 03:14:00 christos Exp $	*/
+/*	$NetBSD: nouveau_module.c,v 1.4 2015/10/17 12:02:44 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,13 +30,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_module.c,v 1.3 2014/11/12 03:14:00 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_module.c,v 1.4 2015/10/17 12:02:44 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/module.h>
-#ifndef _MODULE
-#include <sys/once.h>
-#endif
 #include <sys/systm.h>
 
 #include <drm/drmP.h>
@@ -45,7 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: nouveau_modu
 #include <core/object.h>
 #include <engine/device.h>
 
-MODULE(MODULE_CLASS_DRIVER, nouveau, "drmkms,drmkms_pci"); /* XXX drmkms_i2c, drmkms_ttm */
+MODULE(MODULE_CLASS_DRIVER, nouveau, "drmkms"); /* XXX drmkms_i2c, drmkms_ttm */
 
 #ifdef _MODULE
 #include "ioconf.c"
@@ -58,53 +55,20 @@ extern struct drm_driver *const nouveau_
 static int
 nouveau_init(void)
 {
-	extern int drm_guarantee_initialized(void);
-	int error;
-
-	error = drm_guarantee_initialized();
-	if (error)
-		return error;
-
-	error = drm_pci_init(nouveau_drm_driver, NULL);
-	if (error) {
-		aprint_error("nouveau: failed to init pci: %d\n", error);
-		return error;
-	}
-
 	nouveau_objects_init();
 	nouveau_devices_init();
-#if 0				/* XXX nouveau acpi */
-	nouveau_register_dsm_handler();
-#endif
 	drm_sysctl_init(&nouveau_def);
 
 	return 0;
 }
 
-int	nouveau_guarantee_initialized(void); /* XXX */
-int
-nouveau_guarantee_initialized(void)
-{
-#ifdef _MODULE
-	return 0;
-#else
-	static ONCE_DECL(nouveau_init_once);
-
-	return RUN_ONCE(&nouveau_init_once, &nouveau_init);
-#endif
-}
-
 static void
 nouveau_fini(void)
 {
 
 	drm_sysctl_fini(&nouveau_def);
-#if 0				/* XXX nouveau acpi */
-	nouveau_unregister_dsm_handler();
-#endif
 	nouveau_devices_fini();
 	nouveau_objects_fini();
-	drm_pci_exit(nouveau_drm_driver, NULL);
 }
 
 static int
@@ -114,11 +78,7 @@ nouveau_modcmd(modcmd_t cmd, void *arg _
 
 	switch (cmd) {
 	case MODULE_CMD_INIT:
-#ifdef _MODULE
 		error = nouveau_init();
-#else
-		error = nouveau_guarantee_initialized();
-#endif
 		if (error) {
 			aprint_error("nouveau: failed to initialize: %d\n",
 			    error);
Index: src/sys/external/bsd/drm2/nouveau/nouveau_pci.c
diff -u src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.3 src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.4
--- src/sys/external/bsd/drm2/nouveau/nouveau_pci.c:1.3	Fri Mar  6 15:39:28 2015
+++ src/sys/external/bsd/drm2/nouveau/nouveau_pci.c	Sat Oct 17 12:02:44 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_pci.c,v 1.3 2015/03/06 15:39:28 riastradh Exp $	*/
+/*	$NetBSD: nouveau_pci.c,v 1.4 2015/10/17 12:02:44 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -30,12 +30,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveau_pci.c,v 1.3 2015/03/06 15:39:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveau_pci.c,v 1.4 2015/10/17 12:02:44 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/device.h>
 #include <sys/queue.h>
 #include <sys/workqueue.h>
+#include <sys/module.h>
 
 #include <drm/drmP.h>
 
@@ -44,9 +45,11 @@ __KERNEL_RCSID(0, "$NetBSD: nouveau_pci.
 #include "nouveau_drm.h"
 #include "nouveau_pci.h"
 
-SIMPLEQ_HEAD(nouveau_task_head, nouveau_task);
+MODULE(MODULE_CLASS_DRIVER, nouveau_pci, "nouveau,drmkms_pci");
 
-struct nouveau_softc {
+SIMPLEQ_HEAD(nouveau_pci_task_head, nouveau_pci_task);
+
+struct nouveau_pci_softc {
 	device_t		sc_dev;
 	enum {
 		NOUVEAU_TASK_ATTACH,
@@ -54,40 +57,32 @@ struct nouveau_softc {
 	}			sc_task_state;
 	union {
 		struct workqueue		*workqueue;
-		struct nouveau_task_head	attach;
+		struct nouveau_pci_task_head	attach;
 	}			sc_task_u;
 	struct drm_device	*sc_drm_dev;
 	struct pci_dev		sc_pci_dev;
 	struct nouveau_device	*sc_nv_dev;
 };
 
-static int	nouveau_match(device_t, cfdata_t, void *);
-static void	nouveau_attach(device_t, device_t, void *);
-static int	nouveau_detach(device_t, int);
+static int	nouveau_pci_match(device_t, cfdata_t, void *);
+static void	nouveau_pci_attach(device_t, device_t, void *);
+static int	nouveau_pci_detach(device_t, int);
 
-static bool	nouveau_suspend(device_t, const pmf_qual_t *);
-static bool	nouveau_resume(device_t, const pmf_qual_t *);
+static bool	nouveau_pci_suspend(device_t, const pmf_qual_t *);
+static bool	nouveau_pci_resume(device_t, const pmf_qual_t *);
 
-static void	nouveau_task_work(struct work *, void *);
+static void	nouveau_pci_task_work(struct work *, void *);
 
-CFATTACH_DECL_NEW(nouveau, sizeof(struct nouveau_softc),
-    nouveau_match, nouveau_attach, nouveau_detach, NULL);
+CFATTACH_DECL_NEW(nouveau_pci, sizeof(struct nouveau_pci_softc),
+    nouveau_pci_match, nouveau_pci_attach, nouveau_pci_detach, NULL);
 
 /* Kludge to get this from nouveau_drm.c.  */
 extern struct drm_driver *const nouveau_drm_driver;
 
 static int
-nouveau_match(device_t parent, cfdata_t match, void *aux)
+nouveau_pci_match(device_t parent, cfdata_t match, void *aux)
 {
-	extern int nouveau_guarantee_initialized(void);
 	const struct pci_attach_args *const pa = aux;
-	int error;
-
-	error = nouveau_guarantee_initialized();
-	if (error) {
-		aprint_error("nouveau: failed to initialize: %d\n", error);
-		return 0;
-	}
 
 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_NVIDIA &&
 	    PCI_VENDOR(pa->pa_id) != PCI_VENDOR_NVIDIA_SGS)
@@ -103,9 +98,9 @@ extern char *nouveau_config;
 extern char *nouveau_debug;
 
 static void
-nouveau_attach(device_t parent, device_t self, void *aux)
+nouveau_pci_attach(device_t parent, device_t self, void *aux)
 {
-	struct nouveau_softc *const sc = device_private(self);
+	struct nouveau_pci_softc *const sc = device_private(self);
 	const struct pci_attach_args *const pa = aux;
 	uint64_t devname;
 	int error;
@@ -114,8 +109,8 @@ nouveau_attach(device_t parent, device_t
 
 	sc->sc_dev = self;
 
-	if (!pmf_device_register(self, &nouveau_suspend,
-		&nouveau_resume))
+	if (!pmf_device_register(self, &nouveau_pci_suspend,
+		&nouveau_pci_resume))
 		aprint_error_dev(self, "unable to establish power handler\n");
 
 	sc->sc_task_state = NOUVEAU_TASK_ATTACH;
@@ -142,7 +137,7 @@ nouveau_attach(device_t parent, device_t
 	}
 
 	while (!SIMPLEQ_EMPTY(&sc->sc_task_u.attach)) {
-		struct nouveau_task *const task =
+		struct nouveau_pci_task *const task =
 		    SIMPLEQ_FIRST(&sc->sc_task_u.attach);
 
 		SIMPLEQ_REMOVE_HEAD(&sc->sc_task_u.attach, nt_u.queue);
@@ -150,8 +145,8 @@ nouveau_attach(device_t parent, device_t
 	}
 
 	sc->sc_task_state = NOUVEAU_TASK_WORKQUEUE;
-	error = workqueue_create(&sc->sc_task_u.workqueue, "intelfb",
-	    &nouveau_task_work, NULL, PRI_NONE, IPL_NONE, WQ_MPSAFE);
+	error = workqueue_create(&sc->sc_task_u.workqueue, "nouveau_pci",
+	    &nouveau_pci_task_work, NULL, PRI_NONE, IPL_NONE, WQ_MPSAFE);
 	if (error) {
 		aprint_error_dev(self, "unable to create workqueue: %d\n",
 		    error);
@@ -161,9 +156,9 @@ nouveau_attach(device_t parent, device_t
 }
 
 static int
-nouveau_detach(device_t self, int flags)
+nouveau_pci_detach(device_t self, int flags)
 {
-	struct nouveau_softc *const sc = device_private(self);
+	struct nouveau_pci_softc *const sc = device_private(self);
 	int error;
 
 	/* XXX Check for in-use before tearing it all down...  */
@@ -199,36 +194,36 @@ out0:	pmf_device_deregister(self);
  * XXX Synchronize with nouveau_do_suspend in nouveau_drm.c.
  */
 static bool
-nouveau_suspend(device_t self, const pmf_qual_t *qual __unused)
+nouveau_pci_suspend(device_t self, const pmf_qual_t *qual __unused)
 {
-	struct nouveau_softc *const sc = device_private(self);
+	struct nouveau_pci_softc *const sc = device_private(self);
 	struct device *const dev = &sc->sc_pci_dev.dev; /* XXX KLUDGE */
 
 	return nouveau_pmops_suspend(dev) == 0;
 }
 
 static bool
-nouveau_resume(device_t self, const pmf_qual_t *qual)
+nouveau_pci_resume(device_t self, const pmf_qual_t *qual)
 {
-	struct nouveau_softc *const sc = device_private(self);
+	struct nouveau_pci_softc *const sc = device_private(self);
 	struct device *const dev = &sc->sc_pci_dev.dev; /* XXX KLUDGE */
 
 	return nouveau_pmops_resume(dev) == 0;
 }
 
 static void
-nouveau_task_work(struct work *work, void *cookie __unused)
+nouveau_pci_task_work(struct work *work, void *cookie __unused)
 {
-	struct nouveau_task *const task = container_of(work,
-	    struct nouveau_task, nt_u.work);
+	struct nouveau_pci_task *const task = container_of(work,
+	    struct nouveau_pci_task, nt_u.work);
 
 	(*task->nt_fn)(task);
 }
 
 int
-nouveau_task_schedule(device_t self, struct nouveau_task *task)
+nouveau_pci_task_schedule(device_t self, struct nouveau_pci_task *task)
 {
-	struct nouveau_softc *const sc = device_private(self);
+	struct nouveau_pci_softc *const sc = device_private(self);
 
 	switch (sc->sc_task_state) {
 	case NOUVEAU_TASK_ATTACH:
@@ -247,3 +242,33 @@ nouveau_task_schedule(device_t self, str
 		    (int)sc->sc_task_state);
 	}
 }
+
+static int
+nouveau_pci_modcmd(modcmd_t cmd, void *arg __unused)
+{
+	int error;
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		error = drm_pci_init(nouveau_drm_driver, NULL);
+		if (error) {
+			aprint_error("nouveau_pci: failed to init: %d\n",
+			    error);
+			return error;
+		}
+#if 0		/* XXX nouveau acpi */
+		nouveau_register_dsm_handler();
+#endif
+		break;
+	case MODULE_CMD_FINI:
+#if 0		/* XXX nouveau acpi */
+		nouveau_unregister_dsm_handler();
+#endif
+		drm_pci_exit(nouveau_drm_driver, NULL);
+		break;
+	default:
+		return ENOTTY;
+	}
+
+	return 0;
+}

Index: src/sys/external/bsd/drm2/nouveau/nouveau_pci.h
diff -u src/sys/external/bsd/drm2/nouveau/nouveau_pci.h:1.1 src/sys/external/bsd/drm2/nouveau/nouveau_pci.h:1.2
--- src/sys/external/bsd/drm2/nouveau/nouveau_pci.h:1.1	Fri Mar  6 01:43:07 2015
+++ src/sys/external/bsd/drm2/nouveau/nouveau_pci.h	Sat Oct 17 12:02:44 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveau_pci.h,v 1.1 2015/03/06 01:43:07 riastradh Exp $	*/
+/*	$NetBSD: nouveau_pci.h,v 1.2 2015/10/17 12:02:44 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -35,21 +35,21 @@
 #include <sys/queue.h>
 #include <sys/workqueue.h>
 
-struct nouveau_task {
+struct nouveau_pci_task {
 	union {
-		SIMPLEQ_ENTRY(nouveau_task)	queue;
+		SIMPLEQ_ENTRY(nouveau_pci_task)	queue;
 		struct work			work;
 	}			nt_u;
-	void			(*nt_fn)(struct nouveau_task *);
+	void			(*nt_fn)(struct nouveau_pci_task *);
 };
 
 static inline void
-nouveau_task_init(struct nouveau_task *task, void (*fn)(struct nouveau_task *))
+nouveau_pci_task_init(struct nouveau_pci_task *task, void (*fn)(struct nouveau_pci_task *))
 {
 
 	task->nt_fn = fn;
 }
 
-int	nouveau_task_schedule(device_t, struct nouveau_task *);
+int	nouveau_pci_task_schedule(device_t, struct nouveau_pci_task *);
 
 #endif	/* _NOUVEAU_NOUVEAU_PCI_H_ */

Index: src/sys/external/bsd/drm2/nouveau/nouveaufb.c
diff -u src/sys/external/bsd/drm2/nouveau/nouveaufb.c:1.2 src/sys/external/bsd/drm2/nouveau/nouveaufb.c:1.3
--- src/sys/external/bsd/drm2/nouveau/nouveaufb.c:1.2	Sat Apr  4 15:12:39 2015
+++ src/sys/external/bsd/drm2/nouveau/nouveaufb.c	Sat Oct 17 12:02:44 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: nouveaufb.c,v 1.2 2015/04/04 15:12:39 jmcneill Exp $	*/
+/*	$NetBSD: nouveaufb.c,v 1.3 2015/10/17 12:02:44 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nouveaufb.c,v 1.2 2015/04/04 15:12:39 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nouveaufb.c,v 1.3 2015/10/17 12:02:44 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/bus.h>
@@ -51,7 +51,7 @@ static int	nouveaufb_match(device_t, cfd
 static void	nouveaufb_attach(device_t, device_t, void *);
 static int	nouveaufb_detach(device_t, int);
 
-static void	nouveaufb_attach_task(struct nouveau_task *);
+static void	nouveaufb_attach_task(struct nouveau_pci_task *);
 
 static bool	nouveaufb_shutdown(device_t, int);
 static paddr_t	nouveaufb_drmfb_mmapfb(struct drmfb_softc *, off_t, int);
@@ -60,7 +60,7 @@ struct nouveaufb_softc {
 	struct drmfb_softc		sc_drmfb; /* XXX Must be first.  */
 	device_t			sc_dev;
 	struct nouveaufb_attach_args	sc_nfa;
-	struct nouveau_task		sc_attach_task;
+	struct nouveau_pci_task		sc_attach_task;
 	bool				sc_scheduled:1;
 	bool				sc_attached:1;
 };
@@ -97,8 +97,8 @@ nouveaufb_attach(device_t parent, device
 	aprint_naive("\n");
 	aprint_normal("\n");
 
-	nouveau_task_init(&sc->sc_attach_task, &nouveaufb_attach_task);
-	error = nouveau_task_schedule(parent, &sc->sc_attach_task);
+	nouveau_pci_task_init(&sc->sc_attach_task, &nouveaufb_attach_task);
+	error = nouveau_pci_task_schedule(parent, &sc->sc_attach_task);
 	if (error) {
 		aprint_error_dev(self, "failed to schedule mode set: %d\n",
 		    error);
@@ -137,7 +137,7 @@ nouveaufb_detach(device_t self, int flag
 }
 
 static void
-nouveaufb_attach_task(struct nouveau_task *task)
+nouveaufb_attach_task(struct nouveau_pci_task *task)
 {
 	struct nouveaufb_softc *const sc = container_of(task,
 	    struct nouveaufb_softc, sc_attach_task);

Reply via email to