Received: by 10.223.185.116 with SMTP id b49csp1446255wrg; Sun, 11 Feb 2018 12:12:31 -0800 (PST) X-Google-Smtp-Source: AH8x224ruwSuVA/mzlDzdZIQ5HWZhwOx5HKpH2IKz9hKKHDR9Qh94H9QRNrlbVWKuT0+jcnRjNX4 X-Received: by 10.99.122.74 with SMTP id j10mr3396974pgn.84.1518379951079; Sun, 11 Feb 2018 12:12:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518379951; cv=none; d=google.com; s=arc-20160816; b=A2ezDn/F7rt1zK1J8l0wVcoNW5DKesp8LoPqlw/5dlpv732tiYQKP2oNBYMzGJ7/4B bJ0HRSH6wlM4+jKBIcKtXecZDsh+p7EidN5dkWePkVoeV3A58k2fYc9y2rUEaHOsYH68 9AHvXdb3JDWyPmZ3CeI4zAg69KjCx4NPNcJX0KYJLDZ3eDQOTkkc/qh65g3/d3Km1pxw GueoY6eGh2GhLef1WKacIdwWbKXnXulWgJuPHF5lbmRi8MC0oxlZh/P9VvMWdsI3l1RO e7ba8+Y6M9v4DWQ45/QHkzf1POS1/E0aJWChl/f37KxCPpeUuiVDr3CU4O73LutBJ+Zb M34g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=D9/lZTIIeXOQfRjEYMYANVOta21TZoiavz+GswsYadU=; b=yefvvVKNXKcyCHnttdGkliK+qGsxGxlFRBwyhuZ77OWBa4gxAZnU5aq6Ij3Rsl6r4O quhcihOHhcalxHOsfqvPJ2haE7dKKDQIX5q7svLhcWfnOVWewpzCqEBGG6uhwW4OmT+W ydzlQL2edX7OAesYksI7bxuwF2Ij7QV+sWzXW6kHtMNAflagknnFfCnUGDKFC7YlW/00 nLjMZPpp9zQK7qpjK4548ZMjweMrqxB3txh1EOB0Dj6lW8fs8lMiFUe3I8nzKuHInfKr zT/zbOCJVtKqO89VeY+1gjLbU9t5xBMEhO9VWriT+I6r0nogCwI3RSJaqqW+pqHk0UFb 6qMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=fESmoLuy; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v80si1194023pfj.80.2018.02.11.12.12.17; Sun, 11 Feb 2018 12:12:31 -0800 (PST) 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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=fESmoLuy; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932215AbeBKULY (ORCPT + 99 others); Sun, 11 Feb 2018 15:11:24 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:46964 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932140AbeBKULX (ORCPT ); Sun, 11 Feb 2018 15:11:23 -0500 Received: by mail-pg0-f68.google.com with SMTP id a11so6094140pgu.13; Sun, 11 Feb 2018 12:11:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=D9/lZTIIeXOQfRjEYMYANVOta21TZoiavz+GswsYadU=; b=fESmoLuyvtjtJWxAG97yNpPIuLisluYY9Tblo8WKRPv7sAer1PanjR40+g8YV+aVz+ ABuvoJ0pUMu8TZLApZCtNaIZrg+wHLZPInL3kO4XmEf+wYj/3lhTcs02QspcpBiT0D+n bQmYb9Avn2wivDb/nXWhWXiWM9sKVqIlcMBzMHLYcDwRVJrp77MS/rdIRdrcwK6EUCN1 psNk4MhffGFE3thwNzZb6ltN4XhZNI1PgExevhZYPrPbzx5FTbOXHxcsqg3Hp3GUD4oJ 3l8Cy4XA/VL0cI38JnJpGA2ZiHSN3pQJeFSjpmIswksHjZ4bQ/x2SWFXGcVJ6H8GV6Eb ZW/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to:user-agent; bh=D9/lZTIIeXOQfRjEYMYANVOta21TZoiavz+GswsYadU=; b=nU7xtRz80r3gNe4XRsa61hUzIzKP9mLXC6APlrC1MPhCWclGppXjkvJZuKpxBRVzaw n+zVlhUEt70HXT+DvUfBfJwArQb1btRosOG8LKy6IZmGhCHLJ6H31ETK+c0IvGRRzTCj 3IbWDAke+TXxygE7QhsBAakc0mXtaZ3+rquVWtKqMCe+wE53okqFuTR4xZKjIww/ww5C LFGKXHotOtuUDjL3DO8Vd3BuUWZwWsLpUJJ/W8bsv0eJ7hzrcrlnLg79dojDPoC1G9V1 digAPsqiHUuq/B7hEqoV3SQ/R6WBmTaqQj/sjr5E52U66au1OjJwivDbIBj6qjWGuYdU eUdA== X-Gm-Message-State: APf1xPAIN91a8XiafBPwf0Un6Wotxw0KH4me42TZJDHc/Au9R+gwTubZ 2XqRHdy3kqg4zetNf6WoddkBHw== X-Received: by 10.99.144.74 with SMTP id a71mr7604259pge.244.1518379882538; Sun, 11 Feb 2018 12:11:22 -0800 (PST) Received: from localhost (108-223-40-66.lightspeed.sntcca.sbcglobal.net. [108.223.40.66]) by smtp.gmail.com with ESMTPSA id s12sm17961301pfd.165.2018.02.11.12.11.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 11 Feb 2018 12:11:21 -0800 (PST) Date: Sun, 11 Feb 2018 12:11:20 -0800 From: Guenter Roeck To: Wolfram Sang Cc: Jean Delvare , =?iso-8859-1?B?Wm9sdOFuIEL2c3r2cm3pbnlp?= , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [1/2] i2c: piix4: Use request_muxed_region Message-ID: <20180211201120.GA29394@roeck-us.net> References: <1514652658-6228-1-git-send-email-linux@roeck-us.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1514652658-6228-1-git-send-email-linux@roeck-us.net> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Dec 30, 2017 at 08:50:57AM -0800, Guenter Roeck wrote: > Accesses to SB800_PIIX4_SMB_IDX can occur from multiple drivers. > Use request_muxed_region() to ensure synchronization. > > Signed-off-by: Guenter Roeck Any comments on this patch ? Thanks, Guenter > --- > drivers/i2c/busses/i2c-piix4.c | 50 ++++++++++++++++++------------------------ > 1 file changed, 21 insertions(+), 29 deletions(-) > > diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c > index 462948e2c535..78dd5951d6e7 100644 > --- a/drivers/i2c/busses/i2c-piix4.c > +++ b/drivers/i2c/busses/i2c-piix4.c > @@ -153,10 +153,7 @@ static const struct dmi_system_id piix4_dmi_ibm[] = { > > /* > * SB800 globals > - * piix4_mutex_sb800 protects piix4_port_sel_sb800 and the pair > - * of I/O ports at SB800_PIIX4_SMB_IDX. > */ > -static DEFINE_MUTEX(piix4_mutex_sb800); > static u8 piix4_port_sel_sb800; > static u8 piix4_port_mask_sb800; > static u8 piix4_port_shift_sb800; > @@ -298,12 +295,15 @@ static int piix4_setup_sb800(struct pci_dev *PIIX4_dev, > else > smb_en = (aux) ? 0x28 : 0x2c; > > - mutex_lock(&piix4_mutex_sb800); > + if (!request_muxed_region(SB800_PIIX4_SMB_IDX, 2, "sb800_piix4_smb")) > + return -EBUSY; > + > outb_p(smb_en, SB800_PIIX4_SMB_IDX); > smba_en_lo = inb_p(SB800_PIIX4_SMB_IDX + 1); > outb_p(smb_en + 1, SB800_PIIX4_SMB_IDX); > smba_en_hi = inb_p(SB800_PIIX4_SMB_IDX + 1); > - mutex_unlock(&piix4_mutex_sb800); > + > + release_region(SB800_PIIX4_SMB_IDX, 2); > > if (!smb_en) { > smb_en_status = smba_en_lo & 0x10; > @@ -373,7 +373,12 @@ static int piix4_setup_sb800(struct pci_dev *PIIX4_dev, > break; > } > } else { > - mutex_lock(&piix4_mutex_sb800); > + if (!request_muxed_region(SB800_PIIX4_SMB_IDX, 2, > + "sb800_piix4_smb")) { > + release_region(piix4_smba, SMBIOSIZE); > + return -EBUSY; > + } > + > outb_p(SB800_PIIX4_PORT_IDX_SEL, SB800_PIIX4_SMB_IDX); > port_sel = inb_p(SB800_PIIX4_SMB_IDX + 1); > piix4_port_sel_sb800 = (port_sel & 0x01) ? > @@ -381,7 +386,7 @@ static int piix4_setup_sb800(struct pci_dev *PIIX4_dev, > SB800_PIIX4_PORT_IDX; > piix4_port_mask_sb800 = SB800_PIIX4_PORT_IDX_MASK; > piix4_port_shift_sb800 = SB800_PIIX4_PORT_IDX_SHIFT; > - mutex_unlock(&piix4_mutex_sb800); > + release_region(SB800_PIIX4_SMB_IDX, 2); > } > > dev_info(&PIIX4_dev->dev, > @@ -679,7 +684,8 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr, > u8 port; > int retval; > > - mutex_lock(&piix4_mutex_sb800); > + if (!request_muxed_region(SB800_PIIX4_SMB_IDX, 2, "sb800_piix4_smb")) > + return -EBUSY; > > /* Request the SMBUS semaphore, avoid conflicts with the IMC */ > smbslvcnt = inb_p(SMBSLVCNT); > @@ -695,8 +701,8 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr, > } while (--retries); > /* SMBus is still owned by the IMC, we give up */ > if (!retries) { > - mutex_unlock(&piix4_mutex_sb800); > - return -EBUSY; > + retval = -EBUSY; > + goto release; > } > > /* > @@ -753,8 +759,8 @@ static s32 piix4_access_sb800(struct i2c_adapter *adap, u16 addr, > if ((size == I2C_SMBUS_BLOCK_DATA) && adapdata->notify_imc) > piix4_imc_wakeup(); > > - mutex_unlock(&piix4_mutex_sb800); > - > +release: > + release_region(SB800_PIIX4_SMB_IDX, 2); > return retval; > } > > @@ -899,13 +905,6 @@ static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id) > bool notify_imc = false; > is_sb800 = true; > > - if (!request_region(SB800_PIIX4_SMB_IDX, 2, "smba_idx")) { > - dev_err(&dev->dev, > - "SMBus base address index region 0x%x already in use!\n", > - SB800_PIIX4_SMB_IDX); > - return -EBUSY; > - } > - > if (dev->vendor == PCI_VENDOR_ID_AMD && > dev->device == PCI_DEVICE_ID_AMD_KERNCZ_SMBUS) { > u8 imc; > @@ -922,20 +921,16 @@ static int piix4_probe(struct pci_dev *dev, const struct pci_device_id *id) > > /* base address location etc changed in SB800 */ > retval = piix4_setup_sb800(dev, id, 0); > - if (retval < 0) { > - release_region(SB800_PIIX4_SMB_IDX, 2); > + if (retval < 0) > return retval; > - } > > /* > * Try to register multiplexed main SMBus adapter, > * give up if we can't > */ > retval = piix4_add_adapters_sb800(dev, retval, notify_imc); > - if (retval < 0) { > - release_region(SB800_PIIX4_SMB_IDX, 2); > + if (retval < 0) > return retval; > - } > } else { > retval = piix4_setup(dev, id); > if (retval < 0) > @@ -983,11 +978,8 @@ static void piix4_adap_remove(struct i2c_adapter *adap) > > if (adapdata->smba) { > i2c_del_adapter(adap); > - if (adapdata->port == (0 << piix4_port_shift_sb800)) { > + if (adapdata->port == (0 << piix4_port_shift_sb800)) > release_region(adapdata->smba, SMBIOSIZE); > - if (adapdata->sb800_main) > - release_region(SB800_PIIX4_SMB_IDX, 2); > - } > kfree(adapdata); > kfree(adap); > }