cregit-Linux how code gets into the kernel

Release 4.7 drivers/usb/host/ehci-mem.c

Directory: drivers/usb/host
/*
 * Copyright (c) 2001 by David Brownell
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* this file is part of ehci-hcd.c */

/*-------------------------------------------------------------------------*/

/*
 * There's basically three types of memory:
 *      - data used only by the HCD ... kmalloc is fine
 *      - async and periodic schedules, shared by HC and HCD ... these
 *        need to use dma_pool or dma_alloc_coherent
 *      - driver buffers, read/written by HC ... single shot DMA mapped
 *
 * There's also "register" data (e.g. PCI or SOC), which is memory mapped.
 * No memory seen by this driver is pageable.
 */

/*-------------------------------------------------------------------------*/

/* Allocate the key transfer structures from the previously allocated pool */


static inline void ehci_qtd_init(struct ehci_hcd *ehci, struct ehci_qtd *qtd, dma_addr_t dma) { memset (qtd, 0, sizeof *qtd); qtd->qtd_dma = dma; qtd->hw_token = cpu_to_hc32(ehci, QTD_STS_HALT); qtd->hw_next = EHCI_LIST_END(ehci); qtd->hw_alt_next = EHCI_LIST_END(ehci); INIT_LIST_HEAD (&qtd->qtd_list); }

Contributors

PersonTokensPropCommitsCommitProp
david brownelldavid brownell6081.08%360.00%
stefan roesestefan roese1114.86%120.00%
anatolij gustschinanatolij gustschin34.05%120.00%
Total74100.00%5100.00%


static struct ehci_qtd *ehci_qtd_alloc (struct ehci_hcd *ehci, gfp_t flags) { struct ehci_qtd *qtd; dma_addr_t dma; qtd = dma_pool_alloc (ehci->qtd_pool, flags, &dma); if (qtd != NULL) { ehci_qtd_init(ehci, qtd, dma); } return qtd; }

Contributors

PersonTokensPropCommitsCommitProp
linus torvaldslinus torvalds5086.21%114.29%
david brownelldavid brownell35.17%228.57%
stefan roesestefan roese23.45%114.29%
alexey dobriyanalexey dobriyan11.72%114.29%
deepak saxenadeepak saxena11.72%114.29%
al viroal viro11.72%114.29%
Total58100.00%7100.00%


static inline void ehci_qtd_free (struct ehci_hcd *ehci, struct ehci_qtd *qtd) { dma_pool_free (ehci->qtd_pool, qtd, qtd->qtd_dma); }

Contributors

PersonTokensPropCommitsCommitProp
linus torvaldslinus torvalds2996.67%150.00%
deepak saxenadeepak saxena13.33%150.00%
Total30100.00%2100.00%


static void qh_destroy(struct ehci_hcd *ehci, struct ehci_qh *qh) { /* clean qtds first, and know this is not linked */ if (!list_empty (&qh->qtd_list) || qh->qh_next.ptr) { ehci_dbg (ehci, "unused qh not empty!\n"); BUG (); } if (qh->dummy) ehci_qtd_free (ehci, qh->dummy); dma_pool_free(ehci->qh_pool, qh->hw, qh->qh_dma); kfree(qh); }

Contributors

PersonTokensPropCommitsCommitProp
greg kroah-hartmangreg kroah-hartman6782.72%125.00%
alek dualek du78.64%125.00%
alan sternalan stern56.17%125.00%
david brownelldavid brownell22.47%125.00%
Total81100.00%4100.00%


