From owner-svn-src-all@freebsd.org Wed Feb 14 21:14:30 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DC815F20CBB; Wed, 14 Feb 2018 21:14:29 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8A2C46D942; Wed, 14 Feb 2018 21:14:29 +0000 (UTC) (envelope-from gonzo@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 8175A15316; Wed, 14 Feb 2018 21:14:29 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w1ELETw4031186; Wed, 14 Feb 2018 21:14:29 GMT (envelope-from gonzo@FreeBSD.org) Received: (from gonzo@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w1ELETkO031184; Wed, 14 Feb 2018 21:14:29 GMT (envelope-from gonzo@FreeBSD.org) Message-Id: <201802142114.w1ELETkO031184@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: gonzo set sender to gonzo@FreeBSD.org using -f From: Oleksandr Tymoshenko Date: Wed, 14 Feb 2018 21:14:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r329278 - in stable/11/sys: dev/spibus modules modules/spigen X-SVN-Group: stable-11 X-SVN-Commit-Author: gonzo X-SVN-Commit-Paths: in stable/11/sys: dev/spibus modules modules/spigen X-SVN-Commit-Revision: 329278 X-SVN-Commit-Repository: base 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.25 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: Wed, 14 Feb 2018 21:14:30 -0000 Author: gonzo Date: Wed Feb 14 21:14:28 2018 New Revision: 329278 URL: https://svnweb.freebsd.org/changeset/base/329278 Log: MFC r314933-r314934 r314933: [spigen] make spigen device ready to be compiled as a module - Add flag to indicate that device is opened by userland - Replace "always fail" detach method with proper detach implementation r314934: [spigen] Add spigen module spigen provides userland API to SPI bus. Make it available as a loadable module so people using official ARM images can enabled it on devices like BBB or RPi without re-building kernel Added: stable/11/sys/modules/spigen/ - copied from r314934, head/sys/modules/spigen/ Modified: stable/11/sys/dev/spibus/spigen.c stable/11/sys/modules/Makefile Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/spibus/spigen.c ============================================================================== --- stable/11/sys/dev/spibus/spigen.c Wed Feb 14 21:02:38 2018 (r329277) +++ stable/11/sys/dev/spibus/spigen.c Wed Feb 14 21:14:28 2018 (r329278) @@ -53,6 +53,9 @@ __FBSDID("$FreeBSD$"); #include "spibus_if.h" +#define SPIGEN_OPEN (1 << 0) +#define SPIGEN_MMAP_BUSY (1 << 1) + struct spigen_softc { device_t sc_dev; struct cdev *sc_cdev; @@ -63,8 +66,8 @@ struct spigen_softc { vm_object_t sc_mmap_buffer; /* command, then data */ vm_offset_t sc_mmap_kvaddr; size_t sc_mmap_buffer_size; - int sc_mmap_busy; int sc_debug; + int sc_flags; }; #ifdef FDT @@ -191,10 +194,24 @@ spigen_attach(device_t dev) } static int -spigen_open(struct cdev *dev, int oflags, int devtype, struct thread *td) +spigen_open(struct cdev *cdev, int oflags, int devtype, struct thread *td) { + int error; + device_t dev; + struct spigen_softc *sc; - return (0); + error = 0; + dev = cdev->si_drv1; + sc = device_get_softc(dev); + + mtx_lock(&sc->sc_mtx); + if (sc->sc_flags & SPIGEN_OPEN) + error = EBUSY; + else + sc->sc_flags |= SPIGEN_OPEN; + mtx_unlock(&sc->sc_mtx); + + return (error); } static int @@ -264,7 +281,7 @@ spigen_transfer_mmapped(struct cdev *cdev, struct spig int error = 0; mtx_lock(&sc->sc_mtx); - if (sc->sc_mmap_busy) + if (sc->sc_flags & SPIGEN_MMAP_BUSY) error = EBUSY; else if (stm->stm_command_length > sc->sc_command_length_max || stm->stm_data_length > sc->sc_data_length_max) @@ -275,7 +292,7 @@ spigen_transfer_mmapped(struct cdev *cdev, struct spig stm->stm_command_length + stm->stm_data_length) error = ENOMEM; if (error == 0) - sc->sc_mmap_busy = 1; + sc->sc_flags |= SPIGEN_MMAP_BUSY; mtx_unlock(&sc->sc_mtx); if (error) return (error); @@ -288,8 +305,8 @@ spigen_transfer_mmapped(struct cdev *cdev, struct spig error = SPIBUS_TRANSFER(device_get_parent(dev), dev, &transfer); mtx_lock(&sc->sc_mtx); - KASSERT(sc->sc_mmap_busy, ("mmap no longer marked busy")); - sc->sc_mmap_busy = 0; + KASSERT((sc->sc_flags & SPIGEN_MMAP_BUSY), ("mmap no longer marked busy")); + sc->sc_flags &= ~(SPIGEN_MMAP_BUSY); mtx_unlock(&sc->sc_mtx); return (error); } @@ -391,6 +408,7 @@ spigen_close(struct cdev *cdev, int fflag, int devtype sc->sc_mmap_buffer = NULL; sc->sc_mmap_buffer_size = 0; } + sc->sc_flags &= ~(SPIGEN_OPEN); mtx_unlock(&sc->sc_mtx); return (0); } @@ -398,8 +416,23 @@ spigen_close(struct cdev *cdev, int fflag, int devtype static int spigen_detach(device_t dev) { + struct spigen_softc *sc; - return (EIO); + sc = device_get_softc(dev); + + mtx_lock(&sc->sc_mtx); + if (sc->sc_flags & SPIGEN_OPEN) { + mtx_unlock(&sc->sc_mtx); + return (EBUSY); + } + mtx_unlock(&sc->sc_mtx); + + mtx_destroy(&sc->sc_mtx); + + if (sc->sc_cdev) + destroy_dev(sc->sc_cdev); + + return (0); } static devclass_t spigen_devclass; Modified: stable/11/sys/modules/Makefile ============================================================================== --- stable/11/sys/modules/Makefile Wed Feb 14 21:02:38 2018 (r329277) +++ stable/11/sys/modules/Makefile Wed Feb 14 21:14:28 2018 (r329278) @@ -359,6 +359,7 @@ SUBDIR= \ snp \ sound \ ${_speaker} \ + spigen \ ${_splash} \ ${_sppp} \ ste \