1221905Sgrehan/*-
2221905Sgrehan * Copyright (c) 2011 NetApp, Inc.
3221905Sgrehan * All rights reserved.
4221905Sgrehan *
5221905Sgrehan * Redistribution and use in source and binary forms, with or without
6221905Sgrehan * modification, are permitted provided that the following conditions
7221905Sgrehan * are met:
8221905Sgrehan * 1. Redistributions of source code must retain the above copyright
9221905Sgrehan *    notice, this list of conditions and the following disclaimer.
10221905Sgrehan * 2. Redistributions in binary form must reproduce the above copyright
11221905Sgrehan *    notice, this list of conditions and the following disclaimer in the
12221905Sgrehan *    documentation and/or other materials provided with the distribution.
13221905Sgrehan *
14221905Sgrehan * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
15221905Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16221905Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17221905Sgrehan * ARE DISCLAIMED.  IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
18221905Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19221905Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20221905Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21221905Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22221905Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23221905Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24221905Sgrehan * SUCH DAMAGE.
25221905Sgrehan *
26221905Sgrehan * $FreeBSD$
27221905Sgrehan */
28221905Sgrehan
29221905Sgrehan#include <sys/cdefs.h>
30221905Sgrehan__FBSDID("$FreeBSD$");
31221905Sgrehan
32221905Sgrehan#include <sys/param.h>
33221905Sgrehan#include <sys/kernel.h>
34221905Sgrehan#include <sys/bus.h>
35221905Sgrehan
36221905Sgrehan#include <gdb/gdb.h>
37221905Sgrehan
38221905Sgrehan#include <machine/cpufunc.h>
39221905Sgrehan
40221905Sgrehanstatic gdb_probe_f bvm_dbg_probe;
41221905Sgrehanstatic gdb_init_f bvm_dbg_init;
42221905Sgrehanstatic gdb_term_f bvm_dbg_term;
43221905Sgrehanstatic gdb_getc_f bvm_dbg_getc;
44221905Sgrehanstatic gdb_putc_f bvm_dbg_putc;
45221905Sgrehan
46221905SgrehanGDB_DBGPORT(bvm, bvm_dbg_probe, bvm_dbg_init, bvm_dbg_term,
47221905Sgrehan    bvm_dbg_getc, bvm_dbg_putc);
48221905Sgrehan
49221905Sgrehan#define	BVM_DBG_PORT	0x224
50221905Sgrehanstatic int bvm_dbg_port = BVM_DBG_PORT;
51221905Sgrehan
52242194Sneel#define BVM_DBG_SIG	('B' << 8 | 'V')
53242194Sneel
54221905Sgrehanstatic int
55221905Sgrehanbvm_dbg_probe(void)
56221905Sgrehan{
57221905Sgrehan	int disabled, port;
58221905Sgrehan
59221905Sgrehan	disabled = 0;
60221905Sgrehan	resource_int_value("bvmdbg", 0, "disabled", &disabled);
61221905Sgrehan
62242194Sneel	if (!disabled) {
63242194Sneel		if (resource_int_value("bvmdbg", 0, "port", &port) == 0)
64242194Sneel			bvm_dbg_port = port;
65221905Sgrehan
66242194Sneel		if (inw(bvm_dbg_port) == BVM_DBG_SIG) {
67242194Sneel			/*
68242194Sneel			 * Return a higher priority than 0 to override other
69242194Sneel			 * gdb dbgport providers that may be present (e.g. uart)
70242194Sneel			 */
71242194Sneel			return (1);
72242194Sneel		}
73242194Sneel	}
74242194Sneel
75242194Sneel	return (-1);
76221905Sgrehan}
77221905Sgrehan
78221905Sgrehanstatic void
79221905Sgrehanbvm_dbg_init(void)
80221905Sgrehan{
81221905Sgrehan}
82221905Sgrehan
83221905Sgrehanstatic void
84221905Sgrehanbvm_dbg_term(void)
85221905Sgrehan{
86221905Sgrehan}
87221905Sgrehan
88221905Sgrehanstatic void
89221905Sgrehanbvm_dbg_putc(int c)
90221905Sgrehan{
91221905Sgrehan
92221905Sgrehan	outl(bvm_dbg_port, c);
93221905Sgrehan}
94221905Sgrehan
95221905Sgrehanstatic int
96221905Sgrehanbvm_dbg_getc(void)
97221905Sgrehan{
98221905Sgrehan
99221905Sgrehan	return (inl(bvm_dbg_port));
100221905Sgrehan}
101