From owner-svn-src-all@FreeBSD.ORG Thu Feb 28 19:43:15 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 5243E85F; Thu, 28 Feb 2013 19:43:15 +0000 (UTC) (envelope-from gonzo@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 35A6AE7D; Thu, 28 Feb 2013 19:43:15 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r1SJhFvS023268; Thu, 28 Feb 2013 19:43:15 GMT (envelope-from gonzo@svn.freebsd.org) Received: (from gonzo@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r1SJhEmC023261; Thu, 28 Feb 2013 19:43:14 GMT (envelope-from gonzo@svn.freebsd.org) Message-Id: <201302281943.r1SJhEmC023261@svn.freebsd.org> From: Oleksandr Tymoshenko Date: Thu, 28 Feb 2013 19:43:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r247495 - head/sys/dev/sdhci 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.14 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: Thu, 28 Feb 2013 19:43:15 -0000 Author: gonzo Date: Thu Feb 28 19:43:14 2013 New Revision: 247495 URL: http://svnweb.freebsd.org/changeset/base/247495 Log: Add hooks for plugging platform-provided transfer backend. In order to use platorm backend hardware driver should impement three methods: - platform_start_transfer and platform_finish_transfer to start and finish transfer - platform_will_handle - check whether transaction is suitable for backend. If not - driver will fall back to PIO mode. Submitted by: Daisuke Aoyama Approved by: ian@ Modified: head/sys/dev/sdhci/sdhci.c head/sys/dev/sdhci/sdhci.h head/sys/dev/sdhci/sdhci_if.m Modified: head/sys/dev/sdhci/sdhci.c ============================================================================== --- head/sys/dev/sdhci/sdhci.c Thu Feb 28 19:36:22 2013 (r247494) +++ head/sys/dev/sdhci/sdhci.c Thu Feb 28 19:43:14 2013 (r247495) @@ -573,6 +573,13 @@ sdhci_init_slot(device_t dev, struct sdh if (slot->quirks & SDHCI_QUIRK_FORCE_DMA) slot->opt |= SDHCI_HAVE_DMA; + /* + * Use platform-provided transfer backend + * with PIO as a fallback mechanism + */ + if (slot->opt & SDHCI_PLATFORM_TRANSFER) + slot->opt &= ~SDHCI_HAVE_DMA; + if (bootverbose || sdhci_debug) { slot_printf(slot, "%uMHz%s 4bits%s%s%s %s\n", slot->max_clk / 1000000, @@ -909,7 +916,7 @@ sdhci_start_data(struct sdhci_slot *slot WR2(slot, SDHCI_BLOCK_COUNT, (data->len + 511) / 512); } -static void +void sdhci_finish_data(struct sdhci_slot *slot) { struct mmc_data *data = slot->curcmd->data; @@ -1102,13 +1109,23 @@ sdhci_data_irq(struct sdhci_slot *slot, } if (slot->curcmd->error) { /* No need to continue after any error. */ - sdhci_finish_data(slot); + if (slot->flags & PLATFORM_DATA_STARTED) { + slot->flags &= ~PLATFORM_DATA_STARTED; + SDHCI_PLATFORM_FINISH_TRANSFER(slot->bus, slot); + } else + sdhci_finish_data(slot); return; } /* Handle PIO interrupt. */ - if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) - sdhci_transfer_pio(slot); + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) { + if ((slot->opt & SDHCI_PLATFORM_TRANSFER) && + SDHCI_PLATFORM_WILL_HANDLE(slot->bus, slot)) { + SDHCI_PLATFORM_START_TRANSFER(slot->bus, slot, &intmask); + slot->flags |= PLATFORM_DATA_STARTED; + } else + sdhci_transfer_pio(slot); + } /* Handle DMA border. */ if (intmask & SDHCI_INT_DMA_END) { struct mmc_data *data = slot->curcmd->data; @@ -1147,8 +1164,13 @@ sdhci_data_irq(struct sdhci_slot *slot, WR4(slot, SDHCI_DMA_ADDRESS, slot->paddr); } /* We have got all data. */ - if (intmask & SDHCI_INT_DATA_END) - sdhci_finish_data(slot); + if (intmask & SDHCI_INT_DATA_END) { + if (slot->flags & PLATFORM_DATA_STARTED) { + slot->flags &= ~PLATFORM_DATA_STARTED; + SDHCI_PLATFORM_FINISH_TRANSFER(slot->bus, slot); + } else + sdhci_finish_data(slot); + } } static void Modified: head/sys/dev/sdhci/sdhci.h ============================================================================== --- head/sys/dev/sdhci/sdhci.h Thu Feb 28 19:36:22 2013 (r247494) +++ head/sys/dev/sdhci/sdhci.h Thu Feb 28 19:43:14 2013 (r247495) @@ -224,8 +224,9 @@ struct sdhci_slot { device_t dev; /* Slot device */ u_char num; /* Slot number */ u_char opt; /* Slot options */ +#define SDHCI_HAVE_DMA 1 +#define SDHCI_PLATFORM_TRANSFER 2 u_char version; -#define SDHCI_HAVE_DMA 1 uint32_t max_clk; /* Max possible freq */ uint32_t timeout_clk; /* Timeout freq */ bus_dma_tag_t dmatag; @@ -250,6 +251,7 @@ struct sdhci_slot { #define CMD_STARTED 1 #define STOP_STARTED 2 #define SDHCI_USE_DMA 4 /* Use DMA for this req. */ +#define PLATFORM_DATA_STARTED 8 /* Data transfer is handled by platform */ struct mtx mtx; /* Slot mutex */ }; @@ -257,6 +259,8 @@ int sdhci_generic_read_ivar(device_t bus int sdhci_generic_write_ivar(device_t bus, device_t child, int which, uintptr_t value); int sdhci_init_slot(device_t dev, struct sdhci_slot *slot, int num); void sdhci_start_slot(struct sdhci_slot *slot); +/* performs generic clean-up for platform transfers */ +void sdhci_finish_data(struct sdhci_slot *slot); int sdhci_cleanup_slot(struct sdhci_slot *slot); int sdhci_generic_suspend(struct sdhci_slot *slot); int sdhci_generic_resume(struct sdhci_slot *slot); Modified: head/sys/dev/sdhci/sdhci_if.m ============================================================================== --- head/sys/dev/sdhci/sdhci_if.m Thu Feb 28 19:36:22 2013 (r247494) +++ head/sys/dev/sdhci/sdhci_if.m Thu Feb 28 19:43:14 2013 (r247495) @@ -131,6 +131,22 @@ METHOD void write_multi_4 { bus_size_t count; } +METHOD int platform_will_handle { + device_t brdev; + struct sdhci_slot *slot; +} + +METHOD void platform_start_transfer { + device_t brdev; + struct sdhci_slot *slot; + uint32_t *intmask; +} + +METHOD void platform_finish_transfer { + device_t brdev; + struct sdhci_slot *slot; +} + METHOD uint32_t min_freq { device_t brdev; struct sdhci_slot *slot;