summaryrefslogtreecommitdiff
path: root/common/host_event_commands.c
blob: 0d87fcac38bf852e94e18e74b94973c0012990ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* Host event commands for Chrome EC */

#include "console.h"
#include "host_command.h"
#include "lpc.h"
#include "util.h"

uint32_t host_get_events(void)
{
#ifdef CONFIG_LPC
	return lpc_get_host_events();
#else
	uint32_t *mapped_raw_events =
		(uint32_t *)host_get_memmap(EC_MEMMAP_HOST_EVENTS);
	return *mapped_raw_events;
#endif
}

void host_set_events(uint32_t mask)
{
#ifdef CONFIG_LPC
	lpc_set_host_events(mask);
#else
	uint32_t *mapped_raw_events =
		(uint32_t *)host_get_memmap(EC_MEMMAP_HOST_EVENTS);
	*mapped_raw_events |= mask;
#endif
}

void host_clear_events(uint32_t mask)
{
#ifdef CONFIG_LPC
	lpc_clear_host_events(mask);
#else
	uint32_t *mapped_raw_events =
		(uint32_t *)host_get_memmap(EC_MEMMAP_HOST_EVENTS);
	*mapped_raw_events &= ~mask;
#endif
}

/*****************************************************************************/
/* Console commands */

static int command_host_event(int argc, char **argv)
{
	/* Handle sub-commands */
	if (argc == 3) {
		char *e;
		int i = strtoi(argv[2], &e, 0);
		if (*e)
			return EC_ERROR_PARAM2;

		if (!strcasecmp(argv[1], "set"))
			host_set_events(i);
		else if (!strcasecmp(argv[1], "clear"))
			host_clear_events(i);
#ifdef CONFIG_LPC
		else if (!strcasecmp(argv[1], "smi"))
			lpc_set_host_event_mask(LPC_HOST_EVENT_SMI, i);
		else if (!strcasecmp(argv[1], "sci"))
			lpc_set_host_event_mask(LPC_HOST_EVENT_SCI, i);
		else if (!strcasecmp(argv[1], "wake"))
			lpc_set_host_event_mask(LPC_HOST_EVENT_WAKE, i);
#endif
		else
			return EC_ERROR_PARAM1;
	}

	/* Print current SMI/SCI status */
	ccprintf("Events:    0x%08x\n", host_get_events());
#ifdef CONFIG_LPC
	ccprintf("SMI mask:  0x%08x\n",
		 lpc_get_host_event_mask(LPC_HOST_EVENT_SMI));
	ccprintf("SCI mask:  0x%08x\n",
		 lpc_get_host_event_mask(LPC_HOST_EVENT_SCI));
	ccprintf("Wake mask: 0x%08x\n",
		 lpc_get_host_event_mask(LPC_HOST_EVENT_WAKE));
#endif
	return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(hostevent, command_host_event,
			"[set | clear | smi | sci | wake] [mask]",
			"Print / set host event state",
			NULL);

/*****************************************************************************/
/* Host commands */

#ifdef CONFIG_LPC

static int host_event_get_smi_mask(uint8_t *data, int *resp_size)
{
	struct ec_response_host_event_mask *r =
		(struct ec_response_host_event_mask *)data;

	r->mask = lpc_get_host_event_mask(LPC_HOST_EVENT_SMI);
	*resp_size = sizeof(struct ec_response_host_event_mask);
	return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_SMI_MASK,
		     host_event_get_smi_mask);

static int host_event_get_sci_mask(uint8_t *data, int *resp_size)
{
	struct ec_response_host_event_mask *r =
		(struct ec_response_host_event_mask *)data;

	r->mask = lpc_get_host_event_mask(LPC_HOST_EVENT_SCI);
	*resp_size = sizeof(struct ec_response_host_event_mask);
	return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_SCI_MASK,
		     host_event_get_sci_mask);

static int host_event_get_wake_mask(uint8_t *data, int *resp_size)
{
	struct ec_response_host_event_mask *r =
		(struct ec_response_host_event_mask *)data;

	r->mask = lpc_get_host_event_mask(LPC_HOST_EVENT_WAKE);
	*resp_size = sizeof(struct ec_response_host_event_mask);
	return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_GET_WAKE_MASK,
		     host_event_get_wake_mask);

static int host_event_set_smi_mask(uint8_t *data, int *resp_size)
{
	const struct ec_params_host_event_mask *p =
		(const struct ec_params_host_event_mask *)data;

	lpc_set_host_event_mask(LPC_HOST_EVENT_SMI, p->mask);
	return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_SET_SMI_MASK,
		     host_event_set_smi_mask);

static int host_event_set_sci_mask(uint8_t *data, int *resp_size)
{
	const struct ec_params_host_event_mask *p =
		(const struct ec_params_host_event_mask *)data;

	lpc_set_host_event_mask(LPC_HOST_EVENT_SCI, p->mask);
	return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_SET_SCI_MASK,
		     host_event_set_sci_mask);

static int host_event_set_wake_mask(uint8_t *data, int *resp_size)
{
	const struct ec_params_host_event_mask *p =
		(const struct ec_params_host_event_mask *)data;

	lpc_set_host_event_mask(LPC_HOST_EVENT_WAKE, p->mask);
	return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_SET_WAKE_MASK,
		     host_event_set_wake_mask);

#endif  /* CONFIG_LPC */

static int host_event_clear(uint8_t *data, int *resp_size)
{
	const struct ec_params_host_event_mask *p =
		(const struct ec_params_host_event_mask *)data;

	host_clear_events(p->mask);
	return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_HOST_EVENT_CLEAR, host_event_clear);