Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3334118rdb; Wed, 13 Sep 2023 08:59:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEFq42SPj4MTduq+EAz/uZ9Jk6JBC8+8fBpX6KPBgBB3dtm8QG344AENNF0crvBr0o9yIV8 X-Received: by 2002:a05:6a21:a5a2:b0:137:4fd0:e2e6 with SMTP id gd34-20020a056a21a5a200b001374fd0e2e6mr3236711pzc.6.1694620782647; Wed, 13 Sep 2023 08:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694620782; cv=none; d=google.com; s=arc-20160816; b=dzYqgGJCkWgVQGUAsQPq3e/OZUc1g/0j57eoFSLvtV441QyijvSbBognciP4x4LYwR 3rppU/Z8kD/RLOKPSiFrZNSSjERcyrhH5MQxFS4awtpn0CKFQC6ORdNCTyyYnbjxI6aP tjbgCC2reIVl8fV0w7gSLcUl7SkJoo+qhzHWQEMXHTgtk+Yj0BDmHZQHbutA72s8ah3I EsI5wEPyh8rek1K/B/y/ZipJcr4qDDk0jzmXg6GJgoGJyNh8PN00lZWXlGIDa4Rl+JaO bstFp81mKU2MK6mvtlzJVrZJE4UJHQsZ9/6KIKDX9Dm8PU/T9sHE4dpydXaNNrCcBBDU ZMfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:cc:to:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature; bh=BQVq6keL7Lg9DmVDf+wMf3pQDgbYNDjLgYw1XXoi5ds=; fh=x79AH5v2oUou70Nv1pke+6Sgta/v/4hrWPDSDgJXY1k=; b=R25U1frSCJWZTFwaZDCu6l+nfnXKbwgfbTqRN3zsdQEKRU2B0JItUKEbwLEnBGM76e L1lVI5t6tfftDhAiKW5JfHugP/nex5H6cmEgoKOruP6bbOqu7R0yWDzgXqHpWZ5pa2v9 fCO7lB6nf8fRHfJyHSHLKWJHoxLLQ5vwbvGkWTKvJRiO7u5ndW3L7gvWGt9jzFZ30z+g aGVO82Sv2Oh7vdBr/X/wx4Lqn7AixuK6tenoYHwB+KU7SI67XtKCb7fZ/oJPjWLPSBBQ +zC+WFUEVKOaV1cZWnDYIOgp49PSt7X6ZHR2PCaicPlLra9bJGX0jxL2/1TyPj6V4/89 3XTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b=PR81h69x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mev.co.uk Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id i12-20020a633c4c000000b005774a56d19csi8243464pgn.388.2023.09.13.08.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 08:59:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@mev.co.uk header.s=20221208-6x11dpa4 header.b=PR81h69x; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 9AD1F80740FE; Wed, 13 Sep 2023 08:45:36 -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 S229753AbjIMPpX (ORCPT + 99 others); Wed, 13 Sep 2023 11:45:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229649AbjIMPpW (ORCPT ); Wed, 13 Sep 2023 11:45:22 -0400 Received: from smtp95.iad3b.emailsrvr.com (smtp95.iad3b.emailsrvr.com [146.20.161.95]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B330BC1 for ; Wed, 13 Sep 2023 08:45:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=mev.co.uk; s=20221208-6x11dpa4; t=1694619918; bh=4IAUrf6lnq5lby/Fcq5iZ8ny6EV1LhE/bubOL/S9VaI=; h=Date:Subject:To:From:From; b=PR81h69xV9+LqJ3ZE3UCruaClH027rEvaHObci9DmTVQxBOgaAADuhT23qoZwwL4Y zfDAa0lKneAKj7CT21YZkSJySHqMeCT2fCyJ1c6AfhNffU0B5in7Mz0/W0sPZTJvPm S+Ra2cWv2IusHsi2hR3X3o97ypwc7WHP2poIrwQ8= X-Auth-ID: abbotti@mev.co.uk Received: by smtp20.relay.iad3b.emailsrvr.com (Authenticated sender: abbotti-AT-mev.co.uk) with ESMTPSA id 61D72A0122; Wed, 13 Sep 2023 11:45:17 -0400 (EDT) Message-ID: <79be8582-2395-42c7-92ae-29d9e4c4c33b@mev.co.uk> Date: Wed, 13 Sep 2023 16:45:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 09/13] comedi: ni_mio_common: Conditionally use I/O port or MMIO Content-Language: en-GB To: Arnd Bergmann , linux-kernel@vger.kernel.org Cc: Niklas Schnelle References: <20230913112032.90618-1-abbotti@mev.co.uk> <20230913112032.90618-10-abbotti@mev.co.uk> From: Ian Abbott Organization: MEV Ltd. In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Classification-ID: 096e7432-50a0-4b29-8887-a3795ef0a10f-1-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 08:45:36 -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 On 13/09/2023 13:17, Arnd Bergmann wrote: > On Wed, Sep 13, 2023, at 13:20, Ian Abbott wrote: >> 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 "ni_mio_common.c" file contains calls to both port I/O functions and >> memory-mapped I/O functions. The file is `#include`d by "ni_atmio.c", >> "ni_mio_cs.c", and "ni_pcimio.c" for the ni_atmio, ni_mio_cs, and >> ni_pcimio modules, respectively. Only "ni_pcimio.c" defines the >> `PCIDMA` macro before including "ni_mio_common.c" and various bits of >> code in "ni_mio_common.c" is conditionally compiled according to whether >> that macro is defined or not. Currently, the port I/O function calls >> are compiled in regardless of whether the `PCIDMA` macro is defined or >> not. However, the fact is that the ni_atmio and ni_mio_cs modules will >> never call the memory-mapped I/O functions, and the ni_pcimio module >> will never call the port I/O functions. >> >> Calls to the port I/O and memory-mapped I/O functions is confined to the >> `ni_writel()`, `ni_writew()`, `ni_writeb()`, `ni_readl()`, `ni_readw()`, >> and `ni_readb()` functions which do a run-time test to decide whether to >> call the port I/O functions or the memory-mapped I/O functions. >> Conditionally compile two variants of the functions so they only call >> the port I/O functions if the `PCIDMA` macro is undefined (for the >> ni_atmio and ni_mio_cs modules), and only call the memory-mapped I/O >> functions if the `PCIDMA` macro is defined (for the ni_pcimio module). >> >> Add a run-time check in the `ni_E_init()` function to return an error if >> the comedi device has been set up to use port I/O if `PCIDMA` is >> defined, or has been set up to use memory-mapped I/O if `PCIDMA` is not >> defined. >> >> The changes make it possible to build the ni_pcimio module even if the >> port I/O functions have not been declared. (The ni_atmio and ni_mio_cs >> modules do still require the port I/O functions to be declared.) > > I think this all works, but there is probably a simpler way to > achieve the same: > >> +#ifdef PCIDMA >> + >> static void ni_writel(struct comedi_device *dev, unsigned int data, int reg) >> { >> - if (dev->mmio) >> - writel(data, dev->mmio + reg); >> - else >> - outl(data, dev->iobase + reg); >> + writel(data, dev->mmio + reg); >> } >> >> >> +#else /* PCIDMA */ >> + >> +static void ni_writel(struct comedi_device *dev, unsigned int data, int reg) >> +{ >> + outl(data, dev->iobase + reg); >> +} > > We already have an abstraction for this using iowrite32(), > which turns into either writel() or outl() depending on the > argument, so you could just use pci_iomap() or ioport_map() > to turn port numbers into tokens suitable for the common > helper. > > Arnd It would affect three modules, and there are similar changes that could be made to other modules, so I think I'll put that suggestion on hold for now. I'd also like to get rid of the '#include "ni_mio_common.c"' nonsense at some point, but that's a big job! -- -=( Ian Abbott || MEV Ltd. is a company )=- -=( registered in England & Wales. Regd. number: 02862268. )=- -=( Regd. addr.: S11 & 12 Building 67, Europa Business Park, )=- -=( Bird Hall Lane, STOCKPORT, SK3 0XA, UK. || www.mev.co.uk )=-