]> CyberLeo.Net >> Repos - FreeBSD/releng/8.0.git/blob - sys/arm/arm/vm_machdep.c
Adjust to reflect 8.0-RELEASE.
[FreeBSD/releng/8.0.git] / sys / arm / arm / vm_machdep.c
1 /*-
2  * Copyright (c) 1982, 1986 The Regents of the University of California.
3  * Copyright (c) 1989, 1990 William Jolitz
4  * Copyright (c) 1994 John Dyson
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * the Systems Programming Group of the University of Utah Computer
9  * Science Department, and William Jolitz.
10  *
11  * Redistribution and use in source and binary :forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *      This product includes software developed by the University of
22  *      California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  *      from: @(#)vm_machdep.c  7.3 (Berkeley) 5/13/91
40  *      Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
41  */
42
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD$");
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/malloc.h>
50 #include <sys/mbuf.h>
51 #include <sys/proc.h>
52 #include <sys/socketvar.h>
53 #include <sys/sf_buf.h>
54 #include <sys/unistd.h>
55 #include <machine/cpu.h>
56 #include <machine/pcb.h>
57 #include <machine/sysarch.h>
58 #include <sys/lock.h>
59 #include <sys/mutex.h>
60
61 #include <vm/vm.h>
62 #include <vm/pmap.h>
63 #include <vm/vm_extern.h>
64 #include <vm/vm_kern.h>
65 #include <vm/vm_page.h>
66 #include <vm/vm_map.h>
67 #include <vm/vm_param.h>
68 #include <vm/vm_pageout.h>
69 #include <vm/uma.h>
70 #include <vm/uma_int.h>
71
72 #include <machine/md_var.h>
73
74 #ifndef NSFBUFS
75 #define NSFBUFS         (512 + maxusers * 16)
76 #endif
77
78 #ifndef ARM_USE_SMALL_ALLOC
79 static void     sf_buf_init(void *arg);
80 SYSINIT(sock_sf, SI_SUB_MBUF, SI_ORDER_ANY, sf_buf_init, NULL);
81
82 LIST_HEAD(sf_head, sf_buf);
83         
84
85 /*
86  * A hash table of active sendfile(2) buffers
87  */
88 static struct sf_head *sf_buf_active;
89 static u_long sf_buf_hashmask;
90
91 #define SF_BUF_HASH(m)  (((m) - vm_page_array) & sf_buf_hashmask)
92
93 static TAILQ_HEAD(, sf_buf) sf_buf_freelist;
94 static u_int    sf_buf_alloc_want;
95
96 /*
97  * A lock used to synchronize access to the hash table and free list
98  */
99 static struct mtx sf_buf_lock;
100 #endif
101
102 /*
103  * Finish a fork operation, with process p2 nearly set up.
104  * Copy and update the pcb, set up the stack so that the child
105  * ready to run and return to user mode.
106  */
107 void
108 cpu_fork(register struct thread *td1, register struct proc *p2,
109     struct thread *td2, int flags)
110 {
111         struct pcb *pcb2;
112         struct trapframe *tf;
113         struct switchframe *sf;
114         struct mdproc *mdp2;
115
116         if ((flags & RFPROC) == 0)
117                 return;
118         pcb2 = (struct pcb *)(td2->td_kstack + td2->td_kstack_pages * PAGE_SIZE) - 1;
119 #ifdef __XSCALE__
120 #ifndef CPU_XSCALE_CORE3
121         pmap_use_minicache(td2->td_kstack, td2->td_kstack_pages * PAGE_SIZE);
122 #endif
123 #endif
124         td2->td_pcb = pcb2;
125         bcopy(td1->td_pcb, pcb2, sizeof(*pcb2));
126         mdp2 = &p2->p_md;
127         bcopy(&td1->td_proc->p_md, mdp2, sizeof(*mdp2));
128         pcb2->un_32.pcb32_und_sp = td2->td_kstack + USPACE_UNDEF_STACK_TOP;
129         pcb2->un_32.pcb32_sp = td2->td_kstack +
130             USPACE_SVC_STACK_TOP - sizeof(*pcb2);
131         pmap_activate(td2);
132         td2->td_frame = tf =
133             (struct trapframe *)pcb2->un_32.pcb32_sp - 1;
134         *tf = *td1->td_frame;
135         sf = (struct switchframe *)tf - 1;
136         sf->sf_r4 = (u_int)fork_return;
137         sf->sf_r5 = (u_int)td2;
138         sf->sf_pc = (u_int)fork_trampoline;
139         tf->tf_spsr &= ~PSR_C_bit;
140         tf->tf_r0 = 0;
141         tf->tf_r1 = 0;
142         pcb2->un_32.pcb32_sp = (u_int)sf;
143
144         /* Setup to release spin count in fork_exit(). */
145         td2->td_md.md_spinlock_count = 1;
146         td2->td_md.md_saved_cspr = 0;
147         td2->td_md.md_tp = *(uint32_t **)ARM_TP_ADDRESS;
148 }
149                                 
150 void
151 cpu_thread_swapin(struct thread *td)
152 {
153 }       
154
155 void    
156 cpu_thread_swapout(struct thread *td)
157 {       
158 }
159
160 /*
161  * Detatch mapped page and release resources back to the system.
162  */
163 void
164 sf_buf_free(struct sf_buf *sf)
165 {
166 #ifndef ARM_USE_SMALL_ALLOC
167          mtx_lock(&sf_buf_lock);
168          sf->ref_count--;
169          if (sf->ref_count == 0) {
170                  TAILQ_INSERT_TAIL(&sf_buf_freelist, sf, free_entry);
171                  nsfbufsused--;
172                  if (sf_buf_alloc_want > 0)
173                          wakeup_one(&sf_buf_freelist);
174          }
175          mtx_unlock(&sf_buf_lock);                               
176 #endif
177 }
178
179 #ifndef ARM_USE_SMALL_ALLOC
180 /*
181  * Allocate a pool of sf_bufs (sendfile(2) or "super-fast" if you prefer. :-))
182  */
183 static void
184 sf_buf_init(void *arg)
185 {       
186         struct sf_buf *sf_bufs;
187         vm_offset_t sf_base;
188         int i;
189                                         
190         nsfbufs = NSFBUFS;
191         TUNABLE_INT_FETCH("kern.ipc.nsfbufs", &nsfbufs);
192                 
193         sf_buf_active = hashinit(nsfbufs, M_TEMP, &sf_buf_hashmask);
194         TAILQ_INIT(&sf_buf_freelist);
195         sf_base = kmem_alloc_nofault(kernel_map, nsfbufs * PAGE_SIZE);
196         sf_bufs = malloc(nsfbufs * sizeof(struct sf_buf), M_TEMP,
197             M_NOWAIT | M_ZERO);
198         for (i = 0; i < nsfbufs; i++) {
199                 sf_bufs[i].kva = sf_base + i * PAGE_SIZE;
200                 TAILQ_INSERT_TAIL(&sf_buf_freelist, &sf_bufs[i], free_entry);
201         }
202         sf_buf_alloc_want = 0; 
203         mtx_init(&sf_buf_lock, "sf_buf", NULL, MTX_DEF);
204 }
205 #endif
206
207 /*
208  * Get an sf_buf from the freelist. Will block if none are available.
209  */
210 struct sf_buf *
211 sf_buf_alloc(struct vm_page *m, int flags)
212 {
213 #ifdef ARM_USE_SMALL_ALLOC
214         return ((struct sf_buf *)m);
215 #else
216         struct sf_head *hash_list;
217         struct sf_buf *sf;
218         int error;
219
220         hash_list = &sf_buf_active[SF_BUF_HASH(m)];
221         mtx_lock(&sf_buf_lock);
222         LIST_FOREACH(sf, hash_list, list_entry) {
223                 if (sf->m == m) {
224                         sf->ref_count++;
225                         if (sf->ref_count == 1) {
226                                 TAILQ_REMOVE(&sf_buf_freelist, sf, free_entry);
227                                 nsfbufsused++;
228                                 nsfbufspeak = imax(nsfbufspeak, nsfbufsused);
229                         }
230                         goto done;
231                 }
232         }
233         while ((sf = TAILQ_FIRST(&sf_buf_freelist)) == NULL) {
234                 if (flags & SFB_NOWAIT)
235                         goto done;
236                 sf_buf_alloc_want++;
237                 mbstat.sf_allocwait++;
238                 error = msleep(&sf_buf_freelist, &sf_buf_lock,
239                     (flags & SFB_CATCH) ? PCATCH | PVM : PVM, "sfbufa", 0);
240                 sf_buf_alloc_want--;
241         
242
243                 /*
244                  * If we got a signal, don't risk going back to sleep. 
245                  */
246                 if (error)
247                         goto done;
248         }
249         TAILQ_REMOVE(&sf_buf_freelist, sf, free_entry);
250         if (sf->m != NULL)
251                 LIST_REMOVE(sf, list_entry);
252         LIST_INSERT_HEAD(hash_list, sf, list_entry);
253         sf->ref_count = 1;
254         sf->m = m;
255         nsfbufsused++;
256         nsfbufspeak = imax(nsfbufspeak, nsfbufsused);
257         pmap_kenter(sf->kva, VM_PAGE_TO_PHYS(sf->m));
258 done:
259         mtx_unlock(&sf_buf_lock);
260         return (sf);
261 #endif
262 }
263
264 /*
265  * Initialize machine state (pcb and trap frame) for a new thread about to
266  * upcall. Put enough state in the new thread's PCB to get it to go back 
267  * userret(), where we can intercept it again to set the return (upcall)
268  * Address and stack, along with those from upcals that are from other sources
269  * such as those generated in thread_userret() itself.
270  */
271 void
272 cpu_set_upcall(struct thread *td, struct thread *td0)
273 {
274         struct trapframe *tf;
275         struct switchframe *sf;
276
277         bcopy(td0->td_frame, td->td_frame, sizeof(struct trapframe));
278         bcopy(td0->td_pcb, td->td_pcb, sizeof(struct pcb));
279         tf = td->td_frame;
280         sf = (struct switchframe *)tf - 1;
281         sf->sf_r4 = (u_int)fork_return;
282         sf->sf_r5 = (u_int)td;
283         sf->sf_pc = (u_int)fork_trampoline;
284         tf->tf_spsr &= ~PSR_C_bit;
285         tf->tf_r0 = 0;
286         td->td_pcb->un_32.pcb32_sp = (u_int)sf;
287         td->td_pcb->un_32.pcb32_und_sp = td->td_kstack + USPACE_UNDEF_STACK_TOP;
288
289         /* Setup to release spin count in fork_exit(). */
290         td->td_md.md_spinlock_count = 1;
291         td->td_md.md_saved_cspr = 0;
292 }
293
294 /*
295  * Set that machine state for performing an upcall that has to
296  * be done in thread_userret() so that those upcalls generated
297  * in thread_userret() itself can be done as well.
298  */
299 void
300 cpu_set_upcall_kse(struct thread *td, void (*entry)(void *), void *arg,
301         stack_t *stack)
302 {
303         struct trapframe *tf = td->td_frame;
304
305         tf->tf_usr_sp = ((int)stack->ss_sp + stack->ss_size
306             - sizeof(struct trapframe)) & ~7;
307         tf->tf_pc = (int)entry;
308         tf->tf_r0 = (int)arg;
309         tf->tf_spsr = PSR_USR32_MODE;
310 }
311
312 int
313 cpu_set_user_tls(struct thread *td, void *tls_base)
314 {
315
316         if (td != curthread)
317                 td->td_md.md_tp = tls_base;
318         else {
319                 critical_enter();
320                 *(void **)ARM_TP_ADDRESS = tls_base;
321                 critical_exit();
322         }
323         return (0);
324 }
325
326 void
327 cpu_thread_exit(struct thread *td)
328 {
329 }
330
331 void
332 cpu_thread_alloc(struct thread *td)
333 {
334         td->td_pcb = (struct pcb *)(td->td_kstack + td->td_kstack_pages * 
335             PAGE_SIZE) - 1;
336         td->td_frame = (struct trapframe *)
337             ((u_int)td->td_kstack + USPACE_SVC_STACK_TOP - sizeof(struct pcb)) - 1;
338 #ifdef __XSCALE__
339 #ifndef CPU_XSCALE_CORE3
340         pmap_use_minicache(td->td_kstack, td->td_kstack_pages * PAGE_SIZE);
341 #endif
342 #endif  
343 }
344
345 void
346 cpu_thread_free(struct thread *td)
347 {
348 }
349
350 void
351 cpu_thread_clean(struct thread *td)
352 {
353 }
354
355 /*
356  * Intercept the return address from a freshly forked process that has NOT
357  * been scheduled yet.
358  *
359  * This is needed to make kernel threads stay in kernel mode.
360  */
361 void
362 cpu_set_fork_handler(struct thread *td, void (*func)(void *), void *arg)
363 {
364         struct switchframe *sf;
365         struct trapframe *tf;
366         
367         tf = td->td_frame;
368         sf = (struct switchframe *)tf - 1;
369         sf->sf_r4 = (u_int)func;
370         sf->sf_r5 = (u_int)arg;
371         td->td_pcb->un_32.pcb32_sp = (u_int)sf;
372 }
373
374 /*
375  * Software interrupt handler for queued VM system processing.
376  */   
377 void  
378 swi_vm(void *dummy)
379 {
380         
381         if (busdma_swi_pending)
382                 busdma_swi();
383 }
384
385 void
386 cpu_exit(struct thread *td)
387 {
388 }
389
390 #define BITS_PER_INT    (8 * sizeof(int))
391 vm_offset_t arm_nocache_startaddr;
392 static int arm_nocache_allocated[ARM_NOCACHE_KVA_SIZE / (PAGE_SIZE * 
393     BITS_PER_INT)];
394
395 /*
396  * Functions to map and unmap memory non-cached into KVA the kernel won't try 
397  * to allocate. The goal is to provide uncached memory to busdma, to honor
398  * BUS_DMA_COHERENT. 
399  * We can allocate at most ARM_NOCACHE_KVA_SIZE bytes. 
400  * The allocator is rather dummy, each page is represented by a bit in
401  * a bitfield, 0 meaning the page is not allocated, 1 meaning it is.
402  * As soon as it finds enough contiguous pages to satisfy the request,
403  * it returns the address.
404  */
405 void *
406 arm_remap_nocache(void *addr, vm_size_t size)
407 {
408         int i, j;
409
410         size = round_page(size);
411         for (i = 0; i < ARM_NOCACHE_KVA_SIZE / PAGE_SIZE; i++) {
412                 if (!(arm_nocache_allocated[i / BITS_PER_INT] & (1 << (i % 
413                     BITS_PER_INT)))) {
414                         for (j = i; j < i + (size / (PAGE_SIZE)); j++)
415                                 if (arm_nocache_allocated[j / BITS_PER_INT] &
416                                     (1 << (j % BITS_PER_INT)))
417                                         break;
418                         if (j == i + (size / (PAGE_SIZE)))
419                                 break;
420                 }
421         }
422         if (i < ARM_NOCACHE_KVA_SIZE / PAGE_SIZE) {
423                 vm_offset_t tomap = arm_nocache_startaddr + i * PAGE_SIZE;
424                 void *ret = (void *)tomap;
425                 vm_paddr_t physaddr = vtophys((vm_offset_t)addr);
426                 vm_offset_t vaddr = (vm_offset_t) addr;
427                 
428                 vaddr = vaddr & ~PAGE_MASK;
429                 for (; tomap < (vm_offset_t)ret + size; tomap += PAGE_SIZE,
430                     vaddr += PAGE_SIZE, physaddr += PAGE_SIZE, i++) {
431                         cpu_idcache_wbinv_range(vaddr, PAGE_SIZE);
432                         cpu_l2cache_wbinv_range(vaddr, PAGE_SIZE);
433                         pmap_kenter_nocache(tomap, physaddr);
434                         cpu_tlb_flushID_SE(vaddr);
435                         arm_nocache_allocated[i / BITS_PER_INT] |= 1 << (i % 
436                             BITS_PER_INT);
437                 }
438                 return (ret);
439         }
440
441         return (NULL);
442 }
443
444 void
445 arm_unmap_nocache(void *addr, vm_size_t size)
446 {
447         vm_offset_t raddr = (vm_offset_t)addr;
448         int i;
449
450         size = round_page(size);
451         i = (raddr - arm_nocache_startaddr) / (PAGE_SIZE);
452         for (; size > 0; size -= PAGE_SIZE, i++)
453                 arm_nocache_allocated[i / BITS_PER_INT] &= ~(1 << (i % 
454                     BITS_PER_INT));
455 }
456
457 #ifdef ARM_USE_SMALL_ALLOC
458
459 static TAILQ_HEAD(,arm_small_page) pages_normal = 
460         TAILQ_HEAD_INITIALIZER(pages_normal);
461 static TAILQ_HEAD(,arm_small_page) pages_wt = 
462         TAILQ_HEAD_INITIALIZER(pages_wt);
463 static TAILQ_HEAD(,arm_small_page) free_pgdesc =
464         TAILQ_HEAD_INITIALIZER(free_pgdesc);
465
466 extern uma_zone_t l2zone;
467
468 struct mtx smallalloc_mtx;
469
470 MALLOC_DEFINE(M_VMSMALLALLOC, "vm_small_alloc", "VM Small alloc data");
471
472 vm_offset_t alloc_firstaddr;
473
474 #ifdef ARM_HAVE_SUPERSECTIONS
475 #define S_FRAME L1_SUP_FRAME
476 #define S_SIZE  L1_SUP_SIZE
477 #else
478 #define S_FRAME L1_S_FRAME
479 #define S_SIZE  L1_S_SIZE
480 #endif
481
482 vm_offset_t
483 arm_ptovirt(vm_paddr_t pa)
484 {
485         int i;
486         vm_offset_t addr = alloc_firstaddr;
487
488         KASSERT(alloc_firstaddr != 0, ("arm_ptovirt called too early ?"));
489         for (i = 0; dump_avail[i + 1]; i += 2) {
490                 if (pa >= dump_avail[i] && pa < dump_avail[i + 1])
491                         break;
492                 addr += (dump_avail[i + 1] & S_FRAME) + S_SIZE -
493                     (dump_avail[i] & S_FRAME);
494         }
495         KASSERT(dump_avail[i + 1] != 0, ("Trying to access invalid physical address"));
496         return (addr + (pa - (dump_avail[i] & S_FRAME)));
497 }
498
499 void
500 arm_init_smallalloc(void)
501 {
502         vm_offset_t to_map = 0, mapaddr;
503         int i;
504         
505         /* 
506          * We need to use dump_avail and not phys_avail, since we want to
507          * map the whole memory and not just the memory available to the VM
508          * to be able to do a pa => va association for any address.
509          */
510            
511         for (i = 0; dump_avail[i + 1]; i+= 2) {
512                 to_map += (dump_avail[i + 1] & S_FRAME) + S_SIZE -
513                     (dump_avail[i] & S_FRAME);
514         }
515         alloc_firstaddr = mapaddr = KERNBASE - to_map;
516         for (i = 0; dump_avail[i + 1]; i+= 2) {
517                 vm_offset_t size = (dump_avail[i + 1] & S_FRAME) +
518                     S_SIZE - (dump_avail[i] & S_FRAME);
519                 vm_offset_t did = 0;
520                 while (size > 0) {
521 #ifdef ARM_HAVE_SUPERSECTIONS
522                         pmap_kenter_supersection(mapaddr,
523                             (dump_avail[i] & L1_SUP_FRAME) + did, 
524                             SECTION_CACHE);
525 #else
526                         pmap_kenter_section(mapaddr, 
527                             (dump_avail[i] & L1_S_FRAME) + did, SECTION_CACHE);
528 #endif
529                         mapaddr += S_SIZE;
530                         did += S_SIZE;
531                         size -= S_SIZE;
532                 }
533         }
534 }
535
536 void
537 arm_add_smallalloc_pages(void *list, void *mem, int bytes, int pagetable)
538 {
539         struct arm_small_page *pg;
540         
541         bytes &= ~PAGE_MASK;
542         while (bytes > 0) {
543                 pg = (struct arm_small_page *)list;
544                 pg->addr = mem;
545                 if (pagetable)
546                         TAILQ_INSERT_HEAD(&pages_wt, pg, pg_list);
547                 else
548                         TAILQ_INSERT_HEAD(&pages_normal, pg, pg_list);
549                 list = (char *)list + sizeof(*pg);
550                 mem = (char *)mem + PAGE_SIZE;
551                 bytes -= PAGE_SIZE;
552         }
553 }
554
555 void *
556 uma_small_alloc(uma_zone_t zone, int bytes, u_int8_t *flags, int wait)
557 {
558         void *ret;
559         struct arm_small_page *sp;
560         TAILQ_HEAD(,arm_small_page) *head;
561         static vm_pindex_t color;
562         vm_page_t m;
563
564         *flags = UMA_SLAB_PRIV;
565         /*
566          * For CPUs where we setup page tables as write back, there's no
567          * need to maintain two separate pools.
568          */
569         if (zone == l2zone && pte_l1_s_cache_mode != pte_l1_s_cache_mode_pt)
570                 head = (void *)&pages_wt;
571         else
572                 head = (void *)&pages_normal;
573
574         mtx_lock(&smallalloc_mtx);
575         sp = TAILQ_FIRST(head);
576
577         if (!sp) {
578                 int pflags;
579
580                 mtx_unlock(&smallalloc_mtx);
581                 if (zone == l2zone &&
582                     pte_l1_s_cache_mode != pte_l1_s_cache_mode_pt) {
583                         *flags = UMA_SLAB_KMEM;
584                         ret = ((void *)kmem_malloc(kmem_map, bytes, M_NOWAIT));
585                         return (ret);
586                 }
587                 if ((wait & (M_NOWAIT|M_USE_RESERVE)) == M_NOWAIT)
588                         pflags = VM_ALLOC_INTERRUPT | VM_ALLOC_WIRED;
589                 else
590                         pflags = VM_ALLOC_SYSTEM | VM_ALLOC_WIRED;
591                 if (wait & M_ZERO)
592                         pflags |= VM_ALLOC_ZERO;
593                 for (;;) {
594                         m = vm_page_alloc(NULL, color++, 
595                             pflags | VM_ALLOC_NOOBJ);
596                         if (m == NULL) {
597                                 if (wait & M_NOWAIT)
598                                         return (NULL);
599                                 VM_WAIT;
600                         } else
601                                 break;
602                 }
603                 ret = (void *)arm_ptovirt(VM_PAGE_TO_PHYS(m));
604                 if ((wait & M_ZERO) && (m->flags & PG_ZERO) == 0)
605                         bzero(ret, PAGE_SIZE);
606                 return (ret);
607         }    
608         TAILQ_REMOVE(head, sp, pg_list);
609         TAILQ_INSERT_HEAD(&free_pgdesc, sp, pg_list);
610         ret = sp->addr;
611         mtx_unlock(&smallalloc_mtx);
612         if ((wait & M_ZERO))
613                 bzero(ret, bytes);
614         return (ret);
615 }
616
617 void
618 uma_small_free(void *mem, int size, u_int8_t flags)
619 {
620         pd_entry_t *pd;
621         pt_entry_t *pt;
622
623         if (flags & UMA_SLAB_KMEM)
624                 kmem_free(kmem_map, (vm_offset_t)mem, size);
625         else {
626                 struct arm_small_page *sp;
627
628                 if ((vm_offset_t)mem >= KERNBASE) {
629                         mtx_lock(&smallalloc_mtx);
630                         sp = TAILQ_FIRST(&free_pgdesc);
631                         KASSERT(sp != NULL, ("No more free page descriptor ?"));
632                         TAILQ_REMOVE(&free_pgdesc, sp, pg_list);
633                         sp->addr = mem;
634                         pmap_get_pde_pte(kernel_pmap, (vm_offset_t)mem, &pd,
635                             &pt);
636                         if ((*pd & pte_l1_s_cache_mask) == 
637                             pte_l1_s_cache_mode_pt &&
638                             pte_l1_s_cache_mode_pt != pte_l1_s_cache_mode)
639                                 TAILQ_INSERT_HEAD(&pages_wt, sp, pg_list);
640                         else
641                                 TAILQ_INSERT_HEAD(&pages_normal, sp, pg_list);
642                         mtx_unlock(&smallalloc_mtx);
643                 } else {
644                         vm_page_t m;
645                         vm_paddr_t pa = vtophys((vm_offset_t)mem);
646
647                         m = PHYS_TO_VM_PAGE(pa);
648                         m->wire_count--;
649                         vm_page_free(m);
650                         atomic_subtract_int(&cnt.v_wire_count, 1);
651                 }
652         }
653 }
654
655 #endif