Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2773734yba; Sun, 28 Apr 2019 08:42:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7FRviP+E5G9pCJPM7mcdDq3Y6vdD6Afl4qpUUspcIslSzCCc9ZZ7SUrxM8q6sMmEDzfD/ X-Received: by 2002:a62:1a84:: with SMTP id a126mr8405777pfa.52.1556466178332; Sun, 28 Apr 2019 08:42:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556466178; cv=none; d=google.com; s=arc-20160816; b=N6BcnTI8DH9wTGRLRq4j2XEwUbis7WaSoZkqXoMp0c9S4Slgw6qG+cClTCEIJJVU1C QAJBIf68vxVIMAGCjJ3t6r1sydhVr4QJR+cJ2L9/yKZzaUwWNq2+PA/KnnjiqWX6mCBK 1Mb6dUKL2o9Zb9DrofnfUZaBmfKvumOULGkJqB+75NGj8PAT2eiC76K4CLxIq2z8/7O5 Q+/ppHpcKptPHgh0tYxX2T7qj1JkMRFhoNi3x3HdY1Gu1Is2dYuLeOzKeREV+SkObL1H vd/E5urqu4KYcS6gOpC/9cdQhPcalSbUdXGRmOf/71v4k63vAs1czYbGOigqutFiXgKq 8mKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Q4gjuCqLbMIR78uMVv5wKJsST7XijbCE5DyP0EdQm2I=; b=zpvWqhWjcthgP9YhHJHcvdjFQBkVvX7dDldADvm+vreLbymRvzaiLTzZa7tCgdFWRq pH6TpAO7jJS4mG/kjsbAZF+Vmy+pLcmtIS0cb+ypeUV24FhUL6NQYtunfKebFTSjCaYW TpYXQoe0qgNbanvgdQuIxsbUiT9ydoVHWYus136qcBE93oQjxA++tBprCQ3Q3AUxYDTq eMmKSx2Eg2zxgoqPUiACuCD3xhfeyGnHERoER6Vk87/eJFkHYxeTLryUwReYXlhDyL0p ZBQllKlnGB8EHP+Ir6Cu7/+7Al6vCXRzaJQc1HHEPWEgH8WpBlSE3+dQBURjR1cmtUTJ 4BTA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g189si29249438pgc.112.2019.04.28.08.42.29; Sun, 28 Apr 2019 08:42:58 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726830AbfD1PjP (ORCPT + 99 others); Sun, 28 Apr 2019 11:39:15 -0400 Received: from mga05.intel.com ([192.55.52.43]:28404 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726769AbfD1PjP (ORCPT ); Sun, 28 Apr 2019 11:39:15 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Apr 2019 08:39:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,406,1549958400"; d="scan'208";a="138181186" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.86]) by orsmga008.jf.intel.com with ESMTP; 28 Apr 2019 08:39:07 -0700 Received: from andy by smile with local (Exim 4.92) (envelope-from ) id 1hKltR-0005hz-Nc; Sun, 28 Apr 2019 18:39:05 +0300 Date: Sun, 28 Apr 2019 18:39:05 +0300 From: Andy Shevchenko To: "Enrico Weigelt, metux IT consult" Cc: linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, andrew@aj.id.au, macro@linux-mips.org, vz@mleia.com, slemieux.tyco@gmail.com, khilman@baylibre.com, liviu.dudau@arm.com, sudeep.holla@arm.com, lorenzo.pieralisi@arm.com, davem@davemloft.net, jacmet@sunsite.dk, linux@prisktech.co.nz, matthias.bgg@gmail.com, linux-mips@vger.kernel.org, linux-serial@vger.kernel.org, linux-ia64@vger.kernel.org, linux-amlogic@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org Subject: Re: [PATCH 40/41] drivers: tty: serial: helper for setting mmio range Message-ID: <20190428153905.GR9224@smile.fi.intel.com> References: <1556369542-13247-1-git-send-email-info@metux.net> <1556369542-13247-41-git-send-email-info@metux.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1556369542-13247-41-git-send-email-info@metux.net> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 27, 2019 at 02:52:21PM +0200, Enrico Weigelt, metux IT consult wrote: > Introduce a little helpers for settings the mmio range from an > struct resource or start/len parameters with less code. > (also setting iotype to UPIO_MEM) > > Also converting drivers to use these new helpers as well as > fetching mapsize field instead of using hardcoded values. > (the runtime overhead of that should be negligible) > > The idea is moving to a consistent scheme, so later common > calls like request+ioremap combination can be done by generic > helpers. > --- a/drivers/tty/serial/8250/8250_exar.c > +++ b/drivers/tty/serial/8250/8250_exar.c > @@ -134,8 +134,10 @@ static int default_setup(struct exar8250 *priv, struct pci_dev *pcidev, > const struct exar8250_board *board = priv->board; > unsigned int bar = 0; > > - port->port.iotype = UPIO_MEM; > - port->port.mapbase = pci_resource_start(pcidev, bar) + offset; > + uart_memres_set_start_len(&port->port, > + pci_resource_start(pcidev, bar) + offset, > + pci_resource_len(pcidev, bar)); > + I don't see how it's better. Moreover, the size argument seems wrong here. > + uart_memres_set_start_len( > + &port, > + FRODO_BASE + FRODO_APCI_OFFSET(1), 0); Please, avoid such splitting, first parameter is quite fit above line. > port.uartclk = HPDCA_BAUD_BASE * 16; > - port.mapbase = (pa + UART_OFFSET); > + > + uart_memres_set_start_len(&port, (pa + UART_OFFSET)); > port.membase = (char *)(port.mapbase + DIO_VIRADDRBASE); > port.regshift = 1; > port.irq = DIO_IPL(pa + DIO_VIRADDRBASE); Here... > uart.port.flags = UPF_SKIP_TEST | UPF_SHARE_IRQ | UPF_BOOT_AUTOCONF; > uart.port.irq = d->ipl; > uart.port.uartclk = HPDCA_BAUD_BASE * 16; > - uart.port.mapbase = (d->resource.start + UART_OFFSET); > + uart_memres_set_start_len(&uart.port, > + (d->resource.start + UART_OFFSET), > + resource_size(&d->resource)); > uart.port.membase = (char *)(uart.port.mapbase + DIO_VIRADDRBASE); > uart.port.regshift = 1; > uart.port.dev = &d->dev; ...and here, and maybe in other places you split the assignments to the members in two part. Better to call your function before or after these blocks of assignments. > - uport->mapsize = ZS_CHAN_IO_SIZE; > - uport->mapbase = dec_kn_slot_base + > - zs_parms.scc[chip] + > - (side ^ ZS_CHAN_B) * ZS_CHAN_IO_SIZE; > + > + uart_memres_set_start_len(dec_kn_slot_base + > + zs_parms.scc[chip] + > + (side ^ ZS_CHAN_B) * > + ZS_CHAN_IO_SIZE, > + ZS_CHAN_IO_SIZE); This looks hard to read. Think of temporary variables and better formatting style. > /* > + * set physical io range from struct resource > + * if resource is NULL, clear the fields > + * also set the iotype to UPIO_MEM Something wrong with punctuation and style. Please, use proper casing and sentences split. > + */ Shouldn't be kernel-doc formatted? > +static inline void uart_memres_set_res(struct uart_port *port, Perhaps better name can be found. Especially taking into account that it handles IO / MMIO here. > + struct resource *res) > +{ > + if (!res) { It should return an error in such case. > + port->mapsize = 0; > + port->mapbase = 0; > + port->iobase = 0; > + return; > + } > + > + if (resource_type(res) == IORESOURCE_IO) { > + port->iotype = UPIO_PORT; > + port->iobase = resource->start; > + return; > + } > + > + uart->mapbase = res->start; > + uart->mapsize = resource_size(res); > + uart->iotype = UPIO_MEM; Only one type? Why type is even set here? > +} > + > +/* > + * set physical io range by start address and length > + * if resource is NULL, clear the fields > + * also set the iotype to UPIO_MEM Should be fixed as told above. > + */ > +static inline void uart_memres_set_start_len(struct uart_driver *uart, > + resource_size_t start, > + resource_size_t len) The comment doesn't tell why this is needed when we have one for struct resource. > +{ > + uart->mapbase = start; > + uart->mapsize = len; > + uart->iotype = UPIO_MEM; Only one type? > +} > + > +/* -- With Best Regards, Andy Shevchenko