ulong umbrwmalloc(ulong addr, int size, int align) { ulong a; uchar o[2], *p; if(a = mapalloc(&rmapumbrw, addr, size, align)) return(ulong)KADDR(a); /* * Perhaps the memory wasn't visible before * the interface is initialised, so try again. */ if((a = umbmalloc(addr, size, align)) == 0) return 0; p = (uchar*)a; o[0] = p[0]; p[0] = 0xCC; o[1] = p[size-1]; p[size-1] = 0xCC; if(p[0] == 0xCC && p[size-1] == 0xCC){ p[0] = o[0]; p[size-1] = o[1]; return a; } umbfree(a, size); return 0; }
uint32_t umbrwmalloc(uint32_t addr, int size, int align) { uint32_t a; uint8_t *p; if(a = mapalloc(&rmapumbrw, addr, size, align)) return(uint32_t)KADDR(a); /* * Perhaps the memory wasn't visible before * the interface is initialised, so try again. */ if((a = umbmalloc(addr, size, align)) == 0) return 0; p = (uint8_t*)a; p[0] = 0xCC; p[size-1] = 0xCC; if(p[0] == 0xCC && p[size-1] == 0xCC) return a; umbfree(a, size); return 0; }
/* * get a map for pc card region, return corrected len */ PCMmap* pcmmap(int slotno, ulong offset, int len, int attr) { PCMslot *pp; uchar we, bit; PCMmap *m, *nm; int i; ulong e; pp = slot + slotno; lock(&pp->mlock); /* convert offset to granularity */ if(len <= 0) len = 1; e = ROUND(offset+len, Mgran); offset &= Mmask; len = e - offset; /* look for a map that covers the right area */ we = rdreg(pp, Rwe); bit = 1; nm = 0; for(m = pp->mmap; m < &pp->mmap[nelem(pp->mmap)]; m++){ if((we & bit)) if(m->attr == attr) if(offset >= m->ca && e <= m->cea){ m->ref++; unlock(&pp->mlock); return m; } bit <<= 1; if(nm == 0 && m->ref == 0) nm = m; } m = nm; if(m == 0){ unlock(&pp->mlock); return 0; } /* if isa space isn't big enough, free it and get more */ if(m->len < len){ if(m->isa){ umbfree(m->isa, m->len); m->len = 0; } m->isa = PADDR(umbmalloc(0, len, Mgran)); if(m->isa == 0){ print("pcmmap: out of isa space\n"); unlock(&pp->mlock); return 0; } m->len = len; } /* set up new map */ m->ca = offset; m->cea = m->ca + m->len; m->attr = attr; i = m-pp->mmap; bit = 1<<i; wrreg(pp, Rwe, we & ~bit); /* disable map before changing it */ wrreg(pp, MAP(i, Mbtmlo), m->isa>>Mshift); wrreg(pp, MAP(i, Mbtmhi), (m->isa>>(Mshift+8)) | F16bit); wrreg(pp, MAP(i, Mtoplo), (m->isa+m->len-1)>>Mshift); wrreg(pp, MAP(i, Mtophi), ((m->isa+m->len-1)>>(Mshift+8))); offset -= m->isa; offset &= (1<<25)-1; offset >>= Mshift; wrreg(pp, MAP(i, Mofflo), offset); wrreg(pp, MAP(i, Moffhi), (offset>>8) | (attr ? Fregactive : 0)); wrreg(pp, Rwe, we | bit); /* enable map */ m->ref = 1; unlock(&pp->mlock); return m; }