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 if((b = mallocz(sizeof(Block)+size+Hdrspc, 0)) == nil)
30 /* align start of data portion by rounding up */
32 addr = ROUND(addr + sizeof(Block), BLOCKALIGN);
33 b->base = (uchar*)addr;
35 /* align end of data portion by rounding down */
36 b->lim = (uchar*)b + msize(b);
37 addr = (uintptr)b->lim;
38 addr &= ~(BLOCKALIGN-1);
39 b->lim = (uchar*)addr;
41 /* leave sluff at beginning for added headers */
42 b->rp = b->lim - ROUND(size, BLOCKALIGN);
56 * Check in a process and wait until successful.
59 panic("allocb without up: %#p", getcallerpc(&size));
60 while((b = _allocb(size)) == nil){
61 if(up->nlocks || m->ilockdepth || !islo()){
64 panic("allocb: no memory for %d bytes", size);
67 resrcwait("no memory for allocb");
71 setmalloctag(b, getcallerpc(&size));
81 if((b = _allocb(size)) == nil){
83 if((nerr++%10000)==0){
87 panic("iallocb: out of memory");
89 iprint("iallocb: no memory for %d bytes\n", size);
93 setmalloctag(b, getcallerpc(&size));
102 void *dead = (void*)Bdead;
108 * drivers which perform non cache coherent DMA manage their own buffer
109 * pool of uncached buffers and provide their own free routine.
116 /* poison the block in case someone is still holding onto it */
127 checkb(Block *b, char *msg)
129 void *dead = (void*)Bdead;
132 panic("checkb b %s %#p", msg, b);
133 if(b->base == dead || b->lim == dead || b->next == dead
134 || b->rp == dead || b->wp == dead){
135 print("checkb: base %#p lim %#p next %#p\n",
136 b->base, b->lim, b->next);
137 print("checkb: rp %#p wp %#p\n", b->rp, b->wp);
138 panic("checkb dead: %s", msg);
142 panic("checkb 0 %s %#p %#p", msg, b->base, b->lim);
144 panic("checkb 1 %s %#p %#p", msg, b->base, b->rp);
146 panic("checkb 2 %s %#p %#p", msg, b->base, b->wp);
148 panic("checkb 3 %s %#p %#p", msg, b->rp, b->lim);
150 panic("checkb 4 %s %#p %#p", msg, b->wp, b->lim);