From patchwork Tue Dec 5 01:01:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 844524 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 3yrNp44Jjdz9s7g for ; Tue, 5 Dec 2017 12:05:16 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yrNp42xC3zF07F for ; Tue, 5 Dec 2017 12:05:16 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=au1.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=cyril.bur@au1.ibm.com; receiver=) 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 3yrNk33QwmzDrqK for ; Tue, 5 Dec 2017 12:01:47 +1100 (AEDT) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vB50x6DG039870 for ; Mon, 4 Dec 2017 20:01:44 -0500 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0b-001b2d01.pphosted.com with ESMTP id 2encj7jg2t-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 04 Dec 2017 20:01:44 -0500 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 5 Dec 2017 01:01:42 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 5 Dec 2017 01:01:39 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vB511cPw26148978; Tue, 5 Dec 2017 01:01:38 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C3C7611C04A; Tue, 5 Dec 2017 00:56:06 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0800311C04C; Tue, 5 Dec 2017 00:56:06 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 5 Dec 2017 00:56:05 +0000 (GMT) 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 A9718A03A3; Tue, 5 Dec 2017 12:01:34 +1100 (AEDT) From: Cyril Bur To: skiboot@lists.ozlabs.org Date: Tue, 5 Dec 2017 12:01:12 +1100 X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171205010113.23263-1-cyril.bur@au1.ibm.com> References: <20171205010113.23263-1-cyril.bur@au1.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17120501-0016-0000-0000-000005095A65 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17120501-0017-0000-0000-0000284552D9 Message-Id: <20171205010113.23263-11-cyril.bur@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-04_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=3 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1712050012 Subject: [Skiboot] [PATCH v3 10/11] libflash/mbox-flash: Add the ability to lock flash X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair@popple.id.au MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Cyril Bur --- libflash/mbox-flash.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++---- libflash/mbox-flash.h | 1 + 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c index e832bc9f..8af2251a 100644 --- a/libflash/mbox-flash.c +++ b/libflash/mbox-flash.c @@ -152,7 +152,7 @@ static mbox_handler *handlers_v1[] = { static void mbox_flash_callback(struct bmc_mbox_msg *msg, void *priv); static void mbox_flash_attn(uint8_t attn, void *priv); -static int protocol_init(struct mbox_flash_data *mbox_flash); +static int protocol_init(struct mbox_flash_data *mbox_flash, uint8_t shift); static int lpc_window_read(struct mbox_flash_data *mbox_flash, uint32_t pos, void *buf, uint32_t len) @@ -539,7 +539,7 @@ static int handle_reboot(struct mbox_flash_data *mbox_flash) return rc; } - rc = protocol_init(mbox_flash); + rc = protocol_init(mbox_flash, 0); if (rc) mbox_flash->reboot = true; @@ -975,11 +975,14 @@ out: mbox_flash->busy = false; } -static int protocol_init(struct mbox_flash_data *mbox_flash) +static int protocol_init(struct mbox_flash_data *mbox_flash, uint8_t shift) { struct bmc_mbox_msg msg = MSG_CREATE(MBOX_C_GET_MBOX_INFO); int rc; + mbox_flash->read.open = false; + mbox_flash->write.open = false; + /* Assume V2+ */ mbox_flash->bl.read = &mbox_flash_read; mbox_flash->bl.write = &mbox_flash_write; @@ -1013,7 +1016,7 @@ static int protocol_init(struct mbox_flash_data *mbox_flash) mbox_flash->version = 3; msg_put_u8(&msg, 0, mbox_flash->version); - msg_put_u8(&msg, 1, 0); /* Don't request a shift, let the BMC give us one */ + msg_put_u8(&msg, 1, shift); rc = msg_send(mbox_flash, &msg, mbox_flash->timeout); if (rc) { prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); @@ -1050,6 +1053,63 @@ static int protocol_init(struct mbox_flash_data *mbox_flash) return rc; } +int mbox_flash_lock(struct blocklevel_device *bl, uint64_t pos, uint64_t len) +{ + struct mbox_flash_data *mbox_flash; + struct bmc_mbox_msg msg = MSG_CREATE(MBOX_C_MARK_LOCKED); + int rc; + + /* mbox-flash only talks 32bit for now */ + if (pos > UINT_MAX || len > UINT_MAX) + return FLASH_ERR_PARM_ERROR; + + /* + * If the region isn't at least 4k aligned and in size then bail + * out, the protocol won't allow for smaller block sizes. + */ + if (pos & ((1 << 12) - 1) || len & ((1 << 12) - 1)) + return FLASH_ERR_PARM_ERROR; + + mbox_flash = container_of(bl, struct mbox_flash_data, bl); + if ((pos & mbox_flash_mask(mbox_flash)) || (len & mbox_flash_mask(mbox_flash))) { + uint8_t shift = 0; + /* + * The current block size won't work for locking the requested + * region must reinit. + */ + while (!((1 << shift) & pos) && !((1 << shift) & len)) + shift++; + + prlog(PR_INFO, "Locking flash requires re-init from shift of %d to shift of %d\n", + mbox_flash->shift, shift); + + rc = protocol_init(mbox_flash, shift); + if (rc) + return rc; + + /* + * The daemon didn't agree with the requested shift - the + * flash won't be able to be locked + */ + if (mbox_flash->shift > shift) + return FLASH_ERR_PARM_ERROR; + } + + msg_put_u16(&msg, 0, bytes_to_blocks(mbox_flash, pos)); + msg_put_u16(&msg, 2, bytes_to_blocks(mbox_flash, len)); + rc = msg_send(mbox_flash, &msg, mbox_flash->timeout); + if (rc) { + prlog(PR_ERR, "Failed to enqueue/send BMC MBOX message\n"); + return rc; + } + + rc = wait_for_bmc(mbox_flash, mbox_flash->timeout); + if (rc) + prlog(PR_ERR, "Error waiting for BMC\n"); + + return rc; +} + int mbox_flash_init(struct blocklevel_device **bl) { struct mbox_flash_data *mbox_flash; @@ -1077,7 +1137,7 @@ int mbox_flash_init(struct blocklevel_device **bl) if (bmc_mbox_get_attn_reg() & MBOX_ATTN_BMC_REBOOT) rc = handle_reboot(mbox_flash); else - rc = protocol_init(mbox_flash); + rc = protocol_init(mbox_flash, 0); if (rc) { free(mbox_flash); return rc; diff --git a/libflash/mbox-flash.h b/libflash/mbox-flash.h index cd587d4c..34b4f651 100644 --- a/libflash/mbox-flash.h +++ b/libflash/mbox-flash.h @@ -17,6 +17,7 @@ #ifndef __LIBFLASH_MBOX_FLASH_H #define __LIBFLASH_MBOX_FLASH_H +int mbox_flash_lock(struct blocklevel_device *bl, uint64_t pos, uint64_t len); int mbox_flash_init(struct blocklevel_device **bl); void mbox_flash_exit(struct blocklevel_device *bl); #endif /* __LIBFLASH_MBOX_FLASH_H */