2 * allocate Blocks from uncached memory
5 #include "../port/lib.h"
13 Hdrspc = 64, /* leave room for high-level headers */
14 Bdead = 0x51494F42, /* "QIOB" */
29 if((b = ucalloc(sizeof(Block)+size+Hdrspc)) == nil)
39 /* align start of data portion by rounding up */
41 addr = ROUND(addr + sizeof(Block), BLOCKALIGN);
42 b->base = (uchar*)addr;
44 /* align end of data portion by rounding down */
45 b->lim = ((uchar*)b) + msize(b);
46 addr = (ulong)(b->lim);
47 addr = addr & ~(BLOCKALIGN-1);
48 b->lim = (uchar*)addr;
50 /* leave sluff at beginning for added headers */
51 b->rp = b->lim - ROUND(size, BLOCKALIGN);
65 * Check in a process and wait until successful.
66 * Can still error out of here, though.
69 panic("ucallocb without up: %#p", getcallerpc(&size));
70 if((b = _ucallocb(size)) == nil)
71 panic("ucallocb: no memory for %d bytes", size);
72 setmalloctag(b, getcallerpc(&size));
81 static int m1, m2, mp;
83 if(0 && ucialloc.bytes > conf.ialloc){
89 iprint("uciallocb: limited %lud/%lud\n",
90 ucialloc.bytes, conf.ialloc);
95 if((b = _ucallocb(size)) == nil){
96 if(0 && (m2++%10000)==0){
101 iprint("uciallocb: no memory %lud/%lud\n",
102 ucialloc.bytes, conf.ialloc);
106 setmalloctag(b, getcallerpc(&size));
110 ucialloc.bytes += b->lim - b->base;
119 void *dead = (void*)Bdead;
122 if(b == nil || (ref = _xdec(&b->ref)) > 0)
127 panic("ucfreeb: ref %ld; caller pc %#p", ref, getcallerpc(&b));
131 * drivers which perform non cache coherent DMA manage their own buffer
132 * pool of uncached buffers and provide their own free routine.
138 if(b->flag & BINTR) {
140 ucialloc.bytes -= b->lim - b->base;
144 /* poison the block in case someone is still holding onto it */