From owner-svn-src-all@freebsd.org Fri Apr 8 15:28:14 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 570D3B089C7; Fri, 8 Apr 2016 15:28:14 +0000 (UTC) (envelope-from sgalabov@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 183771A55; Fri, 8 Apr 2016 15:28:14 +0000 (UTC) (envelope-from sgalabov@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u38FSD35062751; Fri, 8 Apr 2016 15:28:13 GMT (envelope-from sgalabov@FreeBSD.org) Received: (from sgalabov@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u38FSDRM062749; Fri, 8 Apr 2016 15:28:13 GMT (envelope-from sgalabov@FreeBSD.org) Message-Id: <201604081528.u38FSDRM062749@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sgalabov set sender to sgalabov@FreeBSD.org using -f From: Stanislav Galabov Date: Fri, 8 Apr 2016 15:28:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r297718 - head/sys/mips/mediatek X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Apr 2016 15:28:14 -0000 Author: sgalabov Date: Fri Apr 8 15:28:12 2016 New Revision: 297718 URL: https://svnweb.freebsd.org/changeset/base/297718 Log: Introduce better locking for mtk_gpio_v[12] drivers Approved by: adrian (mentor) Sponsored by: Smartcom - Bulgaria AD Differential Revision: https://reviews.freebsd.org/D5887 Modified: head/sys/mips/mediatek/mtk_gpio_v1.c head/sys/mips/mediatek/mtk_gpio_v2.c Modified: head/sys/mips/mediatek/mtk_gpio_v1.c ============================================================================== --- head/sys/mips/mediatek/mtk_gpio_v1.c Fri Apr 8 15:26:49 2016 (r297717) +++ head/sys/mips/mediatek/mtk_gpio_v1.c Fri Apr 8 15:28:12 2016 (r297718) @@ -431,19 +431,29 @@ mtk_gpio_pin_setflags(device_t dev, uint static int mtk_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value) { - struct mtk_gpio_softc *sc = device_get_softc(dev); + struct mtk_gpio_softc *sc; + int ret; + + sc = device_get_softc(dev); + ret = 0; - if (pin >= sc->num_pins || !(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) + if (pin >= sc->num_pins) return (EINVAL); MTK_GPIO_LOCK(sc); + if(!(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) { + ret = EINVAL; + goto out; + } + if (value) MTK_WRITE_4(sc, GPIO_PIOSET(sc), (1u << pin)); else MTK_WRITE_4(sc, GPIO_PIORESET(sc), (1u << pin)); - MTK_GPIO_UNLOCK(sc); - return (0); +out: + MTK_GPIO_UNLOCK(sc); + return (ret); } static int @@ -451,33 +461,50 @@ mtk_gpio_pin_get(device_t dev, uint32_t { struct mtk_gpio_softc *sc; uint32_t data; + int ret; sc = device_get_softc(dev); + ret = 0; - if (pin >= sc->num_pins || !(sc->pins[pin].pin_flags & GPIO_PIN_INPUT)) + if (pin >= sc->num_pins) return (EINVAL); MTK_GPIO_LOCK(sc); + if(!(sc->pins[pin].pin_flags & GPIO_PIN_INPUT)) { + ret = EINVAL; + goto out; + } data = MTK_READ_4(sc, GPIO_PIODATA(sc)); - MTK_GPIO_UNLOCK(sc); *val = (data & (1u << pin)) ? 1 : 0; - return (0); +out: + MTK_GPIO_UNLOCK(sc); + return (ret); } static int mtk_gpio_pin_toggle(device_t dev, uint32_t pin) { - struct mtk_gpio_softc *sc = device_get_softc(dev); + struct mtk_gpio_softc *sc; + int ret; - if (pin >= sc->num_pins || !(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) + if (pin >= sc->num_pins) return (EINVAL); + sc = device_get_softc(dev); + ret = 0; + MTK_GPIO_LOCK(sc); + if (!(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) { + ret = EINVAL; + goto out; + } MTK_WRITE_4(sc, GPIO_PIOTOG(sc), (1u << pin)); + +out: MTK_GPIO_UNLOCK(sc); - return (0); + return (ret); } static int @@ -571,7 +598,9 @@ mtk_gpio_pic_post_filter(device_t dev, s pisrc = (struct mtk_gpio_pin_irqsrc *)isrc; sc = device_get_softc(dev); + MTK_GPIO_LOCK(sc); MTK_WRITE_4(sc, GPIO_PIOINT(sc), 1u << pisrc->irq); + MTK_GPIO_UNLOCK(sc); } static int Modified: head/sys/mips/mediatek/mtk_gpio_v2.c ============================================================================== --- head/sys/mips/mediatek/mtk_gpio_v2.c Fri Apr 8 15:26:49 2016 (r297717) +++ head/sys/mips/mediatek/mtk_gpio_v2.c Fri Apr 8 15:28:12 2016 (r297718) @@ -425,19 +425,29 @@ mtk_gpio_pin_setflags(device_t dev, uint static int mtk_gpio_pin_set(device_t dev, uint32_t pin, unsigned int value) { - struct mtk_gpio_softc *sc = device_get_softc(dev); + struct mtk_gpio_softc *sc; + int ret; - if (pin >= sc->num_pins || !(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) + if (pin >= sc->num_pins) return (EINVAL); + sc = device_get_softc(dev); + ret = 0; + MTK_GPIO_LOCK(sc); + if (!(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) { + ret = EINVAL; + goto out; + } if (value) MTK_WRITE_4(sc, GPIO_PIOSET(sc), (1u << pin)); else MTK_WRITE_4(sc, GPIO_PIORESET(sc), (1u << pin)); + +out: MTK_GPIO_UNLOCK(sc); - return (0); + return (ret); } static int @@ -445,39 +455,56 @@ mtk_gpio_pin_get(device_t dev, uint32_t { struct mtk_gpio_softc *sc; uint32_t data; + int ret; - sc = device_get_softc(dev); - - if (pin >= sc->num_pins || !(sc->pins[pin].pin_flags & GPIO_PIN_INPUT)) + if (pin >= sc->num_pins) return (EINVAL); + sc = device_get_softc(dev); + ret = 0; + MTK_GPIO_LOCK(sc); + if (!(sc->pins[pin].pin_flags & GPIO_PIN_INPUT)) { + ret = EINVAL; + goto out; + } data = MTK_READ_4(sc, GPIO_PIODATA(sc)); - MTK_GPIO_UNLOCK(sc); *val = (data & (1u << pin)) ? 1 : 0; - return (0); +out: + MTK_GPIO_UNLOCK(sc); + return (ret); } static int mtk_gpio_pin_toggle(device_t dev, uint32_t pin) { - struct mtk_gpio_softc *sc = device_get_softc(dev); + struct mtk_gpio_softc *sc; uint32_t val; + int ret; - if (pin >= sc->num_pins || !(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) + if (pin >= sc->num_pins) return (EINVAL); + sc = device_get_softc(dev); + ret = 0; + MTK_GPIO_LOCK(sc); + if(!(sc->pins[pin].pin_flags & GPIO_PIN_OUTPUT)) { + ret = EINVAL; + goto out; + } val = MTK_READ_4(sc, GPIO_PIODATA(sc)); val &= (1u << pin); if (val) MTK_WRITE_4(sc, GPIO_PIORESET(sc), (1u << pin)); else MTK_WRITE_4(sc, GPIO_PIOSET(sc), (1u << pin)); + +out: MTK_GPIO_UNLOCK(sc); - return (0); + return (ret); } static int @@ -571,7 +598,9 @@ mtk_gpio_pic_post_filter(device_t dev, s pisrc = (struct mtk_gpio_pin_irqsrc *)isrc; sc = device_get_softc(dev); + MTK_GPIO_LOCK(sc); MTK_WRITE_4(sc, GPIO_PIOINT(sc), 1u << pisrc->irq); + MTK_GPIO_UNLOCK(sc); } static int