2 #include "../port/lib.h"
10 Hdrspc = 64, /* leave room for high-level headers */
11 Bdead = 0x51494F42, /* "QIOB" */
26 if((b = mallocz(sizeof(Block)+size+Hdrspc, 0)) == nil)
36 /* align start of data portion by rounding up */
38 addr = ROUND(addr + sizeof(Block), BLOCKALIGN);
39 b->base = (uchar*)addr;
41 /* align end of data portion by rounding down */
42 b->lim = ((uchar*)b) + msize(b);
43 addr = (ulong)(b->lim);
44 addr = addr & ~(BLOCKALIGN-1);
45 b->lim = (uchar*)addr;
47 /* leave sluff at beginning for added headers */
48 b->rp = b->lim - ROUND(size, BLOCKALIGN);
62 * Check in a process and wait until successful.
63 * Can still error out of here, though.
66 panic("allocb without up: %#p", getcallerpc(&size));
67 if((b = _allocb(size)) == nil){
70 panic("allocb: no memory for %d bytes", size);
72 setmalloctag(b, getcallerpc(&size));
81 static int m1, m2, mp;
83 if(ialloc.bytes > conf.ialloc){
89 iprint("iallocb: limited %lud/%lud\n",
90 ialloc.bytes, conf.ialloc);
95 if((b = _allocb(size)) == nil){
101 iprint("iallocb: no memory %lud/%lud\n",
102 ialloc.bytes, conf.ialloc);
106 setmalloctag(b, getcallerpc(&size));
110 ialloc.bytes += b->lim - b->base;
119 void *dead = (void*)Bdead;
122 if(b == nil || (ref = _xdec(&b->ref)) > 0)
127 panic("freeb: 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 ialloc.bytes -= b->lim - b->base;
144 /* poison the block in case someone is still holding onto it */
155 checkb(Block *b, char *msg)
157 void *dead = (void*)Bdead;
160 panic("checkb b %s %#p", msg, b);
161 if(b->base == dead || b->lim == dead || b->next == dead
162 || b->rp == dead || b->wp == dead){
163 print("checkb: base %#p lim %#p next %#p\n",
164 b->base, b->lim, b->next);
165 print("checkb: rp %#p wp %#p\n", b->rp, b->wp);
166 panic("checkb dead: %s", msg);
170 panic("checkb 0 %s %#p %#p", msg, b->base, b->lim);
172 panic("checkb 1 %s %#p %#p", msg, b->base, b->rp);
174 panic("checkb 2 %s %#p %#p", msg, b->base, b->wp);
176 panic("checkb 3 %s %#p %#p", msg, b->rp, b->lim);
178 panic("checkb 4 %s %#p %#p", msg, b->wp, b->lim);
184 print("ialloc %lud/%lud\n", ialloc.bytes, conf.ialloc);