1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2020 Broadcom
9 #include "tf_session.h"
15 tf_open_session(struct tf *tfp,
16 struct tf_open_session_parms *parms)
19 struct tf_session *session;
20 struct tfp_calloc_parms alloc_parms;
21 unsigned int domain, bus, slot, device;
22 uint8_t fw_session_id;
24 if (tfp == NULL || parms == NULL)
27 /* Filter out any non-supported device types on the Core
28 * side. It is assumed that the Firmware will be supported if
29 * firmware open session succeeds.
31 if (parms->device_type != TF_DEVICE_TYPE_WH)
34 /* Build the beginning of session_id */
35 rc = sscanf(parms->ctrl_chan_name,
43 "Failed to scan device ctrl_chan_name\n");
47 /* open FW session and get a new session_id */
48 rc = tf_msg_session_open(tfp,
49 parms->ctrl_chan_name,
55 "Session is already open, rc:%d\n",
59 "Open message send failed, rc:%d\n",
62 parms->session_id.id = TF_FW_SESSION_ID_INVALID;
66 /* Allocate session */
67 alloc_parms.nitems = 1;
68 alloc_parms.size = sizeof(struct tf_session_info);
69 alloc_parms.alignment = 0;
70 rc = tfp_calloc(&alloc_parms);
74 "Failed to allocate session info, rc:%d\n",
79 tfp->session = (struct tf_session_info *)alloc_parms.mem_va;
81 /* Allocate core data for the session */
82 alloc_parms.nitems = 1;
83 alloc_parms.size = sizeof(struct tf_session);
84 alloc_parms.alignment = 0;
85 rc = tfp_calloc(&alloc_parms);
89 "Failed to allocate session data, rc:%d\n",
94 tfp->session->core_data = alloc_parms.mem_va;
96 session = (struct tf_session *)tfp->session->core_data;
97 tfp_memcpy(session->ctrl_chan_name,
98 parms->ctrl_chan_name,
101 /* Initialize Session */
102 session->device_type = parms->device_type;
104 /* Construct the Session ID */
105 session->session_id.internal.domain = domain;
106 session->session_id.internal.bus = bus;
107 session->session_id.internal.device = device;
108 session->session_id.internal.fw_session_id = fw_session_id;
110 rc = tf_msg_session_qcfg(tfp);
114 "Query config message send failed, rc:%d\n",
119 session->ref_count++;
121 /* Return session ID */
122 parms->session_id = session->session_id;
125 "Session created, session_id:%d\n",
126 parms->session_id.id);
129 "domain:%d, bus:%d, device:%d, fw_session_id:%d\n",
130 parms->session_id.internal.domain,
131 parms->session_id.internal.bus,
132 parms->session_id.internal.device,
133 parms->session_id.internal.fw_session_id);
138 tfp_free(tfp->session->core_data);
139 tfp_free(tfp->session);