hyperv/util: Factor out helper for IC device_probe DEVMETHOD
MFC after: 1 week Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D7530
This commit is contained in:
parent
50ac04f160
commit
c24d51a7f2
@ -41,10 +41,15 @@
|
||||
#include "hv_util.h"
|
||||
#include "vmbus_if.h"
|
||||
|
||||
/* Heartbeat Service */
|
||||
static const struct hyperv_guid service_guid = { .hv_guid =
|
||||
{0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
|
||||
0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d} };
|
||||
static const struct vmbus_ic_desc vmbus_heartbeat_descs[] = {
|
||||
{
|
||||
.ic_guid = { .hv_guid = {
|
||||
0x39, 0x4f, 0x16, 0x57, 0x15, 0x91, 0x78, 0x4e,
|
||||
0xab, 0x55, 0x38, 0x2f, 0x3b, 0xd5, 0x42, 0x2d} },
|
||||
.ic_desc = "Hyper-V Heartbeat"
|
||||
},
|
||||
VMBUS_IC_DESC_END
|
||||
};
|
||||
|
||||
/**
|
||||
* Process heartbeat message
|
||||
@ -96,14 +101,8 @@ hv_heartbeat_cb(struct vmbus_channel *channel, void *context)
|
||||
static int
|
||||
hv_heartbeat_probe(device_t dev)
|
||||
{
|
||||
if (resource_disabled("hvheartbeat", 0))
|
||||
return ENXIO;
|
||||
|
||||
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;
|
||||
return (vmbus_ic_probe(dev, vmbus_heartbeat_descs));
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -87,9 +87,15 @@ static int hv_kvp_log = 0;
|
||||
log(LOG_INFO, "hv_kvp: " __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
static const struct hyperv_guid service_guid = { .hv_guid =
|
||||
{0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d,
|
||||
0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6} };
|
||||
static const struct vmbus_ic_desc vmbus_kvp_descs[] = {
|
||||
{
|
||||
.ic_guid = { .hv_guid = {
|
||||
0xe7, 0xf4, 0xa0, 0xa9, 0x45, 0x5a, 0x96, 0x4d,
|
||||
0xb8, 0x27, 0x8a, 0x84, 0x1e, 0x8c, 0x3, 0xe6 } },
|
||||
.ic_desc = "Hyper-V KVP"
|
||||
},
|
||||
VMBUS_IC_DESC_END
|
||||
};
|
||||
|
||||
/* character device prototypes */
|
||||
static d_open_t hv_kvp_dev_open;
|
||||
@ -867,14 +873,8 @@ hv_kvp_dev_daemon_poll(struct cdev *dev, int events, struct thread *td)
|
||||
static int
|
||||
hv_kvp_probe(device_t dev)
|
||||
{
|
||||
if (resource_disabled("hvkvp", 0))
|
||||
return ENXIO;
|
||||
|
||||
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;
|
||||
return (vmbus_ic_probe(dev, vmbus_kvp_descs));
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -46,9 +46,15 @@
|
||||
#include "hv_util.h"
|
||||
#include "vmbus_if.h"
|
||||
|
||||
static const struct hyperv_guid service_guid = { .hv_guid =
|
||||
{0x31, 0x60, 0x0B, 0X0E, 0x13, 0x52, 0x34, 0x49,
|
||||
0x81, 0x8B, 0x38, 0XD9, 0x0C, 0xED, 0x39, 0xDB} };
|
||||
static const struct vmbus_ic_desc vmbus_shutdown_descs[] = {
|
||||
{
|
||||
.ic_guid = { .hv_guid = {
|
||||
0x31, 0x60, 0x0b, 0x0e, 0x13, 0x52, 0x34, 0x49,
|
||||
0x81, 0x8b, 0x38, 0xd9, 0x0c, 0xed, 0x39, 0xdb } },
|
||||
.ic_desc = "Hyper-V Shutdown"
|
||||
},
|
||||
VMBUS_IC_DESC_END
|
||||
};
|
||||
|
||||
/**
|
||||
* Shutdown
|
||||
@ -118,14 +124,8 @@ hv_shutdown_cb(struct vmbus_channel *channel, void *context)
|
||||
static int
|
||||
hv_shutdown_probe(device_t dev)
|
||||
{
|
||||
if (resource_disabled("hvshutdown", 0))
|
||||
return ENXIO;
|
||||
|
||||
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;
|
||||
return (vmbus_ic_probe(dev, vmbus_shutdown_descs));
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -58,10 +58,15 @@ typedef struct {
|
||||
uint64_t data;
|
||||
} time_sync_data;
|
||||
|
||||
/* Time Synch Service */
|
||||
static const struct hyperv_guid service_guid = {.hv_guid =
|
||||
{0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49,
|
||||
0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf } };
|
||||
static const struct vmbus_ic_desc vmbus_timesync_descs[] = {
|
||||
{
|
||||
.ic_guid = { .hv_guid = {
|
||||
0x30, 0xe6, 0x27, 0x95, 0xae, 0xd0, 0x7b, 0x49,
|
||||
0xad, 0xce, 0xe8, 0x0a, 0xb0, 0x17, 0x5c, 0xaf } },
|
||||
.ic_desc = "Hyper-V Timesync"
|
||||
},
|
||||
VMBUS_IC_DESC_END
|
||||
};
|
||||
|
||||
struct hv_ictimesync_data {
|
||||
uint64_t parenttime;
|
||||
@ -174,14 +179,8 @@ hv_timesync_cb(struct vmbus_channel *channel, void *context)
|
||||
static int
|
||||
hv_timesync_probe(device_t dev)
|
||||
{
|
||||
if (resource_disabled("hvtimesync", 0))
|
||||
return ENXIO;
|
||||
|
||||
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;
|
||||
return (vmbus_ic_probe(dev, vmbus_timesync_descs));
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -42,7 +42,9 @@
|
||||
#include <dev/hyperv/include/hyperv.h>
|
||||
#include <dev/hyperv/include/vmbus.h>
|
||||
#include <dev/hyperv/utilities/hv_utilreg.h>
|
||||
#include "hv_util.h"
|
||||
#include <dev/hyperv/utilities/hv_util.h>
|
||||
|
||||
#include "vmbus_if.h"
|
||||
|
||||
#define VMBUS_IC_BRSIZE (4 * PAGE_SIZE)
|
||||
|
||||
@ -74,6 +76,24 @@ hv_negotiate_version(struct hv_vmbus_icmsg_hdr *icmsghdrp, uint8_t *buf)
|
||||
negop->icmsg_vercnt = 1;
|
||||
}
|
||||
|
||||
int
|
||||
vmbus_ic_probe(device_t dev, const struct vmbus_ic_desc descs[])
|
||||
{
|
||||
device_t bus = device_get_parent(dev);
|
||||
const struct vmbus_ic_desc *d;
|
||||
|
||||
if (resource_disabled(device_get_name(dev), 0))
|
||||
return (ENXIO);
|
||||
|
||||
for (d = descs; d->ic_desc != NULL; ++d) {
|
||||
if (VMBUS_PROBE_GUID(bus, dev, &d->ic_guid) == 0) {
|
||||
device_set_desc(dev, d->ic_desc);
|
||||
return (BUS_PROBE_DEFAULT);
|
||||
}
|
||||
}
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
int
|
||||
hv_util_attach(device_t dev, vmbus_chan_callback_t cb)
|
||||
{
|
||||
|
@ -31,6 +31,7 @@
|
||||
#ifndef _HVUTIL_H_
|
||||
#define _HVUTIL_H_
|
||||
|
||||
#include <dev/hyperv/include/hyperv.h>
|
||||
#include <dev/hyperv/include/vmbus.h>
|
||||
|
||||
/**
|
||||
@ -42,9 +43,17 @@ typedef struct hv_util_sc {
|
||||
int ic_buflen;
|
||||
} hv_util_sc;
|
||||
|
||||
struct vmbus_ic_desc {
|
||||
const struct hyperv_guid ic_guid;
|
||||
const char *ic_desc;
|
||||
};
|
||||
|
||||
#define VMBUS_IC_DESC_END { .ic_desc = NULL }
|
||||
|
||||
void hv_negotiate_version(struct hv_vmbus_icmsg_hdr *icmsghdrp, uint8_t *buf);
|
||||
|
||||
int hv_util_attach(device_t dev, vmbus_chan_callback_t cb);
|
||||
int hv_util_detach(device_t dev);
|
||||
int hv_util_attach(device_t dev, vmbus_chan_callback_t cb);
|
||||
int hv_util_detach(device_t dev);
|
||||
int vmbus_ic_probe(device_t dev, const struct vmbus_ic_desc descs[]);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user