Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752424AbdF1QA4 (ORCPT ); Wed, 28 Jun 2017 12:00:56 -0400 Received: from mx2.rt-rk.com ([89.216.37.149]:50913 "EHLO mail.rt-rk.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752316AbdF1P7R (ORCPT ); Wed, 28 Jun 2017 11:59:17 -0400 From: Aleksandar Markovic To: linux-mips@linux-mips.org Cc: Miodrag Dinic , Goran Ferenc , Aleksandar Markovic , Douglas Leung , James Hogan , Jonas Gorski , linux-kernel@vger.kernel.org, Marcin Nowakowski , Paul Burton , Petar Jovanovic , Raghu Gandham , Ralf Baechle Subject: [PATCH v2 08/10] MIPS: Introduce check_legacy_ioport() interface Date: Wed, 28 Jun 2017 17:47:01 +0200 Message-Id: <1498664922-28493-9-git-send-email-aleksandar.markovic@rt-rk.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1498664922-28493-1-git-send-email-aleksandar.markovic@rt-rk.com> References: <1498664922-28493-1-git-send-email-aleksandar.markovic@rt-rk.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2764 Lines: 78 From: Miodrag Dinic Some drivers may try to probe some I/O ports which can lead to kernel panic if the device is not present and mapped. This function should be used to check for existence of such devices and return 0 for MIPS boards which implement them, otherwise it should return -ENODEV and the affected device driver should never try to read/write the requested I/O port. This is particularly useful for multiplaform kernels which are board agnostic and this interface can be used to match drivers against available devices on a specific board in runtime. This patch just adds a no-op check_legacy_ioport() function which will be enriched with logic in a later patch. Signed-off-by: Miodrag Dinic Signed-off-by: Goran Ferenc Signed-off-by: Aleksandar Markovic --- arch/mips/include/asm/io.h | 5 +++++ arch/mips/kernel/setup.c | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h index ecabc00..62b9f89 100644 --- a/arch/mips/include/asm/io.h +++ b/arch/mips/include/asm/io.h @@ -78,6 +78,11 @@ static inline void set_io_port_base(unsigned long base) } /* + * Check for existence of legacy devices + */ +extern int check_legacy_ioport(unsigned long base_port); + +/* * Thanks to James van Artsdalen for a better timing-fix than * the two short jumps: using outb's to a nonexistent port seems * to guarantee better timings even on fast machines. diff --git a/arch/mips/kernel/setup.c b/arch/mips/kernel/setup.c index 01d1dbd..c22cde8 100644 --- a/arch/mips/kernel/setup.c +++ b/arch/mips/kernel/setup.c @@ -78,6 +78,31 @@ static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE; const unsigned long mips_io_port_base = -1; EXPORT_SYMBOL(mips_io_port_base); +/* + * Check for existence of legacy devices + * + * Some drivers may try to probe some I/O ports which can lead to + * kernel panic if the device is not present and mapped. This method + * should check for existence of such devices and return 0 for MIPS + * boards which actually have them, otherwise it will return -ENODEV + * and the affected device driver should never try to read/write the + * requested I/O port. + */ +int check_legacy_ioport(unsigned long base_port) +{ + int ret = 0; + + switch (base_port) { + default: + /* We will assume that the I/O device port exists if + * not explicitly added to the blacklist match table + */ + break; + } + return ret; +} +EXPORT_SYMBOL(check_legacy_ioport); + static struct resource code_resource = { .name = "Kernel code", }; static struct resource data_resource = { .name = "Kernel data", }; -- 2.7.4