From patchwork Fri Nov 18 05:01:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 696416 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tKm9n63LRz9syB for ; Fri, 18 Nov 2016 16:03:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="wxyYXIDX"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3tKm9n4thZzDvxm for ; Fri, 18 Nov 2016 16:03:57 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="wxyYXIDX"; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mail-pg0-x244.google.com (mail-pg0-x244.google.com [IPv6:2607:f8b0:400e:c05::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3tKm864hfCzDvw6 for ; Fri, 18 Nov 2016 16:02:30 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="wxyYXIDX"; dkim-atps=neutral Received: by mail-pg0-x244.google.com with SMTP id 3so19520483pgd.0 for ; Thu, 17 Nov 2016 21:02:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+uZ+61UwBbcu28GkUlP97m/brfd0OvJd9pWt2IrpAW4=; b=wxyYXIDXZiNDxDeutgQxKb3sL03TepUXceaIFkqhOT6ENHyceediTwMGqHBQj/tQut 9wxAgaUbZh4MIPIPJAzeqmvSyIPD7dekTGSlqh9SwHE/u2FoduFJXsw6YVU/XSq8T+Wq KbzBR9bYid0I1UaHYzMUU+clRQIBYjBBf/362YB9SMuySMmv/VCobJm2Gcodt2cv8fuB RLJ86kGJ4NKqIC/qzsyRaagncthAS9CcCdEQEpnqWYUb8f39pS/oSqSLnEWPGhXsf49i uv0GDyfDfKq8axAF3mf3U5BChoBXzLDECyvxrHGe/4NFsiEH2tpLtwEUHaC2qoTQYjjY /w0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+uZ+61UwBbcu28GkUlP97m/brfd0OvJd9pWt2IrpAW4=; b=BUNPkRNY+wX6uPWqvia12clCgPqcB50m1prh5WTORLHHBNjnfN6XGb1eK3J9R9z5D+ 8iCcuoREWR1c0bOyGvKbtnUYNz/DWJmgzV2bFaft3V+BM+ZKBBBJsjEKnzfWNPDXPe50 ll3NMrJoqc16jB1yabLiuUPqNJHZLP4Sw/yenA0OSTO9toB5RKWHmKZcAbwcQIMZ1dDR 5mTkD1LjzeWj0ViqUMmZbor8Qsf6p2qum25s+A1ZoMzIYhmaVjSE8cusxSWSjdL0nWwO 6t6CHFQeuyzKFRwOYdmdZ6fBrtTkeX3q9b/P/Yqa16V5AbgG7srk9EZyvfU7UwGgfylr CuDg== X-Gm-Message-State: ABUngveulxMHFWsLv6W6mBdj42+huEXJIkeZr+dCywIaA6TaZ6HdhULsUm2W39uveUEpQA== X-Received: by 10.99.132.194 with SMTP id k185mr14957040pgd.171.1479445348654; Thu, 17 Nov 2016 21:02:28 -0800 (PST) Received: from canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id x90sm12613462pfk.73.2016.11.17.21.02.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 21:02:28 -0800 (PST) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Fri, 18 Nov 2016 16:01:47 +1100 Message-Id: <1479445312-12382-10-git-send-email-oohall@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1479445312-12382-1-git-send-email-oohall@gmail.com> References: <1479445312-12382-1-git-send-email-oohall@gmail.com> Subject: [Skiboot] [PATCH 09/14] console: add opal_con_ops API X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Adds a new structure that contains the implementations of the various OPAL console handlers. This is intended to replace the existing ad-hoc mechanism where the OPAL call handlers are overwritten in the OPAL console driver's init function. Currently this just moves the site where the OPAL call handlers are overwritten to inside of console.c, but it is intended to give us a mechanism for implementing features such as pointer validation for the OPAL console calls without having to manually update each driver. This also helps to clarify differences between the internal (skiboot) console and the external (OPAL) console. Signed-off-by: Oliver O'Halloran --- core/console.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/console.h | 25 +++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/core/console.c b/core/console.c index b053e491e351..85ca462988ca 100644 --- a/core/console.c +++ b/core/console.c @@ -31,8 +31,13 @@ static char *con_buf = (char *)INMEM_CON_START; static size_t con_in; static size_t con_out; static bool con_wrapped; + +/* Internal console driver ops */ static struct con_ops *con_driver; +/* External (OPAL) console driver ops */ +static struct opal_con_ops *opal_con_driver = &dummy_opal_con; + static struct lock con_lock = LOCK_UNLOCKED; /* This is mapped via TCEs so we keep it alone in a page */ @@ -303,6 +308,12 @@ void console_complete_flush(void) } } +/* + * set_console() + * + * This sets the driver used internally by Skiboot. This is different to the + * OPAL console driver. + */ void set_console(struct con_ops *driver) { con_driver = driver; @@ -310,6 +321,45 @@ void set_console(struct con_ops *driver) flush_console(); } +/* + * set_opal_console() + * + * Configure the console driver to handle the console provided by the OPAL API. + * They are different to the above in that they are typically buffered, and used + * by the host OS rather than skiboot. + */ +static bool opal_cons_init = false; + +void set_opal_console(struct opal_con_ops *driver) +{ + assert(!opal_cons_init); + opal_con_driver = driver; +} + +void init_opal_console(void) +{ + assert(!opal_cons_init); + opal_cons_init = true; + + if (dummy_console_enabled() && opal_con_driver != &dummy_opal_con) { + prlog(PR_WARNING, "OPAL: Dummy console forced, %s ignored\n", + opal_con_driver->name); + + opal_con_driver = &dummy_opal_con; + } + + prlog(PR_NOTICE, "OPAL: Using %s\n", opal_con_driver->name); + + if (opal_con_driver->init) + opal_con_driver->init(); + + opal_register(OPAL_CONSOLE_READ, opal_con_driver->read, 3); + opal_register(OPAL_CONSOLE_WRITE, opal_con_driver->write, 3); + opal_register(OPAL_CONSOLE_FLUSH, opal_con_driver->flush, 1); + opal_register(OPAL_CONSOLE_WRITE_BUFFER_SPACE, + opal_con_driver->space, 2); +} + void memcons_add_properties(void) { uint64_t addr = (u64)&memcons; diff --git a/include/console.h b/include/console.h index 6a80bef96c7a..41be064f27cb 100644 --- a/include/console.h +++ b/include/console.h @@ -54,10 +54,35 @@ struct con_ops { int64_t (*flush)(void); }; +struct opal_con_ops { + const char *name; + + /* + * OPAL console driver specific init function. + */ + void (*init)(void); + + int64_t (*write)(int64_t term, int64_t *len, const uint8_t *buf); + int64_t (*read)(int64_t term, int64_t *len, uint8_t *buf); + + /* + * returns the amount of space available in the console write buffer + */ + int64_t (*space)(int64_t term_number, int64_t *length); + + /* + * Forces the write buffer to be flushed by the driver + */ + int64_t (*flush)(int64_t term_number); +}; + extern bool dummy_console_enabled(void); extern void force_dummy_console(void); extern bool flush_console(void); + extern void set_console(struct con_ops *driver); +extern void set_opal_console(struct opal_con_ops *driver); +extern void init_opal_console(void); extern void console_complete_flush(void);