From patchwork Wed Sep 13 16:40:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Abbott X-Patchwork-Id: 139005 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:a8d:b0:3f2:4152:657d with SMTP id gr13csp491vqb; Wed, 13 Sep 2023 11:23:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXtt7xtStGZR5LFX4WAsHuErqwovHVUdHv/ExnxNgvd0wDkreC4QnB8BBaJsnIei5MR4bA X-Received: by 2002:a05:6a21:627:b0:157:c14e:1d00 with SMTP id ll39-20020a056a21062700b00157c14e1d00mr2851639pzb.58.1694629384741; Wed, 13 Sep 2023 11:23:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694629384; cv=none; d=google.com; s=arc-20160816; b=FYdlZL31uyj4aGzmw5Vskm3Tvx95pUUK3f4PBLvsaJdVIKrw5Kf5VGXzzDg6xIV4KO o6/J3UrpySmIh5znxkKJeOOSGZGB8zvtT9T7LZdS18ZMzAlGGlmbV3s0jjyxgorg5IHq rwQyxlW0maRoMyHvYHUrPdC+xLwBFwlkeMyvbTpCgyjUlBDsLqqf94eYQFOiYIy2+e7S xg1VkbHqCInBBW0sR5/fj0jLn/QPGqx1PCsO8Pxk8IA7pf9gXNDyM3praEIXE0+NFPVR RwBsHhX+f0ramzdM9suAh6CRr6wq/OPrsGs+1fgDaVOM8cJixfocz5rusPbRkHEgbtmG 4kNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sWjco15Q2VJQGSon7n2yV7/mJ7GKfR55HFhMl/CtwOc=; fh=V2IY9JiXP/LhUMpX66+Nr0N3VSfqLapXj8NIppeg0Gk=; b=EGG1sgoPXHzC9iVrK19cOx7Kk7kk6NZpZmpIL3QC0Yg2WDv8jN7UBkansmt/TRNQju OVQyskrY0vux0KnaLKetd9SmMqz7f9xTOO973/OPPbaFj2t92wi0SsmtvNDjHelupoOF lfimxHn5/VPylszoazmXts2C82zsuAlDKwQT8M0w8WGg6qOQj/c1een8Xts8zt4GJelb A9HaToen1/+VNyji7EhBquVKEpqMpL3tT7r79w/mvBED0CYKZrlZFt6277EqyqVTb5mz 9E1H0MtLvXkuLelnTPM5o3bNWuAu2OHOOqkxEG5s+/dUxUf4dtVTdtMJ1Wwuc6w3bLJ6 10aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b=b8eDPYI2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mev.co.uk Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id z14-20020a056a001d8e00b0068fcbfdebb2si5534922pfw.257.2023.09.13.11.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 11:23:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b=b8eDPYI2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mev.co.uk Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 14C61825EDBD; Wed, 13 Sep 2023 09:44:19 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231247AbjIMQnu (ORCPT + 35 others); Wed, 13 Sep 2023 12:43:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231616AbjIMQnT (ORCPT ); Wed, 13 Sep 2023 12:43:19 -0400 Received: from smtp65.iad3a.emailsrvr.com (smtp65.iad3a.emailsrvr.com [173.203.187.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 491654237 for ; Wed, 13 Sep 2023 09:40:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20221208-6x11dpa4; t=1694623243; bh=rI2CRIUlkLsVtlmYyygnJdB9GvpVENPYuTmpPjCqLlw=; h=From:To:Subject:Date:From; b=b8eDPYI2WpEwB2YDYcoR0b9vMrSHuE3jdGLorvo1gMhgbePD5zrUD+KgEM0Pwoyd2 WHsA+n2LoLl+5q161/y3GYBgO7fc4h5P8X3WSoLonZqP+GfaTp0PKtqucP1KOnorkM MuZ5QtrJaQ28x+uTziNDANkR28u/KQuGnP3JBBGY= X-Auth-ID: abbotti@mev.co.uk Received: by smtp25.relay.iad3a.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id 9DCE42521C; Wed, 13 Sep 2023 12:40:42 -0400 (EDT) From: Ian Abbott To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Ian Abbott , H Hartley Sweeten , Arnd Bergmann , Niklas Schnelle Subject: [PATCH v2 12/13] comedi: amplc_dio200_common: Conditionally remove I/O port support Date: Wed, 13 Sep 2023 17:40:12 +0100 Message-Id: <20230913164013.107520-13-abbotti@mev.co.uk> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230913164013.107520-1-abbotti@mev.co.uk> References: <20230913164013.107520-1-abbotti@mev.co.uk> MIME-Version: 1.0 X-Classification-ID: bb5231ff-a70f-4c9d-8b55-93f03f91465d-13-1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 13 Sep 2023 09:44:19 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776937908624338410 X-GMAIL-MSGID: 1776947702227433462 In a future patch, the port I/O functions (`inb()`, `outb()`, and friends will only be declared in the `HAS_IOPORT` configuration option is enabled. The amplc_dio200_common module is used by the amplc_dio200 module (for ISA cards) and the amplc_dio200_pci module (for PCI and PCI Express cards). It supports both port I/O and memory-mapped I/O. Port I/O and memory-mapped I/O is confined to the `dio200___read8()`, `dio200___read32()`, `dio200___write8()` and `dio200___write32()` functions. Conditionally compile two versions of those functions. If the `CONFIG_HAS_IOPORT` macro is defined, call either the port I/O or memory mapped I/O functions depending on the `mmio` member of the `struct comedi_device`. If the `CONFIG_HAS_IOPORT` macro is undefined only call the memory-mapped I/O functions. Add a run-time check to `amplc_dio200_common_attach()` to return an error if the device wants to use port I/O when the `CONFIG_HAS_IOPORT` macro is undefined. The changes allow the module to be built even if the port I/O functions have not been declared. Cc: Arnd Bergmann Cc: Niklas Schnelle Signed-off-by: Ian Abbott --- v2: Correct `CONFIG_HAS_PORTIO` to `CONFIG_HAS_IOPORT` in commit description. --- drivers/comedi/drivers/amplc_dio200_common.c | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/comedi/drivers/amplc_dio200_common.c b/drivers/comedi/drivers/amplc_dio200_common.c index e6d63e89e7bf..b1a9b4c4a185 100644 --- a/drivers/comedi/drivers/amplc_dio200_common.c +++ b/drivers/comedi/drivers/amplc_dio200_common.c @@ -86,6 +86,8 @@ struct dio200_subdev_intr { unsigned int active:1; }; +#ifdef CONFIG_HAS_IOPORT + static unsigned char dio200___read8(struct comedi_device *dev, unsigned int offset) { @@ -120,6 +122,34 @@ static void dio200___write32(struct comedi_device *dev, outl(val, dev->iobase + offset); } +#else /* CONFIG_HAS_IOPORT */ + +static unsigned char dio200___read8(struct comedi_device *dev, + unsigned int offset) +{ + return readb(dev->mmio + offset); +} + +static void dio200___write8(struct comedi_device *dev, + unsigned int offset, unsigned char val) +{ + writeb(val, dev->mmio + offset); +} + +static unsigned int dio200___read32(struct comedi_device *dev, + unsigned int offset) +{ + return readl(dev->mmio + offset); +} + +static void dio200___write32(struct comedi_device *dev, + unsigned int offset, unsigned int val) +{ + writel(val, dev->mmio + offset); +} + +#endif /* CONFIG_HAS_IOPORT */ + static unsigned char dio200_read8(struct comedi_device *dev, unsigned int offset) { @@ -803,6 +833,12 @@ int amplc_dio200_common_attach(struct comedi_device *dev, unsigned int irq, unsigned int n; int ret; + if (!IS_ENABLED(CONFIG_HAS_IOPORT) && !dev->mmio) { + dev_err(dev->class_dev, + "error! need I/O port support\n"); + return -ENXIO; + } + ret = comedi_alloc_subdevices(dev, board->n_subdevs); if (ret) return ret;