svn commit: r356523 - head/usr.sbin/bhyve
Vincenzo Maffione
vmaffione at FreeBSD.org
Wed Jan 8 22:55:25 UTC 2020
Author: vmaffione
Date: Wed Jan 8 22:55:22 2020
New Revision: 356523
URL: https://svnweb.freebsd.org/changeset/base/356523
Log:
bhyve: add wrapper for debug printf statements
Add printf() wrapper to use CR/CRLF terminators depending on whether
stdio is mapped to a tty open in raw mode.
Try to use the wrapper everywhere.
For now we leave the custom DPRINTF/WPRINTF defined by device
models, but we may remove them in the future.
Reviewed by: grehan, jhb
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D22657
Added:
head/usr.sbin/bhyve/debug.h (contents, props changed)
Modified:
head/usr.sbin/bhyve/audio.c
head/usr.sbin/bhyve/bhyverun.c
head/usr.sbin/bhyve/block_if.c
head/usr.sbin/bhyve/bootrom.c
head/usr.sbin/bhyve/consport.c
head/usr.sbin/bhyve/hda_codec.c
head/usr.sbin/bhyve/mptbl.c
head/usr.sbin/bhyve/net_backends.c
head/usr.sbin/bhyve/net_utils.c
head/usr.sbin/bhyve/pci_ahci.c
head/usr.sbin/bhyve/pci_e82545.c
head/usr.sbin/bhyve/pci_emul.c
head/usr.sbin/bhyve/pci_fbuf.c
head/usr.sbin/bhyve/pci_hda.c
head/usr.sbin/bhyve/pci_hda.h
head/usr.sbin/bhyve/pci_lpc.c
head/usr.sbin/bhyve/pci_nvme.c
head/usr.sbin/bhyve/pci_uart.c
head/usr.sbin/bhyve/pci_virtio_block.c
head/usr.sbin/bhyve/pci_virtio_console.c
head/usr.sbin/bhyve/pci_virtio_net.c
head/usr.sbin/bhyve/pci_virtio_rnd.c
head/usr.sbin/bhyve/pci_virtio_scsi.c
head/usr.sbin/bhyve/pci_xhci.c
head/usr.sbin/bhyve/ps2kbd.c
head/usr.sbin/bhyve/ps2mouse.c
head/usr.sbin/bhyve/rfb.c
head/usr.sbin/bhyve/smbiostbl.c
head/usr.sbin/bhyve/task_switch.c
head/usr.sbin/bhyve/uart_emul.c
head/usr.sbin/bhyve/usb_mouse.c
head/usr.sbin/bhyve/virtio.c
head/usr.sbin/bhyve/xmsr.c
Modified: head/usr.sbin/bhyve/audio.c
==============================================================================
--- head/usr.sbin/bhyve/audio.c Wed Jan 8 22:48:14 2020 (r356522)
+++ head/usr.sbin/bhyve/audio.c Wed Jan 8 22:55:22 2020 (r356523)
@@ -92,7 +92,7 @@ audio_init(const char *dev_name, uint8_t dir)
if (strlen(dev_name) < sizeof(aud->dev_name))
memcpy(aud->dev_name, dev_name, strlen(dev_name) + 1);
else {
- DPRINTF("dev_name too big\n\r");
+ DPRINTF("dev_name too big");
free(aud);
return NULL;
}
@@ -101,7 +101,7 @@ audio_init(const char *dev_name, uint8_t dir)
aud->fd = open(aud->dev_name, aud->dir ? O_WRONLY : O_RDONLY, 0);
if (aud->fd == -1) {
- DPRINTF("Failed to open dev: %s, errno: %d\n\r",
+ DPRINTF("Failed to open dev: %s, errno: %d",
aud->dev_name, errno);
free(aud);
return (NULL);
@@ -137,7 +137,7 @@ audio_set_params(struct audio *aud, struct audio_param
assert(params);
if ((audio_fd = aud->fd) < 0) {
- DPRINTF("Incorrect audio device descriptor for %s\n\r",
+ DPRINTF("Incorrect audio device descriptor for %s",
aud->dev_name);
return (-1);
}
@@ -146,7 +146,7 @@ audio_set_params(struct audio *aud, struct audio_param
if (aud->inited) {
err = ioctl(audio_fd, SNDCTL_DSP_RESET, NULL);
if (err == -1) {
- DPRINTF("Failed to reset fd: %d, errno: %d\n\r",
+ DPRINTF("Failed to reset fd: %d, errno: %d",
aud->fd, errno);
return (-1);
}
@@ -157,14 +157,14 @@ audio_set_params(struct audio *aud, struct audio_param
format = params->format;
err = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format);
if (err == -1) {
- DPRINTF("Fail to set fmt: 0x%x errno: %d\n\r",
+ DPRINTF("Fail to set fmt: 0x%x errno: %d",
params->format, errno);
return -1;
}
/* The device does not support the requested audio format */
if (format != params->format) {
- DPRINTF("Mismatch format: 0x%x params->format: 0x%x\n\r",
+ DPRINTF("Mismatch format: 0x%x params->format: 0x%x",
format, params->format);
return -1;
}
@@ -173,14 +173,14 @@ audio_set_params(struct audio *aud, struct audio_param
channels = params->channels;
err = ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channels);
if (err == -1) {
- DPRINTF("Fail to set channels: %d errno: %d\n\r",
+ DPRINTF("Fail to set channels: %d errno: %d",
params->channels, errno);
return -1;
}
/* The device does not support the requested no. of channels */
if (channels != params->channels) {
- DPRINTF("Mismatch channels: %d params->channels: %d\n\r",
+ DPRINTF("Mismatch channels: %d params->channels: %d",
channels, params->channels);
return -1;
}
@@ -189,14 +189,14 @@ audio_set_params(struct audio *aud, struct audio_param
rate = params->rate;
err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &rate);
if (err == -1) {
- DPRINTF("Fail to set speed: %d errno: %d\n\r",
+ DPRINTF("Fail to set speed: %d errno: %d",
params->rate, errno);
return -1;
}
/* The device does not support the requested rate / speed */
if (rate != params->rate) {
- DPRINTF("Mismatch rate: %d params->rate: %d\n\r",
+ DPRINTF("Mismatch rate: %d params->rate: %d",
rate, params->rate);
return -1;
}
@@ -205,10 +205,10 @@ audio_set_params(struct audio *aud, struct audio_param
err = ioctl(audio_fd, aud->dir ? SNDCTL_DSP_GETOSPACE :
SNDCTL_DSP_GETISPACE, &info);
if (err == -1) {
- DPRINTF("Fail to get audio buf info errno: %d\n\r", errno);
+ DPRINTF("Fail to get audio buf info errno: %d", errno);
return -1;
}
- DPRINTF("fragstotal: 0x%x fragsize: 0x%x\n\r",
+ DPRINTF("fragstotal: 0x%x fragsize: 0x%x",
info.fragstotal, info.fragsize);
#endif
return 0;
@@ -237,7 +237,7 @@ audio_playback(struct audio *aud, const void *buf, siz
while (total < count) {
len = write(audio_fd, buf + total, count - total);
if (len == -1) {
- DPRINTF("Fail to write to fd: %d, errno: %d\n\r",
+ DPRINTF("Fail to write to fd: %d, errno: %d",
audio_fd, errno);
return -1;
}
@@ -273,7 +273,7 @@ audio_record(struct audio *aud, void *buf, size_t coun
while (total < count) {
len = read(audio_fd, buf + total, count - total);
if (len == -1) {
- DPRINTF("Fail to write to fd: %d, errno: %d\n\r",
+ DPRINTF("Fail to write to fd: %d, errno: %d",
audio_fd, errno);
return -1;
}
Modified: head/usr.sbin/bhyve/bhyverun.c
==============================================================================
--- head/usr.sbin/bhyve/bhyverun.c Wed Jan 8 22:48:14 2020 (r356522)
+++ head/usr.sbin/bhyve/bhyverun.c Wed Jan 8 22:55:22 2020 (r356523)
@@ -167,6 +167,8 @@ uint16_t cores, maxcpus, sockets, threads;
char *guest_uuid_str;
+int raw_stdio = 0;
+
static int gdb_port = 0;
static int guest_vmexit_on_hlt, guest_vmexit_on_pause;
static int virtio_msix = 1;
Modified: head/usr.sbin/bhyve/block_if.c
==============================================================================
--- head/usr.sbin/bhyve/block_if.c Wed Jan 8 22:48:14 2020 (r356522)
+++ head/usr.sbin/bhyve/block_if.c Wed Jan 8 22:55:22 2020 (r356523)
@@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
#include <machine/atomic.h>
#include "bhyverun.h"
+#include "debug.h"
#include "mevent.h"
#include "block_if.h"
@@ -442,7 +443,7 @@ blockif_open(const char *optstr, const char *ident)
else if (sscanf(cp, "sectorsize=%d", &ssopt) == 1)
pssopt = ssopt;
else {
- fprintf(stderr, "Invalid device option \"%s\"\n", cp);
+ EPRINTLN("Invalid device option \"%s\"", cp);
goto err;
}
}
@@ -514,7 +515,7 @@ blockif_open(const char *optstr, const char *ident)
if (ssopt != 0) {
if (!powerof2(ssopt) || !powerof2(pssopt) || ssopt < 512 ||
ssopt > pssopt) {
- fprintf(stderr, "Invalid sector size %d/%d\n",
+ EPRINTLN("Invalid sector size %d/%d",
ssopt, pssopt);
goto err;
}
@@ -528,8 +529,8 @@ blockif_open(const char *optstr, const char *ident)
*/
if (S_ISCHR(sbuf.st_mode)) {
if (ssopt < sectsz || (ssopt % sectsz) != 0) {
- fprintf(stderr, "Sector size %d incompatible "
- "with underlying device sector size %d\n",
+ EPRINTLN("Sector size %d incompatible "
+ "with underlying device sector size %d",
ssopt, sectsz);
goto err;
}
Modified: head/usr.sbin/bhyve/bootrom.c
==============================================================================
--- head/usr.sbin/bhyve/bootrom.c Wed Jan 8 22:48:14 2020 (r356522)
+++ head/usr.sbin/bhyve/bootrom.c Wed Jan 8 22:55:22 2020 (r356523)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
#include <vmmapi.h>
#include "bhyverun.h"
#include "bootrom.h"
+#include "debug.h"
#define MAX_BOOTROM_SIZE (16 * 1024 * 1024) /* 16 MB */
@@ -60,13 +61,13 @@ bootrom_init(struct vmctx *ctx, const char *romfile)
rv = -1;
fd = open(romfile, O_RDONLY);
if (fd < 0) {
- fprintf(stderr, "Error opening bootrom \"%s\": %s\n",
+ EPRINTLN("Error opening bootrom \"%s\": %s",
romfile, strerror(errno));
goto done;
}
if (fstat(fd, &sbuf) < 0) {
- fprintf(stderr, "Could not fstat bootrom file \"%s\": %s\n",
+ EPRINTLN("Could not fstat bootrom file \"%s\": %s",
romfile, strerror(errno));
goto done;
}
@@ -76,13 +77,13 @@ bootrom_init(struct vmctx *ctx, const char *romfile)
* MMIO space (e.g. APIC, HPET, MSI).
*/
if (sbuf.st_size > MAX_BOOTROM_SIZE || sbuf.st_size < PAGE_SIZE) {
- fprintf(stderr, "Invalid bootrom size %ld\n", sbuf.st_size);
+ EPRINTLN("Invalid bootrom size %ld", sbuf.st_size);
goto done;
}
if (sbuf.st_size & PAGE_MASK) {
- fprintf(stderr, "Bootrom size %ld is not a multiple of the "
- "page size\n", sbuf.st_size);
+ EPRINTLN("Bootrom size %ld is not a multiple of the "
+ "page size", sbuf.st_size);
goto done;
}
@@ -100,8 +101,8 @@ bootrom_init(struct vmctx *ctx, const char *romfile)
for (i = 0; i < sbuf.st_size / PAGE_SIZE; i++) {
rlen = read(fd, ptr + i * PAGE_SIZE, PAGE_SIZE);
if (rlen != PAGE_SIZE) {
- fprintf(stderr, "Incomplete read of page %d of bootrom "
- "file %s: %ld bytes\n", i, romfile, rlen);
+ EPRINTLN("Incomplete read of page %d of bootrom "
+ "file %s: %ld bytes", i, romfile, rlen);
goto done;
}
}
Modified: head/usr.sbin/bhyve/consport.c
==============================================================================
--- head/usr.sbin/bhyve/consport.c Wed Jan 8 22:48:14 2020 (r356522)
+++ head/usr.sbin/bhyve/consport.c Wed Jan 8 22:55:22 2020 (r356523)
@@ -51,6 +51,7 @@ __FBSDID("$FreeBSD$");
#include "inout.h"
#include "pci_lpc.h"
+#include "debug.h"
#define BVM_CONSOLE_PORT 0x220
#define BVM_CONS_SIG ('b' << 8 | 'v')
@@ -70,6 +71,7 @@ ttyopen(void)
cfmakeraw(&tio_new);
tcsetattr(STDIN_FILENO, TCSANOW, &tio_new);
+ raw_stdio = 1;
atexit(ttyclose);
}
Added: head/usr.sbin/bhyve/debug.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/usr.sbin/bhyve/debug.h Wed Jan 8 22:55:22 2020 (r356523)
@@ -0,0 +1,47 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 2019 Vincenzo Maffione <vmaffione at freebsd.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _DEBUG_H_
+#define _DEBUG_H_
+
+
+extern int raw_stdio;
+
+#define FPRINTLN(filep, fmt, arg...) \
+ do { \
+ if (raw_stdio) \
+ fprintf(filep, fmt "\r\n", ##arg); \
+ else \
+ fprintf(filep, fmt "\n", ##arg); \
+ } while (0)
+
+#define PRINTLN(fmt, arg...) FPRINTLN(stdout, fmt, ##arg)
+#define EPRINTLN(fmt, arg...) FPRINTLN(stderr, fmt, ##arg)
+
+#endif
Modified: head/usr.sbin/bhyve/hda_codec.c
==============================================================================
--- head/usr.sbin/bhyve/hda_codec.c Wed Jan 8 22:48:14 2020 (r356522)
+++ head/usr.sbin/bhyve/hda_codec.c Wed Jan 8 22:55:22 2020 (r356523)
@@ -400,7 +400,7 @@ hda_codec_init(struct hda_codec_inst *hci, const char
if (!(play || rec))
return (-1);
- DPRINTF("cad: 0x%x opts: %s\n\r", hci->cad, opts);
+ DPRINTF("cad: 0x%x opts: %s", hci->cad, opts);
sc = calloc(1, sizeof(*sc));
if (!sc)
@@ -420,7 +420,7 @@ hda_codec_init(struct hda_codec_inst *hci, const char
sc->conf_default = hda_codec_conf_default;
sc->pin_ctrl_default = hda_codec_pin_ctrl_default;
sc->verb_handlers = hda_codec_verb_handlers;
- DPRINTF("HDA Codec nodes: %d\n\r", sc->no_nodes);
+ DPRINTF("HDA Codec nodes: %d", sc->no_nodes);
/*
* Initialize the Audio Output stream
@@ -435,7 +435,7 @@ hda_codec_init(struct hda_codec_inst *hci, const char
st->aud = audio_init(play, 1);
if (!st->aud) {
- DPRINTF("Fail to init the output audio player\n\r");
+ DPRINTF("Fail to init the output audio player");
return (-1);
}
}
@@ -453,7 +453,7 @@ hda_codec_init(struct hda_codec_inst *hci, const char
st->aud = audio_init(rec, 0);
if (!st->aud) {
- DPRINTF("Fail to init the input audio player\n\r");
+ DPRINTF("Fail to init the input audio player");
return (-1);
}
}
@@ -488,11 +488,11 @@ hda_codec_reset(struct hda_codec_inst *hci)
st->right_mute = HDA_CODEC_SET_AMP_GAIN_MUTE_MUTE;
}
- DPRINTF("cad: 0x%x\n\r", hci->cad);
+ DPRINTF("cad: 0x%x", hci->cad);
if (!hops->signal) {
DPRINTF("The controller ops does not implement \
- the signal function\n\r");
+ the signal function");
return (-1);
}
@@ -538,7 +538,7 @@ hda_codec_command(struct hda_codec_inst *hci, uint32_t
if (!hops->response) {
DPRINTF("The controller ops does not implement \
- the response function\n\r");
+ the response function");
return (-1);
}
@@ -566,11 +566,11 @@ hda_codec_command(struct hda_codec_inst *hci, uint32_t
if (sc->verb_handlers[nid])
res = sc->verb_handlers[nid](sc, verb, payload);
else
- DPRINTF("Unknown VERB: 0x%x\n\r", verb);
+ DPRINTF("Unknown VERB: 0x%x", verb);
break;
}
- DPRINTF("cad: 0x%x nid: 0x%x verb: 0x%x payload: 0x%x response: 0x%x\n\r",
+ DPRINTF("cad: 0x%x nid: 0x%x verb: 0x%x payload: 0x%x response: 0x%x",
cad, nid, verb, payload, res);
return (hops->response(hci, res, HDA_CODEC_RESPONSE_EX_SOL));
@@ -595,11 +595,11 @@ hda_codec_notify(struct hda_codec_inst *hci, uint8_t r
i = dir ? HDA_CODEC_STREAM_OUTPUT : HDA_CODEC_STREAM_INPUT;
st = &sc->streams[i];
- DPRINTF("run: %d, stream: 0x%x, st->stream: 0x%x dir: %d\n\r",
+ DPRINTF("run: %d, stream: 0x%x, st->stream: 0x%x dir: %d",
run, stream, st->stream, dir);
if (stream != st->stream) {
- DPRINTF("Stream not found\n\r");
+ DPRINTF("Stream not found");
return (0);
}
@@ -653,7 +653,7 @@ hda_codec_parse_format(uint16_t fmt, struct audio_para
params->format = AFMT_S32_LE;
break;
default:
- DPRINTF("Unknown format bits: 0x%x\n\r",
+ DPRINTF("Unknown format bits: 0x%x",
fmt & HDA_CODEC_FMT_BITS_MASK);
return (-1);
}
@@ -719,7 +719,7 @@ hda_codec_audio_output_do_setup(void *arg)
if (err)
return (-1);
- DPRINTF("rate: %d, channels: %d, format: 0x%x\n\r",
+ DPRINTF("rate: %d, channels: %d, format: 0x%x",
params.rate, params.channels, params.format);
return (audio_set_params(aud, ¶ms));
@@ -778,7 +778,7 @@ hda_codec_audio_input_do_setup(void *arg)
if (err)
return (-1);
- DPRINTF("rate: %d, channels: %d, format: 0x%x\n\r",
+ DPRINTF("rate: %d, channels: %d, format: 0x%x",
params.rate, params.channels, params.format);
return (audio_set_params(aud, ¶ms));
@@ -792,7 +792,7 @@ hda_codec_audio_inout_nid(struct hda_codec_stream *st,
uint8_t mute = 0;
uint8_t gain = 0;
- DPRINTF("%s verb: 0x%x, payload, 0x%x\n\r", st->actx.name, verb, payload);
+ DPRINTF("%s verb: 0x%x, payload, 0x%x", st->actx.name, verb, payload);
switch (verb) {
case HDA_CMD_VERB_GET_CONV_FMT:
@@ -804,10 +804,10 @@ hda_codec_audio_inout_nid(struct hda_codec_stream *st,
case HDA_CMD_VERB_GET_AMP_GAIN_MUTE:
if (payload & HDA_CMD_GET_AMP_GAIN_MUTE_LEFT) {
res = st->left_gain | st->left_mute;
- DPRINTF("GET_AMP_GAIN_MUTE_LEFT: 0x%x\n\r", res);
+ DPRINTF("GET_AMP_GAIN_MUTE_LEFT: 0x%x", res);
} else {
res = st->right_gain | st->right_mute;
- DPRINTF("GET_AMP_GAIN_MUTE_RIGHT: 0x%x\n\r", res);
+ DPRINTF("GET_AMP_GAIN_MUTE_RIGHT: 0x%x", res);
}
break;
case HDA_CMD_VERB_SET_AMP_GAIN_MUTE:
@@ -818,14 +818,14 @@ hda_codec_audio_inout_nid(struct hda_codec_stream *st,
st->left_mute = mute;
st->left_gain = gain;
DPRINTF("SET_AMP_GAIN_MUTE_LEFT: \
- mute: 0x%x gain: 0x%x\n\r", mute, gain);
+ mute: 0x%x gain: 0x%x", mute, gain);
}
if (payload & HDA_CMD_SET_AMP_GAIN_MUTE_RIGHT) {
st->right_mute = mute;
st->right_gain = gain;
DPRINTF("SET_AMP_GAIN_MUTE_RIGHT: \
- mute: 0x%x gain: 0x%x\n\r", mute, gain);
+ mute: 0x%x gain: 0x%x", mute, gain);
}
break;
case HDA_CMD_VERB_GET_CONV_STREAM_CHAN:
@@ -834,13 +834,13 @@ hda_codec_audio_inout_nid(struct hda_codec_stream *st,
case HDA_CMD_VERB_SET_CONV_STREAM_CHAN:
st->channel = payload & 0x0f;
st->stream = (payload >> 4) & 0x0f;
- DPRINTF("st->channel: 0x%x st->stream: 0x%x\n\r",
+ DPRINTF("st->channel: 0x%x st->stream: 0x%x",
st->channel, st->stream);
if (!st->stream)
hda_audio_ctxt_stop(&st->actx);
break;
default:
- DPRINTF("Unknown VERB: 0x%x\n\r", verb);
+ DPRINTF("Unknown VERB: 0x%x", verb);
break;
}
@@ -867,7 +867,7 @@ hda_audio_ctxt_thr(void *arg)
{
struct hda_audio_ctxt *actx = arg;
- DPRINTF("Start Thread: %s\n\r", actx->name);
+ DPRINTF("Start Thread: %s", actx->name);
pthread_mutex_lock(&actx->mtx);
while (1) {
Modified: head/usr.sbin/bhyve/mptbl.c
==============================================================================
--- head/usr.sbin/bhyve/mptbl.c Wed Jan 8 22:48:14 2020 (r356522)
+++ head/usr.sbin/bhyve/mptbl.c Wed Jan 8 22:55:22 2020 (r356523)
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include "acpi.h"
+#include "debug.h"
#include "bhyverun.h"
#include "mptbl.h"
#include "pci_emul.h"
@@ -312,7 +313,7 @@ mptable_build(struct vmctx *ctx, int ncpu)
startaddr = paddr_guest2host(ctx, MPTABLE_BASE, MPTABLE_MAX_LENGTH);
if (startaddr == NULL) {
- fprintf(stderr, "mptable requires mapped mem\n");
+ EPRINTLN("mptable requires mapped mem");
return (ENOMEM);
}
@@ -323,10 +324,10 @@ mptable_build(struct vmctx *ctx, int ncpu)
*/
for (bus = 1; bus <= PCI_BUSMAX; bus++) {
if (pci_bus_configured(bus)) {
- fprintf(stderr, "MPtable is incompatible with "
- "multiple PCI hierarchies.\r\n");
- fprintf(stderr, "MPtable generation can be disabled "
- "by passing the -Y option to bhyve(8).\r\n");
+ EPRINTLN("MPtable is incompatible with "
+ "multiple PCI hierarchies.");
+ EPRINTLN("MPtable generation can be disabled "
+ "by passing the -Y option to bhyve(8).");
return (EINVAL);
}
}
Modified: head/usr.sbin/bhyve/net_backends.c
==============================================================================
--- head/usr.sbin/bhyve/net_backends.c Wed Jan 8 22:48:14 2020 (r356522)
+++ head/usr.sbin/bhyve/net_backends.c Wed Jan 8 22:55:22 2020 (r356523)
@@ -70,6 +70,7 @@ __FBSDID("$FreeBSD$");
#include <assert.h>
+#include "debug.h"
#include "iov.h"
#include "mevent.h"
#include "net_backends.h"
@@ -156,7 +157,7 @@ SET_DECLARE(net_backend_set, struct net_backend);
#define VNET_HDR_LEN sizeof(struct virtio_net_rxhdr)
-#define WPRINTF(params) printf params
+#define WPRINTF(params) PRINTLN params
/*
* The tap backend
@@ -192,7 +193,7 @@ tap_init(struct net_backend *be, const char *devname,
#endif
if (cb == NULL) {
- WPRINTF(("TAP backend requires non-NULL callback\n\r"));
+ WPRINTF(("TAP backend requires non-NULL callback"));
return (-1);
}
@@ -201,7 +202,7 @@ tap_init(struct net_backend *be, const char *devname,
be->fd = open(tbuf, O_RDWR);
if (be->fd == -1) {
- WPRINTF(("open of tap device %s failed\n\r", tbuf));
+ WPRINTF(("open of tap device %s failed", tbuf));
goto error;
}
@@ -210,7 +211,7 @@ tap_init(struct net_backend *be, const char *devname,
* notifications with the event loop
*/
if (ioctl(be->fd, FIONBIO, &opt) < 0) {
- WPRINTF(("tap device O_NONBLOCK failed\n\r"));
+ WPRINTF(("tap device O_NONBLOCK failed"));
goto error;
}
@@ -222,7 +223,7 @@ tap_init(struct net_backend *be, const char *devname,
priv->mevp = mevent_add_disabled(be->fd, EVF_READ, cb, param);
if (priv->mevp == NULL) {
- WPRINTF(("Could not register event\n\r"));
+ WPRINTF(("Could not register event"));
goto error;
}
@@ -363,7 +364,7 @@ netmap_set_vnet_hdr_len(struct net_backend *be, int vn
req.nr_arg1 = vnet_hdr_len;
err = ioctl(be->fd, NIOCREGIF, &req);
if (err) {
- WPRINTF(("Unable to set vnet header length %d\n\r",
+ WPRINTF(("Unable to set vnet header length %d",
vnet_hdr_len));
return (err);
}
@@ -420,7 +421,7 @@ netmap_init(struct net_backend *be, const char *devnam
priv->nmd = nm_open(priv->ifname, NULL, NETMAP_NO_TX_POLL, NULL);
if (priv->nmd == NULL) {
- WPRINTF(("Unable to nm_open(): interface '%s', errno (%s)\n\r",
+ WPRINTF(("Unable to nm_open(): interface '%s', errno (%s)",
devname, strerror(errno)));
free(priv);
return (-1);
@@ -435,7 +436,7 @@ netmap_init(struct net_backend *be, const char *devnam
priv->mevp = mevent_add_disabled(be->fd, EVF_READ, cb, param);
if (priv->mevp == NULL) {
- WPRINTF(("Could not register event\n\r"));
+ WPRINTF(("Could not register event"));
return (-1);
}
@@ -472,7 +473,7 @@ netmap_send(struct net_backend *be, struct iovec *iov,
ring = priv->tx;
head = ring->head;
if (head == ring->tail) {
- WPRINTF(("No space, drop %zu bytes\n\r", count_iov(iov, iovcnt)));
+ WPRINTF(("No space, drop %zu bytes", count_iov(iov, iovcnt)));
goto txsync;
}
nm_buf = NETMAP_BUF(ring, ring->slot[head].buf_idx);
@@ -513,7 +514,7 @@ netmap_send(struct net_backend *be, struct iovec *iov,
* We ran out of netmap slots while
* splitting the iovec fragments.
*/
- WPRINTF(("No space, drop %zu bytes\n\r",
+ WPRINTF(("No space, drop %zu bytes",
count_iov(iov, iovcnt)));
goto txsync;
}
@@ -585,7 +586,7 @@ netmap_recv(struct net_backend *be, struct iovec *iov,
iovcnt--;
if (iovcnt == 0) {
/* No space to receive. */
- WPRINTF(("Short iov, drop %zd bytes\n\r",
+ WPRINTF(("Short iov, drop %zd bytes",
totlen));
return (-ENOSPC);
}
Modified: head/usr.sbin/bhyve/net_utils.c
==============================================================================
--- head/usr.sbin/bhyve/net_utils.c Wed Jan 8 22:48:14 2020 (r356522)
+++ head/usr.sbin/bhyve/net_utils.c Wed Jan 8 22:55:22 2020 (r356523)
@@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
#include "bhyverun.h"
+#include "debug.h"
#include "net_utils.h"
int
@@ -53,7 +54,7 @@ net_parsemac(char *mac_str, uint8_t *mac_addr)
if (ea == NULL || ETHER_IS_MULTICAST(ea->octet) ||
memcmp(ea->octet, zero_addr, ETHER_ADDR_LEN) == 0) {
- fprintf(stderr, "Invalid MAC %s\n", mac_str);
+ EPRINTLN("Invalid MAC %s", mac_str);
return (EINVAL);
} else
memcpy(mac_addr, ea->octet, ETHER_ADDR_LEN);
Modified: head/usr.sbin/bhyve/pci_ahci.c
==============================================================================
--- head/usr.sbin/bhyve/pci_ahci.c Wed Jan 8 22:48:14 2020 (r356522)
+++ head/usr.sbin/bhyve/pci_ahci.c Wed Jan 8 22:55:22 2020 (r356523)
@@ -240,7 +240,7 @@ ahci_generate_intr(struct pci_ahci_softc *sc, uint32_t
if (p->is & p->ie)
sc->is |= (1 << i);
}
- DPRINTF("%s(%08x) %08x\n\r", __func__, mask, sc->is);
+ DPRINTF("%s(%08x) %08x", __func__, mask, sc->is);
/* If there is nothing enabled -- clear legacy interrupt and exit. */
if (sc->is == 0 || (sc->ghc & AHCI_GHC_IE) == 0) {
@@ -282,7 +282,7 @@ ahci_port_intr(struct ahci_port *p)
struct pci_devinst *pi = sc->asc_pi;
int nmsg;
- DPRINTF("%s(%d) %08x/%08x %08x\n\r", __func__,
+ DPRINTF("%s(%d) %08x/%08x %08x", __func__,
p->port, p->is, p->ie, sc->is);
/* If there is nothing enabled -- we are done. */
@@ -341,7 +341,7 @@ ahci_write_fis(struct ahci_port *p, enum sata_fis_type
irq = (fis[1] & (1 << 6)) ? AHCI_P_IX_PS : 0;
break;
default:
- WPRINTF("unsupported fis type %d\n\r", ft);
+ WPRINTF("unsupported fis type %d", ft);
return;
}
if (fis[2] & ATA_S_ERROR) {
@@ -1601,7 +1601,7 @@ handle_packet_cmd(struct ahci_port *p, int slot, uint8
DPRINTF("ACMD:");
for (i = 0; i < 16; i++)
DPRINTF("%02x ", acmd[i]);
- DPRINTF("\n\r");
+ DPRINTF("");
}
#endif
@@ -1788,7 +1788,7 @@ ahci_handle_cmd(struct ahci_port *p, int slot, uint8_t
handle_packet_cmd(p, slot, cfis);
break;
default:
- WPRINTF("Unsupported cmd:%02x\n\r", cfis[2]);
+ WPRINTF("Unsupported cmd:%02x", cfis[2]);
ahci_write_fis_d2h(p, slot, cfis,
(ATA_E_ABORT << 8) | ATA_S_READY | ATA_S_ERROR);
break;
@@ -1818,22 +1818,22 @@ ahci_handle_slot(struct ahci_port *p, int slot)
#ifdef AHCI_DEBUG
prdt = (struct ahci_prdt_entry *)(cfis + 0x80);
- DPRINTF("\n\rcfis:");
+ DPRINTF("cfis:");
for (i = 0; i < cfl; i++) {
if (i % 10 == 0)
- DPRINTF("\n\r");
+ DPRINTF("");
DPRINTF("%02x ", cfis[i]);
}
- DPRINTF("\n\r");
+ DPRINTF("");
for (i = 0; i < hdr->prdtl; i++) {
- DPRINTF("%d@%08"PRIx64"\n\r", prdt->dbc & 0x3fffff, prdt->dba);
+ DPRINTF("%d@%08"PRIx64"", prdt->dbc & 0x3fffff, prdt->dba);
prdt++;
}
#endif
if (cfis[0] != FIS_TYPE_REGH2D) {
- WPRINTF("Not a H2D FIS:%02x\n\r", cfis[0]);
+ WPRINTF("Not a H2D FIS:%02x", cfis[0]);
return;
}
@@ -1889,7 +1889,7 @@ ata_ioreq_cb(struct blockif_req *br, int err)
uint8_t *cfis;
int slot, ncq, dsm;
- DPRINTF("%s %d\n\r", __func__, err);
+ DPRINTF("%s %d", __func__, err);
ncq = dsm = 0;
aior = br->br_param;
@@ -1949,7 +1949,7 @@ ata_ioreq_cb(struct blockif_req *br, int err)
ahci_handle_port(p);
out:
pthread_mutex_unlock(&sc->mtx);
- DPRINTF("%s exit\n\r", __func__);
+ DPRINTF("%s exit", __func__);
}
static void
@@ -1963,7 +1963,7 @@ atapi_ioreq_cb(struct blockif_req *br, int err)
uint32_t tfd;
int slot;
- DPRINTF("%s %d\n\r", __func__, err);
+ DPRINTF("%s %d", __func__, err);
aior = br->br_param;
p = aior->io_pr;
@@ -2011,7 +2011,7 @@ atapi_ioreq_cb(struct blockif_req *br, int err)
ahci_handle_port(p);
out:
pthread_mutex_unlock(&sc->mtx);
- DPRINTF("%s exit\n\r", __func__);
+ DPRINTF("%s exit", __func__);
}
static void
@@ -2048,7 +2048,7 @@ pci_ahci_port_write(struct pci_ahci_softc *sc, uint64_
offset = (offset - AHCI_OFFSET) % AHCI_STEP;
struct ahci_port *p = &sc->port[port];
- DPRINTF("pci_ahci_port %d: write offset 0x%"PRIx64" value 0x%"PRIx64"\n\r",
+ DPRINTF("pci_ahci_port %d: write offset 0x%"PRIx64" value 0x%"PRIx64"",
port, offset, value);
switch (offset) {
@@ -2120,7 +2120,7 @@ pci_ahci_port_write(struct pci_ahci_softc *sc, uint64_
case AHCI_P_TFD:
case AHCI_P_SIG:
case AHCI_P_SSTS:
- WPRINTF("pci_ahci_port: read only registers 0x%"PRIx64"\n\r", offset);
+ WPRINTF("pci_ahci_port: read only registers 0x%"PRIx64"", offset);
break;
case AHCI_P_SCTL:
p->sctl = value;
@@ -2149,7 +2149,7 @@ pci_ahci_port_write(struct pci_ahci_softc *sc, uint64_
static void
pci_ahci_host_write(struct pci_ahci_softc *sc, uint64_t offset, uint64_t value)
{
- DPRINTF("pci_ahci_host: write offset 0x%"PRIx64" value 0x%"PRIx64"\n\r",
+ DPRINTF("pci_ahci_host: write offset 0x%"PRIx64" value 0x%"PRIx64"",
offset, value);
switch (offset) {
@@ -2157,7 +2157,7 @@ pci_ahci_host_write(struct pci_ahci_softc *sc, uint64_
case AHCI_PI:
case AHCI_VS:
case AHCI_CAP2:
- DPRINTF("pci_ahci_host: read only registers 0x%"PRIx64"\n\r", offset);
+ DPRINTF("pci_ahci_host: read only registers 0x%"PRIx64"", offset);
break;
case AHCI_GHC:
if (value & AHCI_GHC_HR) {
@@ -2195,7 +2195,7 @@ pci_ahci_write(struct vmctx *ctx, int vcpu, struct pci
else if (offset < AHCI_OFFSET + sc->ports * AHCI_STEP)
pci_ahci_port_write(sc, offset, value);
else
- WPRINTF("pci_ahci: unknown i/o write offset 0x%"PRIx64"\n\r", offset);
+ WPRINTF("pci_ahci: unknown i/o write offset 0x%"PRIx64"", offset);
pthread_mutex_unlock(&sc->mtx);
}
@@ -2226,7 +2226,7 @@ pci_ahci_host_read(struct pci_ahci_softc *sc, uint64_t
value = 0;
break;
}
- DPRINTF("pci_ahci_host: read offset 0x%"PRIx64" value 0x%x\n\r",
+ DPRINTF("pci_ahci_host: read offset 0x%"PRIx64" value 0x%x",
offset, value);
return (value);
@@ -2267,7 +2267,7 @@ pci_ahci_port_read(struct pci_ahci_softc *sc, uint64_t
break;
}
- DPRINTF("pci_ahci_port %d: read offset 0x%"PRIx64" value 0x%x\n\r",
+ DPRINTF("pci_ahci_port %d: read offset 0x%"PRIx64" value 0x%x",
port, offset, value);
return value;
@@ -2294,7 +2294,7 @@ pci_ahci_read(struct vmctx *ctx, int vcpu, struct pci_
value = pci_ahci_port_read(sc, offset);
else {
value = 0;
- WPRINTF("pci_ahci: unknown i/o read offset 0x%"PRIx64"\n\r",
+ WPRINTF("pci_ahci: unknown i/o read offset 0x%"PRIx64"",
regoff);
}
value >>= 8 * (regoff & 0x3);
Modified: head/usr.sbin/bhyve/pci_e82545.c
==============================================================================
--- head/usr.sbin/bhyve/pci_e82545.c Wed Jan 8 22:48:14 2020 (r356522)
+++ head/usr.sbin/bhyve/pci_e82545.c Wed Jan 8 22:55:22 2020 (r356523)
@@ -63,6 +63,7 @@ __FBSDID("$FreeBSD$");
#include "mii.h"
#include "bhyverun.h"
+#include "debug.h"
#include "pci_emul.h"
#include "mevent.h"
#include "net_utils.h"
@@ -229,8 +230,8 @@ struct ck_info {
* Debug printf
*/
static int e82545_debug = 0;
-#define DPRINTF(msg,params...) if (e82545_debug) fprintf(stderr, "e82545: " msg, params)
-#define WPRINTF(msg,params...) fprintf(stderr, "e82545: " msg, params)
+#define WPRINTF(msg,params...) PRINTLN("e82545: " msg, params)
+#define DPRINTF(msg,params...) if (e82545_debug) WPRINTF(msg, params)
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
@@ -399,21 +400,21 @@ e82545_init_eeprom(struct e82545_softc *sc)
}
checksum = NVM_SUM - checksum;
sc->eeprom_data[NVM_CHECKSUM_REG] = checksum;
- DPRINTF("eeprom checksum: 0x%x\r\n", checksum);
+ DPRINTF("eeprom checksum: 0x%x", checksum);
}
static void
e82545_write_mdi(struct e82545_softc *sc, uint8_t reg_addr,
uint8_t phy_addr, uint32_t data)
{
- DPRINTF("Write mdi reg:0x%x phy:0x%x data: 0x%x\r\n", reg_addr, phy_addr, data);
+ DPRINTF("Write mdi reg:0x%x phy:0x%x data: 0x%x", reg_addr, phy_addr, data);
}
static uint32_t
e82545_read_mdi(struct e82545_softc *sc, uint8_t reg_addr,
uint8_t phy_addr)
{
- //DPRINTF("Read mdi reg:0x%x phy:0x%x\r\n", reg_addr, phy_addr);
+ //DPRINTF("Read mdi reg:0x%x phy:0x%x", reg_addr, phy_addr);
switch (reg_addr) {
case PHY_STATUS:
return (MII_SR_LINK_STATUS | MII_SR_AUTONEG_CAPS |
@@ -430,7 +431,7 @@ e82545_read_mdi(struct e82545_softc *sc, uint8_t reg_a
case PHY_ID2:
return (M88E1011_I_PHY_ID | E82545_REVISION_4) & 0xFFFF;
default:
- DPRINTF("Unknown mdi read reg:0x%x phy:0x%x\r\n", reg_addr, phy_addr);
+ DPRINTF("Unknown mdi read reg:0x%x phy:0x%x", reg_addr, phy_addr);
return 0;
}
/* not reached */
@@ -442,13 +443,13 @@ e82545_eecd_strobe(struct e82545_softc *sc)
/* Microwire state machine */
/*
DPRINTF("eeprom state machine srtobe "
- "0x%x 0x%x 0x%x 0x%x\r\n",
+ "0x%x 0x%x 0x%x 0x%x",
sc->nvm_mode, sc->nvm_bits,
sc->nvm_opaddr, sc->nvm_data);*/
if (sc->nvm_bits == 0) {
DPRINTF("eeprom state machine not expecting data! "
- "0x%x 0x%x 0x%x 0x%x\r\n",
+ "0x%x 0x%x 0x%x 0x%x",
sc->nvm_mode, sc->nvm_bits,
sc->nvm_opaddr, sc->nvm_data);
return;
@@ -479,13 +480,13 @@ e82545_eecd_strobe(struct e82545_softc *sc)
uint16_t op = sc->nvm_opaddr & E82545_NVM_OPCODE_MASK;
uint16_t addr = sc->nvm_opaddr & E82545_NVM_ADDR_MASK;
if (op != E82545_NVM_OPCODE_WRITE) {
- DPRINTF("Illegal eeprom write op 0x%x\r\n",
+ DPRINTF("Illegal eeprom write op 0x%x",
sc->nvm_opaddr);
} else if (addr >= E82545_NVM_EEPROM_SIZE) {
- DPRINTF("Illegal eeprom write addr 0x%x\r\n",
+ DPRINTF("Illegal eeprom write addr 0x%x",
sc->nvm_opaddr);
} else {
- DPRINTF("eeprom write eeprom[0x%x] = 0x%x\r\n",
+ DPRINTF("eeprom write eeprom[0x%x] = 0x%x",
addr, sc->nvm_data);
sc->eeprom_data[addr] = sc->nvm_data;
}
@@ -503,7 +504,7 @@ e82545_eecd_strobe(struct e82545_softc *sc)
uint16_t op = sc->nvm_opaddr & E82545_NVM_OPCODE_MASK;
switch (op) {
case E82545_NVM_OPCODE_EWEN:
- DPRINTF("eeprom write enable: 0x%x\r\n",
+ DPRINTF("eeprom write enable: 0x%x",
sc->nvm_opaddr);
/* back to opcode mode */
sc->nvm_opaddr = 0;
@@ -518,10 +519,10 @@ e82545_eecd_strobe(struct e82545_softc *sc)
sc->nvm_bits = E82545_NVM_DATA_BITS;
if (addr < E82545_NVM_EEPROM_SIZE) {
sc->nvm_data = sc->eeprom_data[addr];
- DPRINTF("eeprom read: eeprom[0x%x] = 0x%x\r\n",
+ DPRINTF("eeprom read: eeprom[0x%x] = 0x%x",
addr, sc->nvm_data);
} else {
- DPRINTF("eeprom illegal read: 0x%x\r\n",
+ DPRINTF("eeprom illegal read: 0x%x",
sc->nvm_opaddr);
sc->nvm_data = 0;
}
@@ -533,7 +534,7 @@ e82545_eecd_strobe(struct e82545_softc *sc)
sc->nvm_data = 0;
break;
default:
- DPRINTF("eeprom unknown op: 0x%x\r\n",
+ DPRINTF("eeprom unknown op: 0x%x",
sc->nvm_opaddr);
/* back to opcode mode */
sc->nvm_opaddr = 0;
@@ -543,7 +544,7 @@ e82545_eecd_strobe(struct e82545_softc *sc)
}
} else {
DPRINTF("eeprom state machine wrong state! "
- "0x%x 0x%x 0x%x 0x%x\r\n",
+ "0x%x 0x%x 0x%x 0x%x",
sc->nvm_mode, sc->nvm_bits,
sc->nvm_opaddr, sc->nvm_data);
}
@@ -558,7 +559,7 @@ e82545_itr_callback(int fd, enum ev_type type, void *p
pthread_mutex_lock(&sc->esc_mtx);
new = sc->esc_ICR & sc->esc_IMS;
if (new && !sc->esc_irq_asserted) {
- DPRINTF("itr callback: lintr assert %x\r\n", new);
+ DPRINTF("itr callback: lintr assert %x", new);
sc->esc_irq_asserted = 1;
pci_lintr_assert(sc->esc_pi);
} else {
@@ -573,7 +574,7 @@ e82545_icr_assert(struct e82545_softc *sc, uint32_t bi
{
uint32_t new;
- DPRINTF("icr assert: 0x%x\r\n", bits);
+ DPRINTF("icr assert: 0x%x", bits);
/*
* An interrupt is only generated if bits are set that
@@ -584,11 +585,11 @@ e82545_icr_assert(struct e82545_softc *sc, uint32_t bi
sc->esc_ICR |= bits;
if (new == 0) {
- DPRINTF("icr assert: masked %x, ims %x\r\n", new, sc->esc_IMS);
+ DPRINTF("icr assert: masked %x, ims %x", new, sc->esc_IMS);
} else if (sc->esc_mevpitr != NULL) {
- DPRINTF("icr assert: throttled %x, ims %x\r\n", new, sc->esc_IMS);
+ DPRINTF("icr assert: throttled %x, ims %x", new, sc->esc_IMS);
} else if (!sc->esc_irq_asserted) {
- DPRINTF("icr assert: lintr assert %x\r\n", new);
+ DPRINTF("icr assert: lintr assert %x", new);
sc->esc_irq_asserted = 1;
pci_lintr_assert(sc->esc_pi);
if (sc->esc_ITR != 0) {
@@ -612,11 +613,11 @@ e82545_ims_change(struct e82545_softc *sc, uint32_t bi
sc->esc_IMS |= bits;
if (new == 0) {
- DPRINTF("ims change: masked %x, ims %x\r\n", new, sc->esc_IMS);
+ DPRINTF("ims change: masked %x, ims %x", new, sc->esc_IMS);
} else if (sc->esc_mevpitr != NULL) {
- DPRINTF("ims change: throttled %x, ims %x\r\n", new, sc->esc_IMS);
+ DPRINTF("ims change: throttled %x, ims %x", new, sc->esc_IMS);
} else if (!sc->esc_irq_asserted) {
- DPRINTF("ims change: lintr assert %x\r\n", new);
+ DPRINTF("ims change: lintr assert %x", new);
sc->esc_irq_asserted = 1;
pci_lintr_assert(sc->esc_pi);
if (sc->esc_ITR != 0) {
@@ -631,7 +632,7 @@ static void
e82545_icr_deassert(struct e82545_softc *sc, uint32_t bits)
{
- DPRINTF("icr deassert: 0x%x\r\n", bits);
+ DPRINTF("icr deassert: 0x%x", bits);
sc->esc_ICR &= ~bits;
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-all
mailing list