Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4321356imu; Mon, 14 Jan 2019 20:27:55 -0800 (PST) X-Google-Smtp-Source: ALg8bN67IPUPh7cOByxkjWjNyxkrnFeHJBvPp3BvkDLgOqc8HRnv1GVslnbEUU+0iat+bRy7XkF1 X-Received: by 2002:a63:b649:: with SMTP id v9mr2023223pgt.436.1547526475160; Mon, 14 Jan 2019 20:27:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547526475; cv=none; d=google.com; s=arc-20160816; b=Zsj+MCA8f/Zn3J7i+g12kiJWtXQeos2cGi+NfR3Kt8glvyKxllC1jtl8pR6cFWy7e0 x7QkjbHjngDtE5w8UjdxykWsLcHQiKnyQqshWHFMx7HU/OUmxLYt+D6zTe+yK85dlshq 2aJoqHwa9rkrvSUdoGXB+Lq90DfnCnQUUlYDVRiSVUEMw7SFluJqeiYo78eoEt5Ai1zI m6KRwG4bHZMaFryRvHf+a5j6ksmgOMW5BoSlfSCeNbdwCtYyXBy601UFxJyNBCftGt2S Hg2KR4x7QPcsVFjoiQR7gga7xH0xMF7QqysV/H6ilabGUbMA9V/x7pFRlfqkE7FJmGEK uCHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:from:references:in-reply-to :message-id:cc:to; bh=RLyhN9rNG1S2mbg9lgfHKyvPOYpQevUS/dKU0C5m7YA=; b=QLtdnmZwPcxBFqevUNMfVbqATBUNeygz566Z4++xHfchyaOG/xlrpFhzMTZ4W/kf47 wZyFM28F4Y+iBFGz9Fo1sZzjRjmaaxmIdFBv0Ro0lM5O5/0Ojmavbti+oDYf8Chr1/Ep zsyEN/9G0xEuatBC9T2WNKYtvJMeusR/N8tAWrEwvFPCEqBSOtPdadOZGehhaVg6VrOT gQDECRm7Z0pshfD1TBk43tXwjLdWoockYC7PI/4w3jllj5p0GbFWvCANl1xkj7nvTQpe DrsAnonwYIO7AuJ6jYB40F9CQZjXXwUTqyWCwmSi+NMLmEB1AE2tfpqQg2q2TCTQUBGm Zn9w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 4si918167plc.320.2019.01.14.20.27.40; Mon, 14 Jan 2019 20:27:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728318AbfAOEXE (ORCPT + 99 others); Mon, 14 Jan 2019 23:23:04 -0500 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:37472 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728203AbfAOEW3 (ORCPT ); Mon, 14 Jan 2019 23:22:29 -0500 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id B704329E82; Mon, 14 Jan 2019 23:22:24 -0500 (EST) To: Arnd Bergmann , Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linuxppc-dev@lists.ozlabs.org Message-Id: <5b21de311f1b3b6afae0b7b534ac3de7296ed077.1547525936.git.fthain@telegraphics.com.au> In-Reply-To: References: From: Finn Thain Subject: [PATCH v9 18/22] powerpc: Implement nvram ioctls Date: Tue, 15 Jan 2019 15:18:56 +1100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add the powerpc-specific ioctls to the nvram module. This allows the nvram module to replace the generic_nvram module. Tested-by: Stan Johnson Signed-off-by: Finn Thain --- On PPC32, the IOC_NVRAM_SYNC ioctl call always returns 0, even for those platforms that don't implement ppc_md.nvram_sync. This patch retains that quirk. It may be better to return an error (which is what PPC64 does). Changed since v8: - Changed #else to fully specified #elif conditional. - Changed arch_nvram_ops method calls to ppc_md method calls. --- drivers/char/nvram.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/nvram.h | 2 ++ 2 files changed, 40 insertions(+) diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c index c9e295d73dc5..944f05fddacd 100644 --- a/drivers/char/nvram.c +++ b/drivers/char/nvram.c @@ -48,6 +48,9 @@ #include #include +#ifdef CONFIG_PPC +#include +#endif static DEFINE_MUTEX(nvram_mutex); static DEFINE_SPINLOCK(nvram_state_lock); @@ -283,6 +286,38 @@ static long nvram_misc_ioctl(struct file *file, unsigned int cmd, long ret = -ENOTTY; switch (cmd) { +#ifdef CONFIG_PPC + case OBSOLETE_PMAC_NVRAM_GET_OFFSET: + pr_warn("nvram: Using obsolete PMAC_NVRAM_GET_OFFSET ioctl\n"); + /* fall through */ + case IOC_NVRAM_GET_OFFSET: + ret = -EINVAL; +#ifdef CONFIG_PPC_PMAC + if (machine_is(powermac)) { + int part, offset; + + if (copy_from_user(&part, (void __user *)arg, + sizeof(part)) != 0) + return -EFAULT; + if (part < pmac_nvram_OF || part > pmac_nvram_NR) + return -EINVAL; + offset = pmac_get_partition(part); + if (copy_to_user((void __user *)arg, + &offset, sizeof(offset)) != 0) + return -EFAULT; + ret = 0; + } +#endif + break; + case IOC_NVRAM_SYNC: + if (ppc_md.nvram_sync != NULL) { + mutex_lock(&nvram_mutex); + ppc_md.nvram_sync(); + mutex_unlock(&nvram_mutex); + } + ret = 0; + break; +#elif defined(CONFIG_X86) || defined(CONFIG_M68K) case NVRAM_INIT: /* initialize NVRAM contents and checksum */ if (!capable(CAP_SYS_ADMIN)) @@ -306,6 +341,7 @@ static long nvram_misc_ioctl(struct file *file, unsigned int cmd, mutex_unlock(&nvram_mutex); } break; +#endif /* CONFIG_X86 || CONFIG_M68K */ } return ret; } @@ -321,12 +357,14 @@ static int nvram_misc_open(struct inode *inode, struct file *file) return -EBUSY; } +#if defined(CONFIG_X86) || defined(CONFIG_M68K) /* Prevent multiple writers if the set_checksum ioctl is implemented. */ if ((arch_nvram_ops.set_checksum != NULL) && (file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE)) { spin_unlock(&nvram_state_lock); return -EBUSY; } +#endif if (file->f_flags & O_EXCL) nvram_open_mode |= NVRAM_EXCL; diff --git a/include/linux/nvram.h b/include/linux/nvram.h index 9df85703735c..9e3a957c8f1f 100644 --- a/include/linux/nvram.h +++ b/include/linux/nvram.h @@ -31,8 +31,10 @@ struct nvram_ops { void (*write_byte)(unsigned char, int); ssize_t (*read)(char *, size_t, loff_t *); ssize_t (*write)(char *, size_t, loff_t *); +#if defined(CONFIG_X86) || defined(CONFIG_M68K) long (*initialize)(void); long (*set_checksum)(void); +#endif }; extern const struct nvram_ops arch_nvram_ops; -- 2.19.2