From patchwork Thu Feb 26 16:56:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorge Ramirez-Ortiz X-Patchwork-Id: 45194 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-we0-f197.google.com (mail-we0-f197.google.com [74.125.82.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3668F2043C for ; Thu, 26 Feb 2015 16:59:21 +0000 (UTC) Received: by wesw55 with SMTP id w55sf9320726wes.0 for ; Thu, 26 Feb 2015 08:59:20 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=fG6L65ZcU0jlxnupldYjJ3lTHDZQotQDfZ3b0sOVqzQ=; b=g+HH41qBaOkKCCB3e0Jbik0h/aw7Zci7Umknc6l5oBq+eBuMoNPdX/P5dz4/V3Nlp1 olwJvZJ6MSxcqNO4yrWEJdn0TnIFgh3pE/I/AAJxxMOPO3kTpdX4hibP/q3rBkK5sApB pJLoSPnkU9qozMeU0cU29e60LefgS/W92Bdv74pAaYu5EVrnGZe43UJQuJ/PLJyI8y23 mAWlVZcDHLrXpxRGvCJtRm2H/qgyXCpx09ixkU3MWQ5iAGQ2uJxJRqGM+BoEjTtK610e bQV9do6lw2mR/vWxE26APVkCqNY17U66eBz6AFztgRdXyk86qzxRk+bqNMnc413R8C1l Qxzg== X-Gm-Message-State: ALoCoQnIu7mb8fE1ckqOopt0LF794hYuc+ZFUK4D9Ri2Gw+G3Fp97YZKG1C6BPmw4PGsqTK8yOa/ X-Received: by 10.152.19.100 with SMTP id d4mr1461791lae.7.1424969960479; Thu, 26 Feb 2015 08:59:20 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.10.5 with SMTP id e5ls58869lab.37.gmail; Thu, 26 Feb 2015 08:59:20 -0800 (PST) X-Received: by 10.152.115.206 with SMTP id jq14mr8448917lab.69.1424969960324; Thu, 26 Feb 2015 08:59:20 -0800 (PST) Received: from mail-la0-f46.google.com (mail-la0-f46.google.com. [209.85.215.46]) by mx.google.com with ESMTPS id p15si1025345lal.92.2015.02.26.08.59.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Feb 2015 08:59:20 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) client-ip=209.85.215.46; Received: by lamq1 with SMTP id q1so12265280lam.5 for ; Thu, 26 Feb 2015 08:59:20 -0800 (PST) X-Received: by 10.152.4.227 with SMTP id n3mr5499153lan.72.1424969960177; Thu, 26 Feb 2015 08:59:20 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp3424590lbj; Thu, 26 Feb 2015 08:59:18 -0800 (PST) X-Received: by 10.68.135.37 with SMTP id pp5mr16337557pbb.105.1424969957983; Thu, 26 Feb 2015 08:59:17 -0800 (PST) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id hn4si226647pbb.173.2015.02.26.08.59.17 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Feb 2015 08:59:17 -0800 (PST) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YR1ky-00023g-0C; Thu, 26 Feb 2015 16:57:48 +0000 Received: from mail-qc0-f175.google.com ([209.85.216.175]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YR1ka-0001o6-UH for linux-arm-kernel@lists.infradead.org; Thu, 26 Feb 2015 16:57:26 +0000 Received: by qcvp6 with SMTP id p6so9438421qcv.9 for ; Thu, 26 Feb 2015 08:57:02 -0800 (PST) X-Received: by 10.140.42.13 with SMTP id b13mr19464558qga.43.1424969822075; Thu, 26 Feb 2015 08:57:02 -0800 (PST) Received: from localhost.localdomain (cpe-67-247-86-207.rochester.res.rr.com. [67.247.86.207]) by mx.google.com with ESMTPSA id z75sm849760qhd.9.2015.02.26.08.57.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Feb 2015 08:57:01 -0800 (PST) From: Jorge Ramirez-Ortiz To: jorge.ramirez-ortiz@linaro.org, robh@kernel.org, arnd@arndb.de, linux-arm-kernel@lists.infradead.org, viresh.kumar@linaro.org Subject: [PATCH v5] drivers/tty: amba: defer probing DMA availability until hw_init Date: Thu, 26 Feb 2015 11:56:51 -0500 Message-Id: <1424969811-11197-2-git-send-email-jorge.ramirez-ortiz@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1424969811-11197-1-git-send-email-jorge.ramirez-ortiz@linaro.org> References: <1424969811-11197-1-git-send-email-jorge.ramirez-ortiz@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150226_085725_168083_02D19442 X-CRM114-Status: GOOD ( 22.12 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.216.175 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.216.175 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: jorge.ramirez-ortiz@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.46 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Fix a race condition that happens when device_initcall(pl011_dma_initicall) is executed before all the devices have been probed - this issue was observed on an hisi_6220 SoC (HiKey board from Linaro). The deferred driver probing framework relies on late_initcall to trigger deferred probes so it is just possible that, even with a valid DMA driver ready to be loaded, we fail to synchronize with it. The proposed implementation delays probing of the DMA until the uart device is opened. As hw_init is invoked on port startup and port resume - but the DMA probe is only required once - we avoid calling multiple times using a new field in uart_amba_port to track this scenario. This commit allows for subsequent attempts to associate an external DMA if the DMA driver was deferred at UART hw_init time. Signed-off-by: Jorge Ramirez-Ortiz --- drivers/tty/serial/amba-pl011.c | 95 +++++++++++++---------------------------- 1 file changed, 30 insertions(+), 65 deletions(-) diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c index 8d94c19..4ce98e9 100644 --- a/drivers/tty/serial/amba-pl011.c +++ b/drivers/tty/serial/amba-pl011.c @@ -164,6 +164,7 @@ struct uart_amba_port { bool using_rx_dma; struct pl011_dmarx_data dmarx; struct pl011_dmatx_data dmatx; + bool dma_probed; #endif }; @@ -261,10 +262,11 @@ static void pl011_sgbuf_free(struct dma_chan *chan, struct pl011_sgbuf *sg, } } -static void pl011_dma_probe_initcall(struct device *dev, struct uart_amba_port *uap) +static void pl011_dma_probe(struct uart_amba_port *uap) { /* DMA is the sole user of the platform data right now */ - struct amba_pl011_data *plat = dev_get_platdata(uap->port.dev); + struct device *const uap_dev = uap->port.dev; + struct amba_pl011_data *plat = dev_get_platdata(uap_dev); struct dma_slave_config tx_conf = { .dst_addr = uap->port.mapbase + UART01x_DR, .dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE, @@ -275,12 +277,19 @@ static void pl011_dma_probe_initcall(struct device *dev, struct uart_amba_port * struct dma_chan *chan; dma_cap_mask_t mask; - chan = dma_request_slave_channel(dev, "tx"); + uap->dma_probed = true; + + chan = dma_request_slave_channel_reason(uap_dev, "tx"); + if (IS_ERR(chan)) { + if (PTR_ERR(chan) == -EPROBE_DEFER) { + dev_info(uap_dev, "DMA driver not ready\n"); + uap->dma_probed = false; + return; + } - if (!chan) { /* We need platform data */ if (!plat || !plat->dma_filter) { - dev_info(uap->port.dev, "no DMA platform data\n"); + dev_info(uap_dev, "no DMA platform data\n"); return; } @@ -291,7 +300,7 @@ static void pl011_dma_probe_initcall(struct device *dev, struct uart_amba_port * chan = dma_request_channel(mask, plat->dma_filter, plat->dma_tx_param); if (!chan) { - dev_err(uap->port.dev, "no TX DMA channel!\n"); + dev_err(uap_dev, "no TX DMA channel!\n"); return; } } @@ -299,17 +308,17 @@ static void pl011_dma_probe_initcall(struct device *dev, struct uart_amba_port * dmaengine_slave_config(chan, &tx_conf); uap->dmatx.chan = chan; - dev_info(uap->port.dev, "DMA channel TX %s\n", + dev_info(uap_dev, "DMA channel TX %s\n", dma_chan_name(uap->dmatx.chan)); /* Optionally make use of an RX channel as well */ - chan = dma_request_slave_channel(dev, "rx"); + chan = dma_request_slave_channel(uap_dev, "rx"); if (!chan && plat->dma_rx_param) { chan = dma_request_channel(mask, plat->dma_filter, plat->dma_rx_param); if (!chan) { - dev_err(uap->port.dev, "no RX DMA channel!\n"); + dev_err(uap_dev, "no RX DMA channel!\n"); return; } } @@ -333,7 +342,7 @@ static void pl011_dma_probe_initcall(struct device *dev, struct uart_amba_port * if (caps.residue_granularity == DMA_RESIDUE_GRANULARITY_DESCRIPTOR) { dma_release_channel(chan); - dev_info(uap->port.dev, + dev_info(uap_dev, "RX DMA disabled - no residue processing\n"); return; } @@ -362,75 +371,29 @@ static void pl011_dma_probe_initcall(struct device *dev, struct uart_amba_port * plat->dma_rx_poll_timeout; else uap->dmarx.poll_timeout = 3000; - } else if (!plat && dev->of_node) { + } else if (!plat && uap_dev->of_node) { uap->dmarx.auto_poll_rate = of_property_read_bool( - dev->of_node, "auto-poll"); + uap_dev->of_node, "auto-poll"); if (uap->dmarx.auto_poll_rate) { u32 x; - if (0 == of_property_read_u32(dev->of_node, + if (0 == of_property_read_u32(uap_dev->of_node, "poll-rate-ms", &x)) uap->dmarx.poll_rate = x; else uap->dmarx.poll_rate = 100; - if (0 == of_property_read_u32(dev->of_node, + if (0 == of_property_read_u32(uap_dev->of_node, "poll-timeout-ms", &x)) uap->dmarx.poll_timeout = x; else uap->dmarx.poll_timeout = 3000; } } - dev_info(uap->port.dev, "DMA channel RX %s\n", + dev_info(uap_dev, "DMA channel RX %s\n", dma_chan_name(uap->dmarx.chan)); } } -#ifndef MODULE -/* - * Stack up the UARTs and let the above initcall be done at device - * initcall time, because the serial driver is called as an arch - * initcall, and at this time the DMA subsystem is not yet registered. - * At this point the driver will switch over to using DMA where desired. - */ -struct dma_uap { - struct list_head node; - struct uart_amba_port *uap; - struct device *dev; -}; - -static LIST_HEAD(pl011_dma_uarts); - -static int __init pl011_dma_initcall(void) -{ - struct list_head *node, *tmp; - - list_for_each_safe(node, tmp, &pl011_dma_uarts) { - struct dma_uap *dmau = list_entry(node, struct dma_uap, node); - pl011_dma_probe_initcall(dmau->dev, dmau->uap); - list_del(node); - kfree(dmau); - } - return 0; -} - -device_initcall(pl011_dma_initcall); - -static void pl011_dma_probe(struct device *dev, struct uart_amba_port *uap) -{ - struct dma_uap *dmau = kzalloc(sizeof(struct dma_uap), GFP_KERNEL); - if (dmau) { - dmau->uap = uap; - dmau->dev = dev; - list_add_tail(&dmau->node, &pl011_dma_uarts); - } -} -#else -static void pl011_dma_probe(struct device *dev, struct uart_amba_port *uap) -{ - pl011_dma_probe_initcall(dev, uap); -} -#endif - static void pl011_dma_remove(struct uart_amba_port *uap) { /* TODO: remove the initcall if it has not yet executed */ @@ -1142,7 +1105,7 @@ static inline bool pl011_dma_rx_running(struct uart_amba_port *uap) #else /* Blank functions if the DMA engine is not available */ -static inline void pl011_dma_probe(struct device *dev, struct uart_amba_port *uap) +static inline void pl011_dma_probe(struct uart_amba_port *uap) { } @@ -1548,6 +1511,9 @@ static int pl011_hwinit(struct uart_port *port) uap->im = readw(uap->port.membase + UART011_IMSC); writew(UART011_RTIM | UART011_RXIM, uap->port.membase + UART011_IMSC); + if (!uap->dma_probed) + pl011_dma_probe(uap); + if (dev_get_platdata(uap->port.dev)) { struct amba_pl011_data *plat; @@ -2218,7 +2184,6 @@ static int pl011_probe(struct amba_device *dev, const struct amba_id *id) uap->port.ops = &amba_pl011_pops; uap->port.flags = UPF_BOOT_AUTOCONF; uap->port.line = i; - pl011_dma_probe(&dev->dev, uap); /* Ensure interrupts from this UART are masked and cleared */ writew(0, uap->port.membase + UART011_IMSC); @@ -2233,7 +2198,8 @@ static int pl011_probe(struct amba_device *dev, const struct amba_id *id) if (!amba_reg.state) { ret = uart_register_driver(&amba_reg); if (ret < 0) { - pr_err("Failed to register AMBA-PL011 driver\n"); + dev_err(&dev->dev, + "Failed to register AMBA-PL011 driver\n"); return ret; } } @@ -2242,7 +2208,6 @@ static int pl011_probe(struct amba_device *dev, const struct amba_id *id) if (ret) { amba_ports[i] = NULL; uart_unregister_driver(&amba_reg); - pl011_dma_remove(uap); } return ret;