2 #include "../port/lib.h"
10 Hdrspc = 64, /* leave room for high-level headers */
11 Tlrspc = 16, /* extra room at the end for pad/crc/mac */
12 Bdead = 0x51494F42, /* "QIOB" */
22 size = ROUND(size, BLOCKALIGN);
23 if((b = mallocz(sizeof(Block)+BLOCKALIGN+Hdrspc+size, 0)) == nil)
31 /* align start of data portion by rounding up */
33 addr = ROUND(addr + sizeof(Block), BLOCKALIGN);
34 b->base = (uchar*)addr;
36 /* align end of data portion by rounding down */
37 b->lim = (uchar*)b + msize(b);
38 addr = (uintptr)b->lim;
39 addr &= ~(BLOCKALIGN-1);
40 b->lim = (uchar*)addr;
42 /* leave room at beginning for added headers */
43 b->wp = b->rp = b->lim - size;
54 * Check in a process and wait until successful.
57 panic("allocb without up: %#p", getcallerpc(&size));
58 while((b = _allocb(size)) == nil){
59 if(up->nlocks || m->ilockdepth || !islo()){
62 panic("allocb: no memory for %d bytes", size);
65 resrcwait("no memory for allocb");
69 setmalloctag(b, getcallerpc(&size));
79 if((b = _allocb(size)) == nil){
81 if((nerr++%10000)==0){
85 panic("iallocb: out of memory");
87 iprint("iallocb: no memory for %d bytes\n", size);
91 setmalloctag(b, getcallerpc(&size));
100 void *dead = (void*)Bdead;
106 * drivers which perform non cache coherent DMA manage their own buffer
107 * pool of uncached buffers and provide their own free routine.
114 /* poison the block in case someone is still holding onto it */
125 checkb(Block *b, char *msg)
127 void *dead = (void*)Bdead;
130 panic("checkb b %s %#p", msg, b);
131 if(b->base == dead || b->lim == dead || b->next == dead
132 || b->rp == dead || b->wp == dead){
133 print("checkb: base %#p lim %#p next %#p\n",
134 b->base, b->lim, b->next);
135 print("checkb: rp %#p wp %#p\n", b->rp, b->wp);
136 panic("checkb dead: %s", msg);
140 panic("checkb 0 %s %#p %#p", msg, b->base, b->lim);
142 panic("checkb 1 %s %#p %#p", msg, b->base, b->rp);
144 panic("checkb 2 %s %#p %#p", msg, b->base, b->wp);
146 panic("checkb 3 %s %#p %#p", msg, b->rp, b->lim);
148 panic("checkb 4 %s %#p %#p", msg, b->wp, b->lim);