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)
34 /* align start of data portion by rounding up */
36 addr = ROUND(addr + sizeof(Block), BLOCKALIGN);
37 b->base = (uchar*)addr;
39 /* align end of data portion by rounding down */
40 b->lim = (uchar*)b + msize(b);
41 addr = (uintptr)b->lim;
42 addr &= ~(BLOCKALIGN-1);
43 b->lim = (uchar*)addr;
45 /* leave sluff at beginning for added headers */
46 b->rp = b->lim - ROUND(size, BLOCKALIGN);
60 * Check in a process and wait until successful.
61 * Can still error out of here, though.
64 panic("allocb without up: %#p", getcallerpc(&size));
65 while((b = _allocb(size)) == nil){
66 if(up->nlocks || m->ilockdepth || !islo()){
69 panic("allocb: no memory for %d bytes", size);
72 resrcwait("no memory for allocb");
76 setmalloctag(b, getcallerpc(&size));
85 static int m1, m2, mp;
87 if(ialloc.bytes > conf.ialloc){
93 iprint("iallocb: limited %lud/%lud\n",
94 ialloc.bytes, conf.ialloc);
99 if((b = _allocb(size)) == nil){
105 iprint("iallocb: no memory %lud/%lud\n",
106 ialloc.bytes, conf.ialloc);
110 setmalloctag(b, getcallerpc(&size));
114 ialloc.bytes += b->lim - b->base;
123 void *dead = (void*)Bdead;
129 * drivers which perform non cache coherent DMA manage their own buffer
130 * pool of uncached buffers and provide their own free routine.
136 if(b->flag & BINTR) {
138 ialloc.bytes -= b->lim - b->base;
142 /* poison the block in case someone is still holding onto it */
153 checkb(Block *b, char *msg)
155 void *dead = (void*)Bdead;
158 panic("checkb b %s %#p", msg, b);
159 if(b->base == dead || b->lim == dead || b->next == dead
160 || b->rp == dead || b->wp == dead){
161 print("checkb: base %#p lim %#p next %#p\n",
162 b->base, b->lim, b->next);
163 print("checkb: rp %#p wp %#p\n", b->rp, b->wp);
164 panic("checkb dead: %s", msg);
168 panic("checkb 0 %s %#p %#p", msg, b->base, b->lim);
170 panic("checkb 1 %s %#p %#p", msg, b->base, b->rp);
172 panic("checkb 2 %s %#p %#p", msg, b->base, b->wp);
174 panic("checkb 3 %s %#p %#p", msg, b->rp, b->lim);
176 panic("checkb 4 %s %#p %#p", msg, b->wp, b->lim);
182 print("ialloc %lud/%lud\n", ialloc.bytes, conf.ialloc);