scmi.c (d49ed3608010681a5d1958b6499b336d48ec0dcc) scmi.c (c758208373f36c21e0cb15b166e9a6d3d93edc99)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2022 Ruslan Bukin <br@bsdpad.com>
5 * Copyright (c) 2023 Arm Ltd
6 *
7 * This work was supported by Innovate UK project 105694, "Digital Security
8 * by Design (DSbD) Technology Platform Prototype".

--- 132 unchanged lines hidden (view full) ---

141static int scmi_req_track_inflight(struct scmi_softc *,
142 struct scmi_req *);
143static int scmi_req_drop_inflight(struct scmi_softc *,
144 struct scmi_req *);
145static struct scmi_req *scmi_req_lookup_inflight(struct scmi_softc *, uint32_t);
146
147static int scmi_wait_for_response(struct scmi_softc *,
148 struct scmi_req *, void **);
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2022 Ruslan Bukin <br@bsdpad.com>
5 * Copyright (c) 2023 Arm Ltd
6 *
7 * This work was supported by Innovate UK project 105694, "Digital Security
8 * by Design (DSbD) Technology Platform Prototype".

--- 132 unchanged lines hidden (view full) ---

141static int scmi_req_track_inflight(struct scmi_softc *,
142 struct scmi_req *);
143static int scmi_req_drop_inflight(struct scmi_softc *,
144 struct scmi_req *);
145static struct scmi_req *scmi_req_lookup_inflight(struct scmi_softc *, uint32_t);
146
147static int scmi_wait_for_response(struct scmi_softc *,
148 struct scmi_req *, void **);
149static void scmi_process_response(struct scmi_softc *, uint32_t);
149static void scmi_process_response(struct scmi_softc *, uint32_t,
150 unsigned int);
150
151int
152scmi_attach(device_t dev)
153{
154 struct scmi_softc *sc;
155 phandle_t node;
156 int error;
157

--- 306 unchanged lines hidden (view full) ---

464 break;
465 }
466 mtx_unlock_spin(&sc->trs->mtx);
467
468 return (req);
469}
470
471static void
151
152int
153scmi_attach(device_t dev)
154{
155 struct scmi_softc *sc;
156 phandle_t node;
157 int error;
158

--- 306 unchanged lines hidden (view full) ---

465 break;
466 }
467 mtx_unlock_spin(&sc->trs->mtx);
468
469 return (req);
470}
471
472static void
472scmi_process_response(struct scmi_softc *sc, uint32_t hdr)
473scmi_process_response(struct scmi_softc *sc, uint32_t hdr, uint32_t rx_len)
473{
474 bool timed_out = false;
475 struct scmi_req *req;
476
477 req = scmi_req_lookup_inflight(sc, hdr);
478 if (req == NULL) {
479 device_printf(sc->dev,
480 "Unexpected reply with header |%X| - token: 0x%X Drop.\n",
481 hdr, SCMI_MSG_TOKEN(hdr));
482 return;
483 }
484
485 mtx_lock_spin(&req->mtx);
486 req->done = true;
474{
475 bool timed_out = false;
476 struct scmi_req *req;
477
478 req = scmi_req_lookup_inflight(sc, hdr);
479 if (req == NULL) {
480 device_printf(sc->dev,
481 "Unexpected reply with header |%X| - token: 0x%X Drop.\n",
482 hdr, SCMI_MSG_TOKEN(hdr));
483 return;
484 }
485
486 mtx_lock_spin(&req->mtx);
487 req->done = true;
488 req->msg.rx_len = rx_len;
487 if (!req->timed_out) {
488 /*
489 * Consider the case in which a polled message is picked
490 * by chance on the IRQ path on another CPU: setting poll_done
491 * will terminate the other poll loop.
492 */
493 if (!req->msg.polling)
494 wakeup(req);

--- 12 unchanged lines hidden (view full) ---

507 /*
508 * In case of a late reply to a timed-out transaction this will
509 * finally free the pending scmi_req
510 */
511 scmi_req_drop_inflight(sc, req);
512}
513
514void
489 if (!req->timed_out) {
490 /*
491 * Consider the case in which a polled message is picked
492 * by chance on the IRQ path on another CPU: setting poll_done
493 * will terminate the other poll loop.
494 */
495 if (!req->msg.polling)
496 wakeup(req);

--- 12 unchanged lines hidden (view full) ---

509 /*
510 * In case of a late reply to a timed-out transaction this will
511 * finally free the pending scmi_req
512 */
513 scmi_req_drop_inflight(sc, req);
514}
515
516void
515scmi_rx_irq_callback(device_t dev, void *chan, uint32_t hdr)
517scmi_rx_irq_callback(device_t dev, void *chan, uint32_t hdr, uint32_t rx_len)
516{
517 struct scmi_softc *sc;
518
519 sc = device_get_softc(dev);
520
521 if (SCMI_IS_MSG_TYPE_NOTIF(hdr) || SCMI_IS_MSG_TYPE_DRESP(hdr)) {
522 device_printf(dev, "DRESP/NOTIF unsupported. Drop.\n");
523 SCMI_CLEAR_CHANNEL(dev, chan);
524 return;
525 }
526
518{
519 struct scmi_softc *sc;
520
521 sc = device_get_softc(dev);
522
523 if (SCMI_IS_MSG_TYPE_NOTIF(hdr) || SCMI_IS_MSG_TYPE_DRESP(hdr)) {
524 device_printf(dev, "DRESP/NOTIF unsupported. Drop.\n");
525 SCMI_CLEAR_CHANNEL(dev, chan);
526 return;
527 }
528
527 scmi_process_response(sc, hdr);
529 scmi_process_response(sc, hdr, rx_len);
528}
529
530static int
531scmi_wait_for_response(struct scmi_softc *sc, struct scmi_req *req, void **out)
532{
533 int ret;
534
535 if (req->msg.polling) {

--- 115 unchanged lines hidden ---
530}
531
532static int
533scmi_wait_for_response(struct scmi_softc *sc, struct scmi_req *req, void **out)
534{
535 int ret;
536
537 if (req->msg.polling) {

--- 115 unchanged lines hidden ---