Author: sephe
Date: Thu Jun 23 03:14:09 2016
New Revision: 302112
URL: https://svnweb.freebsd.org/changeset/base/302112

Log:
  MFC 300122,300123,300124,300126,300127,300129,300455
  
  300122
      hyperv: Set vm_guest to VM_GUEST_VM, if hypervisor is not Hyper-V
  
      Reviewed by:        kib
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6412
  
  300123
      hyperv/vmbus: Staticize vmbus_devclass
  
      Reviewed by:        Jun Su <junsu microsoft com>
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6414
  
  300124
      hyperv/vmbus: Reindent and cleanup devmethods.
  
      While I'm here, use DEVMETHOD_END.
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6415
  
  300126
      hyperv/vmbus: Fix SYSINIT function prototype and usage.
  
      Reviewed by:        Jun Su <junsu microsoft com>
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6416
  
  300127
      hyperv/vmbus: Minor function definition style fixup
  
      Reviewed by:        Jun Su <junsu microsoft com>
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6417
  
  300129
      hyperv/vmbus: Use consistent device description as other devices
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6418
  
  300455
      hyperv: Move guest id setup to early place
  
      And
      - Rework the guest id composition.
      - Nuke useless saved guest_id.
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6430

Modified:
  stable/10/sys/dev/hyperv/vmbus/hv_connection.c
  stable/10/sys/dev/hyperv/vmbus/hv_hv.c
  stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
  stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/hyperv/vmbus/hv_connection.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_connection.c      Thu Jun 23 02:53:24 
