From patchwork Mon Apr 24 09:14:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 754163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wBLNL4Sl5z9s9Z for ; Mon, 24 Apr 2017 19:17:54 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3wBLNL3dbGzDqLX for ; Mon, 24 Apr 2017 19:17:54 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3wBLL546rNzDqC4 for ; Mon, 24 Apr 2017 19:15:57 +1000 (AEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3O9Dkgg063893 for ; Mon, 24 Apr 2017 05:15:49 -0400 Received: from e23smtp07.au.ibm.com (e23smtp07.au.ibm.com [202.81.31.140]) by mx0b-001b2d01.pphosted.com with ESMTP id 2a094bebq1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 24 Apr 2017 05:15:49 -0400 Received: from localhost by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Apr 2017 19:15:44 +1000 Received: from d23relay06.au.ibm.com (202.81.31.225) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 24 Apr 2017 19:15:39 +1000 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3O9FSK97667972 for ; Mon, 24 Apr 2017 19:15:36 +1000 Received: from d23av02.au.ibm.com (localhost [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v3O9EweA007052 for ; Mon, 24 Apr 2017 19:14:59 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av02.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v3O9Ew98006469; Mon, 24 Apr 2017 19:14:58 +1000 Received: from camb691.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 7B8AAA0321; Mon, 24 Apr 2017 19:14:39 +1000 (AEST) From: Cyril Bur To: skiboot@lists.ozlabs.org Date: Mon, 24 Apr 2017 19:14:08 +1000 X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170424091411.2151-1-cyril.bur@au1.ibm.com> References: <20170424091411.2151-1-cyril.bur@au1.ibm.com> X-TM-AS-MML: disable x-cbid: 17042409-0044-0000-0000-00000247067F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17042409-0045-0000-0000-000006CEC4AB Message-Id: <20170424091411.2151-3-cyril.bur@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-24_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1704240161 Subject: [Skiboot] [PATCH 2/5] hw/lpc-mbox: Use message registers for interrupts 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: , Cc: andrewrj@au1.ibm.com, mikey@neuling.org, alistair@popple.id.au MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Currently the BMC raises the interrupt using the BMC control register. It does so on all accesses to the 16 'data' registers meaning that when the BMC only wants to set the ATTN (on which we have interrupts enabled) bit we will also get a control register based interrupt. The solution here is to mask that interrupt permanently and enable interrupts on the protocol defined 'response' data byte. Signed-off-by: Cyril Bur Reviewed-by: Suraj Jitindar Singh --- hw/lpc-mbox.c | 63 ++++++++++++++++++++++++++++++++++++++++++------------ include/lpc-mbox.h | 4 ++-- 2 files changed, 51 insertions(+), 16 deletions(-) diff --git a/hw/lpc-mbox.c b/hw/lpc-mbox.c index 21e6eee0..7e509f54 100644 --- a/hw/lpc-mbox.c +++ b/hw/lpc-mbox.c @@ -35,12 +35,14 @@ #define MBOX_FLAG_REG 0x0f #define MBOX_STATUS_0 0x10 -#define MBOX_STATUS_ATTN (1 << 7) #define MBOX_STATUS_1 0x11 +#define MBOX_STATUS_1_ATTN (1 << 7) +#define MBOX_STATUS_1_RESP (1 << 5) #define MBOX_BMC_CTRL 0x12 #define MBOX_CTRL_INT_STATUS (1 << 7) #define MBOX_CTRL_INT_MASK (1 << 1) -#define MBOX_CTRL_INT_SEND (1 << 0) +#define MBOX_CTRL_INT_PING (1 << 0) +#define MBOX_CTRL_INT_SEND (MBOX_CTRL_INT_PING | MBOX_CTRL_INT_MASK) #define MBOX_HOST_CTRL 0x13 #define MBOX_BMC_INT_EN_0 0x14 #define MBOX_BMC_INT_EN_1 0x15 @@ -85,7 +87,7 @@ static void bmc_mbox_recv_message(struct bmc_mbox_msg *msg) uint8_t *msg_data = (uint8_t *)msg; int i; - for (i = 0; i < BMC_MBOX_DATA_REGS; i++) + for (i = 0; i < BMC_MBOX_READ_REGS; i++) msg_data[i] = bmc_mbox_inb(i); } @@ -98,9 +100,18 @@ static void bmc_mbox_send_message(struct bmc_mbox_msg *msg) if (!lpc_ok()) /* We're going to have to handle this better */ prlog(PR_ERR, "LPC isn't ok\n"); - for (i = 0; i < BMC_MBOX_DATA_REGS; i++) + + for (i = 0; i < BMC_MBOX_WRITE_REGS; i++) bmc_mbox_outb(msg_data[i], i); + /* + * Don't touch the response byte, we're listening on it to know + * when we get a response + * Don't touch our host status reg, it isn't a part of messages + */ + + /* Absolutely don't touch the BMC status reg, we aren't allowed */ + /* Ping */ prlog(PR_DEBUG, "Sending BMC interrupt\n"); bmc_mbox_outb(MBOX_CTRL_INT_SEND, MBOX_HOST_CTRL); @@ -136,10 +147,14 @@ static void mbox_poll(struct timer *t __unused, void *data __unused, { struct bmc_mbox_msg *msg; - /* This is a 'registered' the message you just sent me */ - if (bmc_mbox_inb(MBOX_HOST_CTRL) & MBOX_CTRL_INT_STATUS) { + /* + * This status bit being high means that someone touched the + * response byte (byte 13). + * There is probably a response for the previously sent commant + */ + if (bmc_mbox_inb(MBOX_STATUS_1) & MBOX_STATUS_1_RESP) { /* W1C on that reg */ - bmc_mbox_outb(MBOX_CTRL_INT_STATUS, MBOX_HOST_CTRL); + bmc_mbox_outb(MBOX_STATUS_1_RESP, MBOX_STATUS_1); prlog(PR_INSANE, "Got a regular interrupt\n"); /* @@ -148,7 +163,7 @@ static void mbox_poll(struct timer *t __unused, void *data __unused, msg = mbox.in_flight; if (msg == NULL) { prlog(PR_CRIT, "Couldn't find the message!!\n"); - return; + goto out_response; } bmc_mbox_recv_message(msg); if (mbox.callback) @@ -162,19 +177,29 @@ static void mbox_poll(struct timer *t __unused, void *data __unused, unlock(&mbox.lock); } - /* This is to indicate that the BMC has information to tell us */ - if (bmc_mbox_inb(MBOX_STATUS_1) & MBOX_STATUS_ATTN) { +out_response: + + /* + * The BMC has touched byte 15 to get our attention as it has + * something to tell us. + */ + if (bmc_mbox_inb(MBOX_STATUS_1) & MBOX_STATUS_1_ATTN) { uint8_t action; /* W1C on that reg */ - bmc_mbox_outb(MBOX_STATUS_ATTN, MBOX_STATUS_1); + bmc_mbox_outb(MBOX_STATUS_1_ATTN, MBOX_STATUS_1); action = bmc_mbox_inb(MBOX_FLAG_REG); - prlog(PR_INSANE, "Got a status register interrupt with action 0x%02x\n", + prlog(PR_TRACE, "Got a status register interrupt with action 0x%02x\n", action); if (action & BMC_RESET) { - /* TODO Freak */ + /* + * It's unlikely that something needs to be done at the + * driver level. Let libflash deal with it. + * Print something just in case, it is quite a signficant + * event. + */ prlog(PR_WARNING, "BMC reset detected\n"); action &= ~BMC_RESET; } @@ -202,7 +227,7 @@ static bool mbox_init_hw(void) { /* Disable all status interrupts except attentions */ bmc_mbox_outb(0x00, MBOX_HOST_INT_EN_0); - bmc_mbox_outb(MBOX_STATUS_ATTN, MBOX_HOST_INT_EN_1); + bmc_mbox_outb(MBOX_STATUS_1_ATTN, MBOX_HOST_INT_EN_1); /* Cleanup host interrupt and status */ bmc_mbox_outb(MBOX_CTRL_INT_STATUS, MBOX_HOST_CTRL); @@ -274,6 +299,13 @@ void mbox_init(void) return; } + /* Disable the standard interrupt we don't care */ + bmc_mbox_outb(MBOX_CTRL_INT_MASK, MBOX_HOST_CTRL); + + /* Clear the status reg bits that we intend to use for interrupts */ + /* W1C */ + bmc_mbox_outb(MBOX_STATUS_1_RESP | MBOX_STATUS_1_ATTN, MBOX_STATUS_1); + mbox.queue_len = 0; mbox.in_flight = NULL; mbox.callback = NULL; @@ -286,6 +318,9 @@ void mbox_init(void) mbox_lpc_client.interrupts = LPC_IRQ(irq); lpc_register_client(chip_id, &mbox_lpc_client, IRQ_ATTR_TARGET_OPAL); + /* Enable interrupts */ + bmc_mbox_outb(MBOX_STATUS_1_ATTN | MBOX_STATUS_1_RESP, MBOX_HOST_INT_EN_1); + prlog(PR_DEBUG, "Enabled on chip %d, IO port 0x%x, IRQ %d\n", chip_id, mbox.base, irq); } diff --git a/include/lpc-mbox.h b/include/lpc-mbox.h index c67efee9..14e38cf8 100644 --- a/include/lpc-mbox.h +++ b/include/lpc-mbox.h @@ -20,9 +20,9 @@ #include #include -/* Not 16 because the last two are interrupt based status regs */ -#define BMC_MBOX_DATA_REGS 14 #define BMC_MBOX_ARGS_REGS 11 +#define BMC_MBOX_READ_REGS 16 +#define BMC_MBOX_WRITE_REGS 13 #define MBOX_C_RESET_STATE 0x01 #define MBOX_C_GET_MBOX_INFO 0x02