cregit-Linux how code gets into the kernel

Release 4.11 drivers/mmc/core/sdio_irq.c

Directory: drivers/mmc/core
/*
 * linux/drivers/mmc/core/sdio_irq.c
 *
 * Author:      Nicolas Pitre
 * Created:     June 18, 2007
 * Copyright:   MontaVista Software Inc.
 *
 * Copyright 2008 Pierre Ossman
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 */

#include <linux/kernel.h>
#include <linux/sched.h>
#include <uapi/linux/sched/types.h>
#include <linux/kthread.h>
#include <linux/export.h>
#include <linux/wait.h>
#include <linux/delay.h>

#include <linux/mmc/core.h>
#include <linux/mmc/host.h>
#include <linux/mmc/card.h>
#include <linux/mmc/sdio.h>
#include <linux/mmc/sdio_func.h>

#include "sdio_ops.h"
#include "core.h"
#include "card.h"


static int process_sdio_pending_irqs(struct mmc_host *host) { struct mmc_card *card = host->card; int i, ret, count; unsigned char pending; struct sdio_func *func; /* * Optimization, if there is only 1 function interrupt registered * and we know an IRQ was signaled then call irq handler directly. * Otherwise do the full probe. */ func = card->sdio_single_irq; if (func && host->sdio_irq_pending) { func->irq_handler(func); return 1; } ret = mmc_io_rw_direct(card, 0, 0, SDIO_CCCR_INTx, 0, &pending); if (ret) { pr_debug("%s: error %d reading SDIO_CCCR_INTx\n", mmc_card_id(card), ret); return ret; } if (pending && mmc_card_broken_irq_polling(card) && !(host->caps & MMC_CAP_SDIO_IRQ)) { unsigned char dummy; /* A fake interrupt could be created when we poll SDIO_CCCR_INTx * register with a Marvell SD8797 card. A dummy CMD52 read to * function 0 register 0xff can avoid this. */ mmc_io_rw_direct(card, 0, 0, 0xff, 0, &dummy); } count = 0; for (i = 1; i <= 7; i++) { if (pending & (1 << i)) { func = card->sdio_func[i - 1]; if (!func) { pr_warn("%s: pending IRQ for non-existent function\n", mmc_card_id(card)); ret = -EINVAL; } else if (func->irq_handler) { func->irq_handler(func); count++; } else { pr_warn("%s: pending IRQ with no handler\n", sdio_func_id(func)); ret = -EINVAL; } } } if (count) return count; return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Nico Pitre17066.93%444.44%
Bing Zhao4116.14%111.11%
Stefan Nilsson XK2911.42%111.11%
Pierre Ossman103.94%111.11%
Joe Perches31.18%111.11%
Girish K.S10.39%111.11%
Total254100.00%9100.00%


void sdio_run_irqs(struct mmc_host *host) { mmc_claim_host(host); host->sdio_irq_pending = true; process_sdio_pending_irqs(host); mmc_release_host(host); }

Contributors

PersonTokensPropCommitsCommitProp
Russell King31100.00%1100.00%
Total31100.00%1100.00%

EXPORT_SYMBOL_GPL(sdio_run_irqs);
static int sdio_irq_thread(void *_host) { struct mmc_host *host = _host; struct sched_param param = { .sched_priority = 1 }; unsigned long period, idle_period; int ret; sched_setscheduler(current, SCHED_FIFO, &param); /* * We want to allow for SDIO cards to work even on non SDIO * aware hosts. One thing that non SDIO host cannot do is * asynchronous notification of pending SDIO card interrupts * hence we poll for them in that case. */ idle_period = msecs_to_jiffies(10); period = (host->caps & MMC_CAP_SDIO_IRQ) ? MAX_SCHEDULE_TIMEOUT : idle_period; pr_debug("%s: IRQ thread started (poll period = %lu jiffies)\n", mmc_hostname(host), period); do { /* * We claim the host here on drivers behalf for a couple * reasons: * * 1) it is already needed to retrieve the CCCR_INTx; * 2) we want the driver(s) to clear the IRQ condition ASAP; * 3) we need to control the abort condition locally. * * Just like traditional hard IRQ handlers, we expect SDIO * IRQ handlers to be quick and to the point, so that the * holding of the host lock does not cover too much work * that doesn't require that lock to be held. */ ret = __mmc_claim_host(host, &host->sdio_irq_thread_abort); if (ret) break; ret = process_sdio_pending_irqs(host); host->sdio_irq_pending = false; mmc_release_host(host); /* * Give other threads a chance to run in the presence of * errors. */ if (ret < 0) { set_current_state(TASK_INTERRUPTIBLE); if (!kthread_should_stop()) schedule_timeout(HZ); set_current_state(TASK_RUNNING); } /* * Adaptive polling frequency based on the assumption * that an interrupt will be closely followed by more. * This has a substantial benefit for network devices. */ if (!(host->caps & MMC_CAP_SDIO_IRQ)) { if (ret > 0) period /= 2; else { period++; if (period > idle_period) period = idle_period; } } set_current_state(TASK_INTERRUPTIBLE); if (host->caps & MMC_CAP_SDIO_IRQ) host->ops->enable_sdio_irq(host, 1); if (!kthread_should_stop()) schedule_timeout(period); set_current_state(TASK_RUNNING); } while (!kthread_should_stop()); if (host->caps & MMC_CAP_SDIO_IRQ) host->ops->enable_sdio_irq(host, 0); pr_debug("%s: IRQ thread exiting with code %d\n", mmc_hostname(host), ret); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Nico Pitre19672.32%350.00%
Pierre Ossman7326.94%233.33%
Robert P. J. Day20.74%116.67%
Total271100.00%6100.00%


static int sdio_card_irq_get(struct mmc_card *card) { struct mmc_host *host = card->host; WARN_ON(!host->claimed); if (!host->sdio_irqs++) { if (!(host->caps2 & MMC_CAP2_SDIO_IRQ_NOTHREAD)) { atomic_set(&host->sdio_irq_thread_abort, 0); host->sdio_irq_thread = kthread_run(sdio_irq_thread, host, "ksdioirqd/%s", mmc_hostname(host)); if (IS_ERR(host->sdio_irq_thread)) { int err = PTR_ERR(host->sdio_irq_thread); host->sdio_irqs--; return err; } } else if (host->caps & MMC_CAP_SDIO_IRQ) { host->ops->enable_sdio_irq(host, 1); } } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Nico Pitre9168.42%120.00%
Russell King2619.55%120.00%
Fu Zhonghui96.77%120.00%
Pierre Ossman75.26%240.00%
Total133100.00%5100.00%


static int sdio_card_irq_put(struct mmc_card *card) { struct mmc_host *host = card->host; WARN_ON(!host->claimed); if (host->sdio_irqs < 1) return -EINVAL; if (!--host->sdio_irqs) { if (!(host->caps2 & MMC_CAP2_SDIO_IRQ_NOTHREAD)) { atomic_set(&host->sdio_irq_thread_abort, 1); kthread_stop(host->sdio_irq_thread); } else if (host->caps & MMC_CAP_SDIO_IRQ) { host->ops->enable_sdio_irq(host, 0); } } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Nico Pitre6259.05%120.00%
Russell King2624.76%120.00%
Fu Zhonghui98.57%120.00%
Shawn Lin76.67%120.00%
Pierre Ossman10.95%120.00%
Total105100.00%5100.00%

/* If there is only 1 function registered set sdio_single_irq */
static void sdio_single_irq_set(struct mmc_card *card) { struct sdio_func *func; int i; card->sdio_single_irq = NULL; if ((card->host->caps & MMC_CAP_SDIO_IRQ) && card->host->sdio_irqs == 1) for (i = 0; i < card->sdio_funcs; i++) { func = card->sdio_func[i]; if (func && func->irq_handler) { card->sdio_single_irq = func; break; } } }

Contributors

PersonTokensPropCommitsCommitProp
Stefan Nilsson XK88100.00%1100.00%
Total88100.00%1100.00%

/** * sdio_claim_irq - claim the IRQ for a SDIO function * @func: SDIO function * @handler: IRQ handler callback * * Claim and activate the IRQ for the given SDIO function. The provided * handler will be called when that IRQ is asserted. The host is always * claimed already when the handler is called so the handler must not * call sdio_claim_host() nor sdio_release_host(). */
int sdio_claim_irq(struct sdio_func *func, sdio_irq_handler_t *handler) { int ret; unsigned char reg; if (!func) return -EINVAL; pr_debug("SDIO: Enabling IRQ for %s...\n", sdio_func_id(func)); if (func->irq_handler) { pr_debug("SDIO: IRQ for %s already in use.\n", sdio_func_id(func)); return -EBUSY; } ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IENx, 0, &reg); if (ret) return ret; reg |= 1 << func->num; reg |= 1; /* Master interrupt enable */ ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IENx, reg, NULL); if (ret) return ret; func->irq_handler = handler; ret = sdio_card_irq_get(func->card); if (ret) func->irq_handler = NULL; sdio_single_irq_set(func->card); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Nico Pitre14991.41%133.33%
Stefan Nilsson XK74.29%133.33%
Shawn Lin74.29%133.33%
Total163100.00%3100.00%

EXPORT_SYMBOL_GPL(sdio_claim_irq); /** * sdio_release_irq - release the IRQ for a SDIO function * @func: SDIO function * * Disable and release the IRQ for the given SDIO function. */
int sdio_release_irq(struct sdio_func *func) { int ret; unsigned char reg; if (!func) return -EINVAL; pr_debug("SDIO: Disabling IRQ for %s...\n", sdio_func_id(func)); if (func->irq_handler) { func->irq_handler = NULL; sdio_card_irq_put(func->card); sdio_single_irq_set(func->card); } ret = mmc_io_rw_direct(func->card, 0, 0, SDIO_CCCR_IENx, 0, &reg); if (ret) return ret; reg &= ~(1 << func->num); /* Disable master interrupt with the last function interrupt */ if (!(reg & 0xFE)) reg = 0; ret = mmc_io_rw_direct(func->card, 1, 0, SDIO_CCCR_IENx, reg, NULL); if (ret) return ret; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Nico Pitre13190.34%133.33%
Shawn Lin74.83%133.33%
Stefan Nilsson XK74.83%133.33%
Total145100.00%3100.00%

EXPORT_SYMBOL_GPL(sdio_release_irq);

Overall Contributors

PersonTokensPropCommitsCommitProp
Nico Pitre84467.30%523.81%
Stefan Nilsson XK13210.53%14.76%
Pierre Ossman927.34%419.05%
Russell King887.02%14.76%
Bing Zhao413.27%14.76%
Shawn Lin211.67%14.76%
Fu Zhonghui181.44%14.76%
Ulf Hansson60.48%29.52%
Paul Gortmaker30.24%14.76%
Joe Perches30.24%14.76%
Ingo Molnar30.24%14.76%
Robert P. J. Day20.16%14.76%
Girish K.S10.08%14.76%
Total1254100.00%21100.00%
Directory: drivers/mmc/core
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.