Author: marcel
Date: Sun Jul 19 23:37:45 2015
New Revision: 285707
URL: https://svnweb.freebsd.org/changeset/base/285707

Log:
  Check the hw.proto.attach environment variable for devices that
  proto(4) should attach to instead of the normal driver.
  
  Document the variable.

Modified:
  head/share/man/man4/proto.4
  head/sys/dev/proto/proto.h
  head/sys/dev/proto/proto_bus_isa.c
  head/sys/dev/proto/proto_bus_pci.c
  head/sys/dev/proto/proto_core.c

Modified: head/share/man/man4/proto.4
==============================================================================
--- head/share/man/man4/proto.4 Sun Jul 19 22:26:02 2015        (r285706)
+++ head/share/man/man4/proto.4 Sun Jul 19 23:37:45 2015        (r285707)
@@ -25,7 +25,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd July 3, 2015
+.Dd July 19, 2015
 .Dt PROTO 4
 .Os
 .\"
@@ -47,6 +47,12 @@ module at boot time, place the following
 .Bd -literal -offset indent
 proto_load="YES"
 .Ed
+.Pp
+To have the driver attach to a device instead of its regular driver,
+mention it in the list of devices assigned to the following loader variable:
+.Bd -ragged -offset indent
+hw.proto.attach="desc[,desc]"
+.Ed
 .\"
 .Sh DESCRIPTION
 The

Modified: head/sys/dev/proto/proto.h
==============================================================================
--- head/sys/dev/proto/proto.h  Sun Jul 19 22:26:02 2015        (r285706)
+++ head/sys/dev/proto/proto.h  Sun Jul 19 23:37:45 2015        (r285707)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2014 Marcel Moolenaar
+ * Copyright (c) 2014, 2015 Marcel Moolenaar
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -61,6 +61,7 @@ extern char proto_driver_name[];
 
 int proto_add_resource(struct proto_softc *, int, int, struct resource *);
 
+int proto_probe(device_t dev, const char *prefix, char ***devnamesp);
 int proto_attach(device_t dev);
 int proto_detach(device_t dev);
 

Modified: head/sys/dev/proto/proto_bus_isa.c
==============================================================================
--- head/sys/dev/proto/proto_bus_isa.c  Sun Jul 19 22:26:02 2015        
(r285706)
+++ head/sys/dev/proto/proto_bus_isa.c  Sun Jul 19 23:37:45 2015        
(r285707)
@@ -59,6 +59,9 @@ static driver_t proto_isa_driver = {
        sizeof(struct proto_softc),
 };
 
+static char proto_isa_prefix[] = "isa";
+static char **proto_isa_devnames;
+
 static int
 proto_isa_probe(device_t dev)
 {
@@ -77,12 +80,12 @@ proto_isa_probe(device_t dev)
                return (ENODEV);
 
        sb = sbuf_new_auto();
-       sbuf_printf(sb, "isa:%#lx", rman_get_start(res));
+       sbuf_printf(sb, "%s:%#lx", proto_isa_prefix, rman_get_start(res));
        sbuf_finish(sb);
        device_set_desc_copy(dev, sbuf_data(sb));
        sbuf_delete(sb);
        bus_release_resource(dev, type, rid, res);
-       return (BUS_PROBE_HOOVER);
+       return (proto_probe(dev, proto_isa_prefix, &proto_isa_devnames));
 }
 
 static int

Modified: head/sys/dev/proto/proto_bus_pci.c
==============================================================================
--- head/sys/dev/proto/proto_bus_pci.c  Sun Jul 19 22:26:02 2015        
(r285706)
+++ head/sys/dev/proto/proto_bus_pci.c  Sun Jul 19 23:37:45 2015        
(r285707)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2014 Marcel Moolenaar
+ * Copyright (c) 2014, 2015 Marcel Moolenaar
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -59,6 +59,9 @@ static driver_t proto_pci_driver = {
        sizeof(struct proto_softc),
 };
 
+static char proto_pci_prefix[] = "pci";
+static char **proto_pci_devnames;
+
 static int
 proto_pci_probe(device_t dev)
 {
@@ -68,12 +71,12 @@ proto_pci_probe(device_t dev)
                return (ENXIO);
 
        sb = sbuf_new_auto();
-       sbuf_printf(sb, "pci%d:%d:%d:%d", pci_get_domain(dev),
+       sbuf_printf(sb, "%s%d:%d:%d:%d", proto_pci_prefix, pci_get_domain(dev),
            pci_get_bus(dev), pci_get_slot(dev), pci_get_function(dev));
        sbuf_finish(sb);
        device_set_desc_copy(dev, sbuf_data(sb));
        sbuf_delete(sb);
-       return (BUS_PROBE_HOOVER);
+       return (proto_probe(dev, proto_pci_prefix, &proto_pci_devnames));
 }
 
 static int

Modified: head/sys/dev/proto/proto_core.c
==============================================================================
--- head/sys/dev/proto/proto_core.c     Sun Jul 19 22:26:02 2015        
(r285706)
+++ head/sys/dev/proto/proto_core.c     Sun Jul 19 23:37:45 2015        
(r285707)
@@ -1,5 +1,5 @@
 /*-
- * Copyright (c) 2014 Marcel Moolenaar
+ * Copyright (c) 2014, 2015 Marcel Moolenaar
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -120,6 +120,62 @@ proto_intr(void *arg)
 #endif
 
 int
+proto_probe(device_t dev, const char *prefix, char ***devnamesp)
+{
+       char **devnames = *devnamesp;
+       const char *dn, *ep, *ev;
+       size_t pfxlen;
+       int idx, names;
+
+       if (devnames == NULL) {
+               pfxlen = strlen(prefix);
+               names = 1;      /* NULL pointer */
+               ev = kern_getenv("hw.proto.attach");
+               if (ev != NULL) {
+                       dn = ev;
+                       while (*dn != '\0') {
+                               ep = dn;
+                               while (*ep != ',' && *ep != '\0')
+                                       ep++;
+                               if ((ep - dn) > pfxlen &&
+                                   strncmp(dn, prefix, pfxlen) == 0)
+                                       names++;
+                               dn = (*ep == ',') ? ep + 1 : ep;
+                       }
+               }
+               devnames = malloc(names * sizeof(caddr_t), M_DEVBUF,
+                   M_WAITOK | M_ZERO);
+               *devnamesp = devnames;
+               if (ev != NULL) {
+                       dn = ev;
+                       idx = 0;
+                       while (*dn != '\0') {
+                               ep = dn;
+                               while (*ep != ',' && *ep != '\0')
+                                       ep++;
+                               if ((ep - dn) > pfxlen &&
+                                   strncmp(dn, prefix, pfxlen) == 0) {
+                                       devnames[idx] = malloc(ep - dn + 1,
+                                           M_DEVBUF, M_WAITOK | M_ZERO);
+                                       memcpy(devnames[idx], dn, ep - dn);
+                                       idx++;
+                               }
+                               dn = (*ep == ',') ? ep + 1 : ep;
+                       }
+                       freeenv(__DECONST(char *, ev));
+               }
+       }
+
+       dn = device_get_desc(dev);
+       while (*devnames != NULL) {
+               if (strcmp(dn, *devnames) == 0)
+                       return (BUS_PROBE_SPECIFIC);
+               devnames++;
+       }
+       return (BUS_PROBE_HOOVER);
+}
+
+int
 proto_attach(device_t dev)
 {
        struct proto_softc *sc;
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to