2016        (r302111)
+++ stable/10/sys/dev/hyperv/vmbus/hv_connection.c      Thu Jun 23 03:14:09 
2016        (r302112)
@@ -152,7 +152,8 @@ hv_vmbus_negotiate_version(hv_vmbus_chan
  * Send a connect request on the partition service connection
  */
 int
-hv_vmbus_connect(void) {
+hv_vmbus_connect(void)
+{
        int                                     ret = 0;
        uint32_t                                version;
        hv_vmbus_channel_msg_info*              msg_info = NULL;
@@ -274,7 +275,8 @@ hv_vmbus_connect(void) {
  * Send a disconnect request on the partition service connection
  */
 int
-hv_vmbus_disconnect(void) {
+hv_vmbus_disconnect(void)
+{
        int                      ret = 0;
        hv_vmbus_channel_unload  msg;
 
@@ -398,7 +400,8 @@ int hv_vmbus_post_message(void *buffer, 
  * Send an event notification to the parent
  */
 int
-hv_vmbus_set_event(hv_vmbus_channel *channel) {
+hv_vmbus_set_event(hv_vmbus_channel *channel)
+{
        int ret = 0;
        uint32_t child_rel_id = channel->offer_msg.child_rel_id;
 

Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_hv.c      Thu Jun 23 02:53:24 2016        
(r302111)
+++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c      Thu Jun 23 03:14:09 2016        
(r302112)
@@ -50,6 +50,35 @@ __FBSDID("$FreeBSD$");
 
 #define        HYPERV_INTERFACE                0x31237648      /* HV#1 */
 
+/*
+ * The guest OS needs to register the guest ID with the hypervisor.
+ * The guest ID is a 64 bit entity and the structure of this ID is
+ * specified in the Hyper-V specification:
+ *
+ * http://msdn.microsoft.com/en-us/library/windows/
+ * hardware/ff542653%28v=vs.85%29.aspx
+ *
+ * While the current guideline does not specify how FreeBSD guest ID(s)
+ * need to be generated, our plan is to publish the guidelines for
+ * FreeBSD and other guest operating systems that currently are hosted
+ * on Hyper-V. The implementation here conforms to this yet
+ * unpublished guidelines.
+ *
+ * Bit(s)
+ * 63    - Indicates if the OS is Open Source or not; 1 is Open Source
+ * 62:56 - Os Type: FreeBSD is 0x02
+ * 55:48 - Distro specific identification
+ * 47:16 - FreeBSD kernel version number
+ * 15:0  - Distro specific identification
+ */
+#define HYPERV_GUESTID_OSS             (0x1ULL << 63)
+#define HYPERV_GUESTID_FREEBSD         (0x02ULL << 56)
+#define HYPERV_GUESTID(id)                             \
+       (HYPERV_GUESTID_OSS | HYPERV_GUESTID_FREEBSD |  \
+        (((uint64_t)(((id) & 0xff0000) >> 16)) << 48) |\
+        (((uint64_t)__FreeBSD_version) << 16) |        \
+        ((uint64_t)((id) & 0x00ffff)))
+
 static u_int hv_get_timecount(struct timecounter *tc);
 
 u_int  hyperv_features;
@@ -143,13 +172,6 @@ hv_vmbus_init(void) 
            goto cleanup;
 
        /*
-        * Write our OS info
-        */
-       uint64_t os_guest_info = HV_FREEBSD_GUEST_ID;
-       wrmsr(HV_X64_MSR_GUEST_OS_ID, os_guest_info);
-       hv_vmbus_g_context.guest_id = os_guest_info;
-
-       /*
         * See if the hypercall page is already set
         */
        hypercall_msr.as_uint64_t = rdmsr(HV_X64_MSR_HYPERCALL);
@@ -192,16 +214,13 @@ hv_vmbus_init(void) 
 void
 hv_vmbus_cleanup(void) 
 {
-       hv_vmbus_x64_msr_hypercall_contents hypercall_msr;
+       if (hv_vmbus_g_context.hypercall_page != NULL) {
+               hv_vmbus_x64_msr_hypercall_contents hypercall_msr;
 
-       if (hv_vmbus_g_context.guest_id == HV_FREEBSD_GUEST_ID) {
-           if (hv_vmbus_g_context.hypercall_page != NULL) {
                hypercall_msr.as_uint64_t = 0;
-               wrmsr(HV_X64_MSR_HYPERCALL,
-                                       hypercall_msr.as_uint64_t);
+               wrmsr(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64_t);
                free(hv_vmbus_g_context.hypercall_page, M_DEVBUF);
                hv_vmbus_g_context.hypercall_page = NULL;
-           }
        }
 }
 
@@ -501,8 +520,15 @@ hyperv_identify(void)
 static void
 hyperv_init(void *dummy __unused)
 {
-       if (!hyperv_identify())
+       if (!hyperv_identify()) {
+               /* Not Hyper-V; reset guest id to the generic one. */
+               if (vm_guest == VM_GUEST_HV)
+                       vm_guest = VM_GUEST_VM;
                return;
+       }
+
+       /* Write guest id */
+       wrmsr(HV_X64_MSR_GUEST_OS_ID, HYPERV_GUESTID(0));
 
        if (hyperv_features & HV_FEATURE_MSR_TIME_REFCNT) {
                /* Register virtual timecount */

Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c       Thu Jun 23 
02:53:24 2016        (r302111)
+++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c       Thu Jun 23 
03:14:09 2016        (r302112)
@@ -346,12 +346,13 @@ hv_vmbus_child_device_unregister(struct 
 }
 
 static int
-vmbus_probe(device_t dev) {
+vmbus_probe(device_t dev)
+{
        if (ACPI_ID_PROBE(device_get_parent(dev), dev, vmbus_ids) == NULL ||
            device_get_unit(dev) != 0)
                return (ENXIO);
 
-       device_set_desc(dev, "Vmbus Devices");
+       device_set_desc(dev, "Hyper-V Vmbus");
 
        return (BUS_PROBE_DEFAULT);
 }
@@ -624,7 +625,7 @@ vmbus_attach(device_t dev)
 }
 
 static void
-vmbus_init(void)
+vmbus_sysinit(void *arg __unused)
 {
        if (vm_guest != VM_GUEST_HV || vmbus_get_softc() == NULL)
                return;
@@ -670,22 +671,23 @@ vmbus_detach(device_t dev)
 }
 
 static device_method_t vmbus_methods[] = {
-       /** Device interface */
-       DEVMETHOD(device_probe, vmbus_probe),
-       DEVMETHOD(device_attach, vmbus_attach),
-       DEVMETHOD(device_detach, vmbus_detach),
-       DEVMETHOD(device_shutdown, bus_generic_shutdown),
-       DEVMETHOD(device_suspend, bus_generic_suspend),
-       DEVMETHOD(device_resume, bus_generic_resume),
-
-       /** Bus interface */
-       DEVMETHOD(bus_add_child, bus_generic_add_child),
-       DEVMETHOD(bus_print_child, bus_generic_print_child),
-       DEVMETHOD(bus_read_ivar, vmbus_read_ivar),
-       DEVMETHOD(bus_write_ivar, vmbus_write_ivar),
-       DEVMETHOD(bus_child_pnpinfo_str, vmbus_child_pnpinfo_str),
+       /* Device interface */
+       DEVMETHOD(device_probe,                 vmbus_probe),
+       DEVMETHOD(device_attach,                vmbus_attach),
+       DEVMETHOD(device_detach,                vmbus_detach),
+       DEVMETHOD(device_shutdown,              bus_generic_shutdown),
+       DEVMETHOD(device_suspend,               bus_generic_suspend),
+       DEVMETHOD(device_resume,                bus_generic_resume),
+
+       /* Bus interface */
+       DEVMETHOD(bus_add_child,                bus_generic_add_child),
+       DEVMETHOD(bus_print_child,              bus_generic_print_child),
+       DEVMETHOD(bus_read_ivar,                vmbus_read_ivar),
+       DEVMETHOD(bus_write_ivar,               vmbus_write_ivar),
+       DEVMETHOD(bus_child_pnpinfo_str,        vmbus_child_pnpinfo_str),
 
-       { 0, 0 } };
+       DEVMETHOD_END
+};
 
 static driver_t vmbus_driver = {
        "vmbus",
@@ -693,12 +695,16 @@ static driver_t vmbus_driver = {
        sizeof(struct vmbus_softc)
 };
 
-devclass_t vmbus_devclass;
+static devclass_t vmbus_devclass;
 
 DRIVER_MODULE(vmbus, acpi, vmbus_driver, vmbus_devclass, NULL, NULL);
 MODULE_DEPEND(vmbus, acpi, 1, 1, 1);
 MODULE_VERSION(vmbus, 1);
 
-/* We want to be started after SMP is initialized */
-SYSINIT(vmb_init, SI_SUB_SMP + 1, SI_ORDER_FIRST, vmbus_init, NULL);
+/*
+ * NOTE:
+ * We have to start as the last step of SI_SUB_SMP, i.e. after SMP is
+ * initialized.
+ */
+SYSINIT(vmbus_initialize, SI_SUB_SMP, SI_ORDER_ANY, vmbus_sysinit, NULL);
 

Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h      Thu Jun 23 02:53:24 
2016        (r302111)
+++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h      Thu Jun 23 03:14:09 
2016        (r302112)
@@ -198,7 +198,6 @@ enum {
 #define HV_HYPERCALL_PARAM_ALIGN sizeof(uint64_t)
 
 typedef struct {
-       uint64_t        guest_id;
        void*           hypercall_page;
        hv_bool_uint8_t syn_ic_initialized;
 
@@ -763,44 +762,6 @@ void                       hv_et_intr(struct trapframe*);
 /* Wait for device creation */
 void                   vmbus_scan(void);
 
-/*
- * The guest OS needs to register the guest ID with the hypervisor.
- * The guest ID is a 64 bit entity and the structure of this ID is
- * specified in the Hyper-V specification:
- *
- * http://msdn.microsoft.com/en-us/library/windows/
- * hardware/ff542653%28v=vs.85%29.aspx
- *
- * While the current guideline does not specify how FreeBSD guest ID(s)
- * need to be generated, our plan is to publish the guidelines for
- * FreeBSD and other guest operating systems that currently are hosted
- * on Hyper-V. The implementation here conforms to this yet
- * unpublished guidelines.
- *
- * Bit(s)
- * 63 - Indicates if the OS is Open Source or not; 1 is Open Source
- * 62:56 - Os Type; Linux is 0x100, FreeBSD is 0x200
- * 55:48 - Distro specific identification
- * 47:16 - FreeBSD kernel version number
- * 15:0  - Distro specific identification
- *
- */
-
-#define HV_FREEBSD_VENDOR_ID   0x8200
-#define HV_FREEBSD_GUEST_ID    hv_generate_guest_id(0,0)
-
-static inline  uint64_t hv_generate_guest_id(
-       uint8_t distro_id_part1,
-       uint16_t distro_id_part2)
-{
-       uint64_t guest_id;
-       guest_id =  (((uint64_t)HV_FREEBSD_VENDOR_ID) << 48);
-       guest_id |= (((uint64_t)(distro_id_part1)) << 48);
-       guest_id |= (((uint64_t)(__FreeBSD_version)) << 16); /* in param.h */
-       guest_id |= ((uint64_t)(distro_id_part2));
-       return guest_id;
-}
-
 typedef struct {
        unsigned int    vector;
        void            *page_buffers[2 * MAXCPU];
_______________________________________________
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