/* *Simplepoweroftwobuddy-likegenericallocator. *Providesnaturallyalignedmemorychunks. * *Thissimplecodeisnotintendedtobefast,butto *providepowerof2alignedmemoryallocations. *SincetheSCRIPTSprocessoronlysupplies8bitarithmetic, *thisallocatorallowssimpleandfastaddresscalculations *fromtheSCRIPTScode.Inaddition,cachelinealignment *isguaranteedforpowerof2cachelinesize. * *ThisallocatorhasbeendevelopedfortheLinuxsym53c8xx *driver,sincethisO/Sdoesnotprovidenaturallyaligned *allocations. *Ithastheadvantageofallowingthedrivertouseprivate *pagesofmemorythatwillbeusefulifweeverneedtodeal *withIOMMUsforPCI.
*/ staticvoid *___sym_malloc(m_pool_p mp, int size)
{ int i = 0; int s = (1 << SYM_MEM_SHIFT); int j; void *a;
m_link_p h = mp->h;
if (size > SYM_MEM_CLUSTER_SIZE) return NULL;
while (size > s) {
s <<= 1;
++i;
}
j = i; while (!h[j].next) { if (s == SYM_MEM_CLUSTER_SIZE) {
h[j].next = (m_link_p) M_GET_MEM_CLUSTER(); if (h[j].next)
h[j].next->next = NULL; break;
}
++j;
s <<= 1;
}
a = h[j].next; if (a) {
h[j].next = h[j].next->next; while (j > i) {
j -= 1;
s >>= 1;
h[j].next = (m_link_p) (a+s);
h[j].next->next = NULL;
}
} #ifdef DEBUG
printf("___sym_malloc(%d) = %p\n", size, (void *) a); #endif return a;
}
/* *Counter-partofthegenericallocator.
*/ staticvoid ___sym_mfree(m_pool_p mp, void *ptr, int size)
{ int i = 0; int s = (1 << SYM_MEM_SHIFT);
m_link_p q; unsignedlong a, b;
m_link_p h = mp->h;
/* *MethodsthatmaintainsDMAablepoolsaccordingtouserallocations. *Newpoolsarecreatedontheflywhenanewpoolidisprovided. *Theyaredeletedontheflywhentheygetemptied.
*/ /* Get a memory cluster that matches the DMA constraints of a given pool */ staticvoid * ___get_dma_mem_cluster(m_pool_p mp)
{
m_vtob_p vbp; void *vaddr;
vbp = __sym_calloc(&mp0, sizeof(*vbp), "VTOB"); if (!vbp) goto out_err;
vaddr = sym_m_get_dma_mem_cluster(mp, vbp); if (vaddr) { int hc = VTOB_HASH_CODE(vaddr);
vbp->next = mp->vtob[hc];
mp->vtob[hc] = vbp;
++mp->nump;
} return vaddr;
out_err: return NULL;
}
#ifdef SYM_MEM_FREE_UNUSED /* Free a memory cluster and associated resources for DMA */ staticvoid ___free_dma_mem_cluster(m_pool_p mp, void *m)
{
m_vtob_p *vbpp, vbp; int hc = VTOB_HASH_CODE(m);
/* Fetch the memory pool for a given pool id (i.e. DMA constraints) */ staticinline m_pool_p ___get_dma_pool(m_pool_ident_t dev_dmat)
{
m_pool_p mp; for (mp = mp0.next;
mp && !sym_m_pool_match(mp->dev_dmat, dev_dmat);
mp = mp->next); return mp;
}
spin_lock_irqsave(&sym53c8xx_lock, flags);
mp = ___get_dma_pool(dev_dmat); if (mp) {
vp = mp->vtob[hc]; while (vp && vp->vaddr != a)
vp = vp->next;
} if (!vp)
panic("sym: VTOBUS FAILED!\n");
b = vp->baddr + (m - a);
spin_unlock_irqrestore(&sym53c8xx_lock, flags); return b;
}
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.13Bemerkung:
(vorverarbeitet am 2026-09-27)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.