1 /* Copyright 2013-2014 IBM Corp.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *	http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define pr_fmt(fmt)	"CHIPTOD: " fmt
18 
19 #include <skiboot.h>
20 #include <chiptod.h>
21 #include <fsp.h>
22 
23 /* Response status for fsp command 0xE6, s/c 0x06 (Enable/Disable Topology) */
24 #define FSP_STATUS_TOPO_IN_USE	0xb8		/* topology is in use */
25 
fsp_chiptod_update_topology(uint32_t cmd_sub_mod,struct fsp_msg * msg)26 static bool fsp_chiptod_update_topology(uint32_t cmd_sub_mod,
27 					struct fsp_msg *msg)
28 {
29 	struct fsp_msg *resp;
30 	enum chiptod_topology topo;
31 	bool action;
32 	uint8_t status = 0;
33 
34 	switch (cmd_sub_mod) {
35 	case FSP_CMD_TOPO_ENABLE_DISABLE:
36 		/*
37 		 * Action Values: 0x00 = Disable, 0x01 = Enable
38 		 * Topology Values: 0x00 = Primary, 0x01 = Secondary
39 		 */
40 		action = !!msg->data.bytes[2];
41 		topo = msg->data.bytes[3];
42 		prlog(PR_DEBUG, "Topology update event:\n");
43 		prlog(PR_DEBUG, "  Action = %s, Topology = %s\n",
44 					action ? "Enable" : "Disable",
45 					topo ? "Secondary" : "Primary");
46 
47 		if (!chiptod_adjust_topology(topo, action))
48 			status = FSP_STATUS_TOPO_IN_USE;
49 		else
50 			status = 0x00;
51 
52 		resp = fsp_mkmsg(FSP_RSP_TOPO_ENABLE_DISABLE | status, 0);
53 		if (!resp) {
54 			prerror("Response allocation failed\n");
55 			return false;
56 		}
57 		if (fsp_queue_msg(resp, fsp_freemsg)) {
58 			fsp_freemsg(resp);
59 			prerror("Failed to queue response msg\n");
60 			return false;
61 		}
62 		return true;
63 	default:
64 		prlog(PR_DEBUG, "Unhandled sub cmd: %06x\n", cmd_sub_mod);
65 		break;
66 	}
67 	return false;
68 }
69 
70 static struct fsp_client fsp_chiptod_client = {
71 		.message = fsp_chiptod_update_topology,
72 };
73 
fsp_chiptod_init(void)74 void fsp_chiptod_init(void)
75 {
76 	/* Register for Class E6 (HW maintanance) */
77 	fsp_register_client(&fsp_chiptod_client, FSP_MCLASS_HW_MAINT);
78 }
79