/* $NetBSD: xen_machdep.c,v 1.4 2008/05/10 16:27:57 ad Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. * * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Manuel Bouyer. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * 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 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. * */ /* * * Copyright (c) 2004 Christian Limpach. * All rights reserved. * * 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. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * This product includes software developed by Christian Limpach. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * 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 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. */ #include <sys/cdefs.h> __KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.4 2008/05/10 16:27:57 ad Exp $"); #include "opt_xen.h" #include <sys/param.h> #include <sys/systm.h> #include <sys/boot_flag.h> #include <sys/mount.h> #include <sys/reboot.h> #include <sys/timetc.h> #include <xen/hypervisor.h> u_int tsc_get_timecount(struct timecounter *); uint64_t tsc_freq; /* XXX */ void xen_parse_cmdline(int what, union xen_cmdline_parseinfo *xcp) { char _cmd_line[256], *cmd_line, *opt, *s; int b, i, ipidx = 0; uint32_t xi_ip[5]; size_t len; len = strlcpy(_cmd_line, xen_start_info.cmd_line, sizeof(_cmd_line)); if (len > sizeof(_cmd_line)) { printf("command line exceeded limit of 255 chars. Truncated.\n"); } cmd_line = _cmd_line; switch (what) { case XEN_PARSE_BOOTDEV: xcp->xcp_bootdev[0] = 0; break; case XEN_PARSE_CONSOLE: xcp->xcp_console[0] = 0; break; } while (cmd_line && *cmd_line) { opt = cmd_line; cmd_line = strchr(opt, ' '); if (cmd_line) *cmd_line = 0; switch (what) { case XEN_PARSE_BOOTDEV: if (strncasecmp(opt, "bootdev=", 8) == 0) { strncpy(xcp->xcp_bootdev, opt + 8, sizeof(xcp->xcp_bootdev)); break; } if (strncasecmp(opt, "root=", 5) == 0) { strncpy(xcp->xcp_bootdev, opt + 5, sizeof(xcp->xcp_bootdev)); break; } break; case XEN_PARSE_NETINFO: if (xcp->xcp_netinfo.xi_root && strncasecmp(opt, "nfsroot=", 8) == 0) strncpy(xcp->xcp_netinfo.xi_root, opt + 8, MNAMELEN); if (strncasecmp(opt, "ip=", 3) == 0) { memset(xi_ip, 0, sizeof(xi_ip)); opt += 3; ipidx = 0; while (opt && *opt) { s = opt; opt = strchr(opt, ':'); if (opt) *opt = 0; switch (ipidx) { case 0: /* ip */ case 1: /* nfs server */ case 2: /* gw */ case 3: /* mask */ case 4: /* host */ if (*s == 0) break; for (i = 0; i < 4; i++) { b = strtoul(s, &s, 10); xi_ip[ipidx] = b + 256 * xi_ip[ipidx]; if (*s != '.') break; s++; } if (i < 3) xi_ip[ipidx] = 0; break; case 5: /* interface */ if (!strncmp(s, "xennet", 6)) s += 6; else if (!strncmp(s, "eth", 3)) s += 3; else break; if (xcp->xcp_netinfo.xi_ifno == strtoul(s, NULL, 10)) memcpy(xcp-> xcp_netinfo.xi_ip, xi_ip, sizeof(xi_ip)); break; } ipidx++; if (opt) *opt++ = ':'; } } break; case XEN_PARSE_CONSOLE: if (strncasecmp(opt, "console=", 8) == 0) strncpy(xcp->xcp_console, opt + 8, sizeof(xcp->xcp_console)); break; case XEN_PARSE_BOOTFLAGS: if (*opt == '-') { opt++; while(*opt != '\0') { BOOT_FLAG(*opt, boothowto); opt++; } } break; } if (cmd_line) *cmd_line++ = ' '; } } u_int tsc_get_timecount(struct timecounter *tc) { panic("xen: tsc_get_timecount"); }