static struct ehci_qh *ehci_qh_alloc (struct ehci_hcd *ehci, gfp_t flags) { struct ehci_qh *qh; dma_addr_t dma; qh = kzalloc(sizeof *qh, GFP_ATOMIC); if (!qh) goto done; qh->hw = (struct ehci_qh_hw *) dma_pool_alloc(ehci->qh_pool, flags, &dma); if (!qh->hw) goto fail; memset(qh->hw, 0, sizeof *qh->hw); qh->qh_dma = dma; // INIT_LIST_HEAD (&qh->qh_list); INIT_LIST_HEAD (&qh->qtd_list); INIT_LIST_HEAD(&qh->unlink_node); /* dummy td enables safe urb queuing */ qh->dummy = ehci_qtd_alloc (ehci, flags); if (qh->dummy == NULL) { ehci_dbg (ehci, "no dummy td\n"); goto fail1; } done: return qh; fail1: dma_pool_free(ehci->qh_pool, qh->hw, qh->qh_dma); fail: kfree(qh); return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
linus torvaldslinus torvalds7240.91%112.50%
alek dualek du5028.41%112.50%
david brownelldavid brownell4223.86%225.00%
ming leiming lei84.55%112.50%
deepak saxenadeepak saxena21.14%112.50%
al viroal viro10.57%112.50%
alexey dobriyanalexey dobriyan10.57%112.50%
Total176100.00%8100.00%

/*-------------------------------------------------------------------------*/ /* The queue heads and transfer descriptors are managed from pools tied * to each of the "per device" structures. * This is the initialisation and cleanup code. */
static void ehci_mem_cleanup (struct ehci_hcd *ehci) { if (ehci->async) qh_destroy(ehci, ehci->async); ehci->async = NULL; if (ehci->dummy) qh_destroy(ehci, ehci->dummy); ehci->dummy = NULL; /* DMA consistent memory and pools */ dma_pool_destroy(ehci->qtd_pool); ehci->qtd_pool = NULL; dma_pool_destroy(ehci->qh_pool); ehci->qh_pool = NULL; dma_pool_destroy(ehci->itd_pool); ehci->itd_pool = NULL; dma_pool_destroy(ehci->sitd_pool); ehci->sitd_pool = NULL; if (ehci->periodic) dma_free_coherent (ehci_to_hcd(ehci)->self.controller, ehci->periodic_size * sizeof (u32), ehci->periodic, ehci->periodic_dma); ehci->periodic = NULL; /* shadow periodic table */ kfree(ehci->pshadow); ehci->pshadow = NULL; }

Contributors

PersonTokensPropCommitsCommitProp
linus torvaldslinus torvalds10162.73%114.29%
andiry xuandiry xu1811.18%114.29%
david brownelldavid brownell1710.56%114.29%
alan sternalan stern95.59%228.57%
deepak saxenadeepak saxena95.59%114.29%
mika kukkonenmika kukkonen74.35%114.29%
Total161100.00%7100.00%

/* remember to add cleanup code (above) if you add anything here */
static int ehci_mem_init (struct ehci_hcd *ehci, gfp_t flags) { int i; /* QTDs for control/bulk/intr transfers */ ehci->qtd_pool = dma_pool_create ("ehci_qtd", ehci_to_hcd(ehci)->self.controller, sizeof (struct ehci_qtd), 32 /* byte alignment (for hw parts) */, 4096 /* can't cross 4K */); if (!ehci->qtd_pool) { goto fail; } /* QHs for control/bulk/intr transfers */ ehci->qh_pool = dma_pool_create ("ehci_qh", ehci_to_hcd(ehci)->self.controller, sizeof(struct ehci_qh_hw), 32 /* byte alignment (for hw parts) */, 4096 /* can't cross 4K */); if (!ehci->qh_pool) { goto fail; } ehci->async = ehci_qh_alloc (ehci, flags); if (!ehci->async) { goto fail; } /* ITD for high speed ISO transfers */ ehci->itd_pool = dma_pool_create ("ehci_itd", ehci_to_hcd(ehci)->self.controller, sizeof (struct ehci_itd), 32 /* byte alignment (for hw parts) */, 4096 /* can't cross 4K */); if (!ehci->itd_pool) { goto fail; } /* SITD for full/low speed split ISO transfers */ ehci->sitd_pool = dma_pool_create ("ehci_sitd", ehci_to_hcd(ehci)->self.controller, sizeof (struct ehci_sitd), 32 /* byte alignment (for hw parts) */, 4096 /* can't cross 4K */); if (!ehci->sitd_pool) { goto fail; } /* Hardware periodic table */ ehci->periodic = (__le32 *) dma_alloc_coherent (ehci_to_hcd(ehci)->self.controller, ehci->periodic_size * sizeof(__le32), &ehci->periodic_dma, flags); if (ehci->periodic == NULL) { goto fail; } if (ehci->use_dummy_qh) { struct ehci_qh_hw *hw; ehci->dummy = ehci_qh_alloc(ehci, flags); if (!ehci->dummy) goto fail; hw = ehci->dummy->hw; hw->hw_next = EHCI_LIST_END(ehci); hw->hw_qtd_next = EHCI_LIST_END(ehci); hw->hw_alt_next = EHCI_LIST_END(ehci); ehci->dummy->hw = hw; for (i = 0; i < ehci->periodic_size; i++) ehci->periodic[i] = cpu_to_hc32(ehci, ehci->dummy->qh_dma); } else { for (i = 0; i < ehci->periodic_size; i++) ehci->periodic[i] = EHCI_LIST_END(ehci); } /* software shadow of hardware table */ ehci->pshadow = kcalloc(ehci->periodic_size, sizeof(void *), flags); if (ehci->pshadow != NULL) return 0; fail: ehci_dbg (ehci, "couldn't init memory\n"); ehci_mem_cleanup (ehci); return -ENOMEM; }

Contributors

PersonTokensPropCommitsCommitProp
linus torvaldslinus torvalds23652.33%17.69%
andiry xuandiry xu10823.95%17.69%
david brownelldavid brownell5311.75%17.69%
deepak saxenadeepak saxena214.66%17.69%
alan sternalan stern204.43%215.38%
al viroal viro30.67%215.38%
eric sesterhenneric sesterhenn30.67%17.69%
stefan roesestefan roese30.67%17.69%
alexey dobriyanalexey dobriyan20.44%17.69%
vladimir zapolskiyvladimir zapolskiy10.22%17.69%
alek dualek du10.22%17.69%
Total451100.00%13100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
linus torvaldslinus torvalds49447.50%14.00%
david brownelldavid brownell17917.21%832.00%
andiry xuandiry xu12612.12%14.00%
greg kroah-hartmangreg kroah-hartman676.44%14.00%
alek dualek du585.58%14.00%
deepak saxenadeepak saxena343.27%14.00%
alan sternalan stern343.27%312.00%
stefan roesestefan roese171.63%14.00%
ming leiming lei80.77%14.00%
mika kukkonenmika kukkonen70.67%14.00%
al viroal viro50.48%28.00%
alexey dobriyanalexey dobriyan40.38%14.00%
anatolij gustschinanatolij gustschin30.29%14.00%
eric sesterhenneric sesterhenn30.29%14.00%
vladimir zapolskiyvladimir zapolskiy10.10%14.00%
Total1040100.00%25100.00%
Directory: drivers/usb/host
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}