Author: sephe
Date: Wed Jul 13 05:01:12 2016
New Revision: 302698
URL: https://svnweb.freebsd.org/changeset/base/302698

Log:
  hyperv/vmbus: Add vmbus method for GUID base device probing.
  
  Reduce the exposure of hv_device.
  
  MFC after:    1 week
  Sponsored by: Microsoft OSTC
  Differential Revision:        https://reviews.freebsd.org/D7024

Modified:
  head/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
  head/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
  head/sys/dev/hyperv/utilities/hv_heartbeat.c
  head/sys/dev/hyperv/utilities/hv_kvp.c
  head/sys/dev/hyperv/utilities/hv_shutdown.c
  head/sys/dev/hyperv/utilities/hv_timesync.c
  head/sys/dev/hyperv/vmbus/vmbus.c
  head/sys/dev/hyperv/vmbus/vmbus_if.m
  head/sys/modules/hyperv/utilities/Makefile

Modified: head/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
==============================================================================
--- head/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c  Wed Jul 13 04:51:37 
2016        (r302697)
+++ head/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c  Wed Jul 13 05:01:12 
2016        (r302698)
@@ -411,18 +411,12 @@ static const hv_guid g_net_vsc_device_ty
 static int
 netvsc_probe(device_t dev)
 {
-       const char *p;
-
-       p = vmbus_get_type(dev);
-       if (!memcmp(p, &g_net_vsc_device_type.data, sizeof(hv_guid))) {
+       if (VMBUS_PROBE_GUID(device_get_parent(dev), dev,
+           &g_net_vsc_device_type) == 0) {
                device_set_desc(dev, "Hyper-V Network Interface");
-               if (bootverbose)
-                       printf("Netvsc probe... DONE \n");
-
-               return (BUS_PROBE_DEFAULT);
+               return BUS_PROBE_DEFAULT;
        }
-
-       return (ENXIO);
+       return ENXIO;
 }
 
 /*

Modified: head/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
==============================================================================
--- head/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c        Wed Jul 13 
04:51:37 2016        (r302697)
+++ head/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c        Wed Jul 13 
05:01:12 2016        (r302698)
@@ -2167,13 +2167,11 @@ storvsc_free_request(struct storvsc_soft
 static enum hv_storage_type
 storvsc_get_storage_type(device_t dev)
 {
-       const char *p = vmbus_get_type(dev);
+       device_t parent = device_get_parent(dev);
 
-       if (!memcmp(p, &gBlkVscDeviceType, sizeof(hv_guid))) {
+       if (VMBUS_PROBE_GUID(parent, dev, &gBlkVscDeviceType) == 0)
                return DRIVER_BLKVSC;
-       } else if (!memcmp(p, &gStorVscDeviceType, sizeof(hv_guid))) {
+       if (VMBUS_PROBE_GUID(parent, dev, &gStorVscDeviceType) == 0)
                return DRIVER_STORVSC;
-       }
-       return (DRIVER_UNKNOWN);
+       return DRIVER_UNKNOWN;
 }
-

Modified: head/sys/dev/hyperv/utilities/hv_heartbeat.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_heartbeat.c        Wed Jul 13 04:51:37 
2016        (r302697)
+++ head/sys/dev/hyperv/utilities/hv_heartbeat.c        Wed Jul 13 05:01:12 
2016        (r302698)
@@ -36,9 +36,10 @@
 
 #include <dev/hyperv/include/hyperv.h>
 #include "hv_util.h"
+#include "vmbus_if.h"
 
 /* Heartbeat Service */
-static hv_guid service_guid = { .data =
+static const hv_guid service_guid = { .data =
        {0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
        0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d} };
 
@@ -93,16 +94,13 @@ hv_heartbeat_cb(void *context)
 static int
 hv_heartbeat_probe(device_t dev)
 {
-       const char *p = vmbus_get_type(dev);
-
        if (resource_disabled("hvheartbeat", 0))
                return ENXIO;
 
-       if (!memcmp(p, &service_guid, sizeof(hv_guid))) {
+       if (VMBUS_PROBE_GUID(device_get_parent(dev), dev, &service_guid) == 0) {
                device_set_desc(dev, "Hyper-V Heartbeat Service");
                return BUS_PROBE_DEFAULT;
        }
-
        return ENXIO;
 }
 

Modified: head/sys/dev/hyperv/utilities/hv_kvp.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_kvp.c      Wed Jul 13 04:51:37 2016        
(r302697)
+++ head/sys/dev/hyperv/utilities/hv_kvp.c      Wed Jul 13 05:01:12 2016        
(r302698)
@@ -69,6 +69,7 @@ __FBSDID("$FreeBSD$");
 #include "hv_util.h"
 #include "unicode.h"
 #include "hv_kvp.h"
+#include "vmbus_if.h"
 
 /* hv_kvp defines */
 #define BUFFERSIZE     sizeof(struct hv_kvp_msg)
@@ -89,7 +90,7 @@ static int hv_kvp_log = 0;
                log(LOG_INFO, "hv_kvp: " __VA_ARGS__);          \
 } while (0)
 
-static hv_guid service_guid = { .data =
+static const hv_guid service_guid = { .data =
        {0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d,
        0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3,  0xe6} };
 
@@ -865,16 +866,13 @@ hv_kvp_dev_daemon_poll(struct cdev *dev,
 static int
 hv_kvp_probe(device_t dev)
 {
-       const char *p = vmbus_get_type(dev);
-
        if (resource_disabled("hvkvp", 0))
                return ENXIO;
 
-       if (!memcmp(p, &service_guid, sizeof(hv_guid))) {
+       if (VMBUS_PROBE_GUID(device_get_parent(dev), dev, &service_guid) == 0) {
                device_set_desc(dev, "Hyper-V KVP Service");
                return BUS_PROBE_DEFAULT;
        }
-
        return ENXIO;
 }
 

Modified: head/sys/dev/hyperv/utilities/hv_shutdown.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_shutdown.c Wed Jul 13 04:51:37 2016        
(r302697)
+++ head/sys/dev/hyperv/utilities/hv_shutdown.c Wed Jul 13 05:01:12 2016        
(r302698)
@@ -41,8 +41,9 @@
 
 #include <dev/hyperv/include/hyperv.h>
 #include "hv_util.h"
+#include "vmbus_if.h"
 
-static hv_guid service_guid = { .data =
+static const hv_guid service_guid = { .data =
        {0x31, 0x60, 0x0B, 0X0E, 0x13, 0x52, 0x34, 0x49,
        0x81, 0x8B, 0x38, 0XD9, 0x0C, 0xED, 0x39, 0xDB} };
 
@@ -115,16 +116,13 @@ hv_shutdown_cb(void *context)
 static int
 hv_shutdown_probe(device_t dev)
 {
-       const char *p = vmbus_get_type(dev);
-
        if (resource_disabled("hvshutdown", 0))
                return ENXIO;
 
-       if (!memcmp(p, &service_guid, sizeof(hv_guid))) {
+       if (VMBUS_PROBE_GUID(device_get_parent(dev), dev, &service_guid) == 0) {
                device_set_desc(dev, "Hyper-V Shutdown Service");
                return BUS_PROBE_DEFAULT;
        }
-
        return ENXIO;
 }
 

Modified: head/sys/dev/hyperv/utilities/hv_timesync.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_timesync.c Wed Jul 13 04:51:37 2016        
(r302697)
+++ head/sys/dev/hyperv/utilities/hv_timesync.c Wed Jul 13 05:01:12 2016        
(r302698)
@@ -41,6 +41,7 @@
 
 #include <dev/hyperv/include/hyperv.h>
 #include "hv_util.h"
+#include "vmbus_if.h"
 
 #define HV_WLTIMEDELTA              116444736000000000L     /* in 100ns unit */
 #define HV_ICTIMESYNCFLAG_PROBE     0
@@ -54,7 +55,7 @@ typedef struct {
 } time_sync_data;
 
         /* Time Synch Service */
-static hv_guid service_guid = {.data =
+static const hv_guid service_guid = {.data =
        {0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49,
        0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf } };
 
@@ -170,16 +171,13 @@ hv_timesync_cb(void *context)
 static int
 hv_timesync_probe(device_t dev)
 {
-       const char *p = vmbus_get_type(dev);
-
        if (resource_disabled("hvtimesync", 0))
                return ENXIO;
 
-       if (!memcmp(p, &service_guid, sizeof(hv_guid))) {
+       if (VMBUS_PROBE_GUID(device_get_parent(dev), dev, &service_guid) == 0) {
                device_set_desc(dev, "Hyper-V Time Synch Service");
                return BUS_PROBE_DEFAULT;
        }
-
        return ENXIO;
 }
 

Modified: head/sys/dev/hyperv/vmbus/vmbus.c
==============================================================================
--- head/sys/dev/hyperv/vmbus/vmbus.c   Wed Jul 13 04:51:37 2016        
(r302697)
+++ head/sys/dev/hyperv/vmbus/vmbus.c   Wed Jul 13 05:01:12 2016        
(r302698)
@@ -1090,6 +1090,16 @@ vmbus_get_version_method(device_t bus, d
 }
 
 static int
+vmbus_probe_guid_method(device_t bus, device_t dev, const struct hv_guid *guid)
+{
+       struct hv_device *hv_dev = device_get_ivars(dev);
+
+       if (memcmp(&hv_dev->class_id, guid, sizeof(struct hv_guid)) == 0)
+               return 0;
+       return ENXIO;
+}
+
+static int
 vmbus_probe(device_t dev)
 {
        char *id[] = { "VMBUS", NULL };
@@ -1306,6 +1316,7 @@ static device_method_t vmbus_methods[] =
 
        /* Vmbus interface */
        DEVMETHOD(vmbus_get_version,            vmbus_get_version_method),
+       DEVMETHOD(vmbus_probe_guid,             vmbus_probe_guid_method),
 
        DEVMETHOD_END
 };

Modified: head/sys/dev/hyperv/vmbus/vmbus_if.m
==============================================================================
--- head/sys/dev/hyperv/vmbus/vmbus_if.m        Wed Jul 13 04:51:37 2016        
(r302697)
+++ head/sys/dev/hyperv/vmbus/vmbus_if.m        Wed Jul 13 05:01:12 2016        
(r302698)
@@ -31,7 +31,17 @@
 
 INTERFACE vmbus;
 
+HEADER {
+       struct hv_guid;
+};
+
 METHOD uint32_t get_version {
        device_t bus;
        device_t dev;
 };
+
+METHOD int probe_guid {
+       device_t bus;
+       device_t dev;
+       const struct hv_guid *guid;
+};

Modified: head/sys/modules/hyperv/utilities/Makefile
==============================================================================
--- head/sys/modules/hyperv/utilities/Makefile  Wed Jul 13 04:51:37 2016        
(r302697)
+++ head/sys/modules/hyperv/utilities/Makefile  Wed Jul 13 05:01:12 2016        
(r302698)
@@ -4,7 +4,7 @@
 
 KMOD=  hv_utils
 SRCS=  hv_util.c hv_kvp.c hv_timesync.c hv_shutdown.c hv_heartbeat.c
-SRCS+= bus_if.h device_if.h
+SRCS+= bus_if.h device_if.h vmbus_if.h
 
 CFLAGS+= -I${.CURDIR}/../../../dev/hyperv/include \
         -I${.CURDIR}/../../../dev/hyperv/vmbus
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to