1 /*- 2 * Copyright (c) 2001 Benno Rice 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #include <sys/cdefs.h> 28 #include <sys/param.h> 29 #include <sys/types.h> 30 31 #include <stand.h> 32 33 #include "libofw.h" 34 #include "openfirm.h" 35 36 struct ofw_mapping { 37 vm_offset_t va; 38 int len; 39 vm_offset_t pa; 40 int mode; 41 }; 42 43 struct ofw_mapping2 { 44 vm_offset_t va; 45 int len; 46 vm_offset_t pa_hi; 47 vm_offset_t pa_lo; 48 int mode; 49 }; 50 51 void 52 ofw_memmap(int acells) 53 { 54 struct ofw_mapping *mapptr; 55 struct ofw_mapping2 *mapptr2; 56 phandle_t mmup; 57 int nmapping, i; 58 u_char mappings[256 * sizeof(struct ofw_mapping2)]; 59 char lbuf[80]; 60 61 mmup = OF_instance_to_package(mmu); 62 63 bzero(mappings, sizeof(mappings)); 64 65 nmapping = OF_getprop(mmup, "translations", mappings, sizeof(mappings)); 66 if (nmapping == -1) { 67 printf("Could not get memory map (%d)\n", 68 nmapping); 69 return; 70 } 71 72 pager_open(); 73 if (acells == 1) { 74 nmapping /= sizeof(struct ofw_mapping); 75 mapptr = (struct ofw_mapping *) mappings; 76 77 printf("%17s\t%17s\t%8s\t%6s\n", "Virtual Range", 78 "Physical Range", "#Pages", "Mode"); 79 80 for (i = 0; i < nmapping; i++) { 81 sprintf(lbuf, "%08jx-%08jx\t%08jx-%08jx\t%8d\t%6x\n", 82 (uintmax_t)mapptr[i].va, 83 (uintmax_t)mapptr[i].va + mapptr[i].len, 84 (uintmax_t)mapptr[i].pa, 85 (uintmax_t)mapptr[i].pa + mapptr[i].len, 86 mapptr[i].len / 0x1000, 87 mapptr[i].mode); 88 if (pager_output(lbuf)) 89 break; 90 } 91 } else { 92 nmapping /= sizeof(struct ofw_mapping2); 93 mapptr2 = (struct ofw_mapping2 *) mappings; 94 95 printf("%17s\t%17s\t%8s\t%6s\n", "Virtual Range", 96 "Physical Range", "#Pages", "Mode"); 97 98 for (i = 0; i < nmapping; i++) { 99 sprintf(lbuf, "%08jx-%08jx\t%08jx-%08jx\t%8d\t%6x\n", 100 (uintmax_t)mapptr2[i].va, 101 (uintmax_t)mapptr2[i].va + mapptr2[i].len, 102 (uintmax_t)mapptr2[i].pa_lo, 103 (uintmax_t)mapptr2[i].pa_lo + mapptr2[i].len, 104 mapptr2[i].len / 0x1000, 105 mapptr2[i].mode); 106 if (pager_output(lbuf)) 107 break; 108 } 109 } 110 pager_close(); 111 } 112 113