···11-/* $Id: memory.c,v 1.5 1999/08/31 06:55:04 davem Exp $22- * memory.c: Prom routine for acquiring various bits of information33- * about RAM on the machine, both virtual and physical.44- *55- * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)66- * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)77- */88-99-#include <linux/kernel.h>1010-#include <linux/init.h>1111-1212-#include <asm/openprom.h>1313-#include <asm/oplib.h>1414-1515-/* This routine, for consistency, returns the ram parameters in the1616- * V0 prom memory descriptor format. I choose this format because I1717- * think it was the easiest to work with. I feel the religious1818- * arguments now... ;) Also, I return the linked lists sorted to1919- * prevent paging_init() upset stomach as I have not yet written2020- * the pepto-bismol kernel module yet.2121- */2222-2323-struct linux_prom64_registers prom_reg_memlist[64];2424-struct linux_prom64_registers prom_reg_tmp[64];2525-2626-struct linux_mlist_p1275 prom_phys_total[64];2727-struct linux_mlist_p1275 prom_prom_taken[64];2828-struct linux_mlist_p1275 prom_phys_avail[64];2929-3030-struct linux_mlist_p1275 *prom_ptot_ptr = prom_phys_total;3131-struct linux_mlist_p1275 *prom_ptak_ptr = prom_prom_taken;3232-struct linux_mlist_p1275 *prom_pavl_ptr = prom_phys_avail;3333-3434-struct linux_mem_p1275 prom_memlist;3535-3636-3737-/* Internal Prom library routine to sort a linux_mlist_p1275 memory3838- * list. Used below in initialization.3939- */4040-static void __init4141-prom_sortmemlist(struct linux_mlist_p1275 *thislist)4242-{4343- int swapi = 0;4444- int i, mitr;4545- unsigned long tmpaddr, tmpsize;4646- unsigned long lowest;4747-4848- for(i=0; thislist[i].theres_more; i++) {4949- lowest = thislist[i].start_adr;5050- for(mitr = i+1; thislist[mitr-1].theres_more; mitr++)5151- if(thislist[mitr].start_adr < lowest) {5252- lowest = thislist[mitr].start_adr;5353- swapi = mitr;5454- }5555- if(lowest == thislist[i].start_adr) continue;5656- tmpaddr = thislist[swapi].start_adr;5757- tmpsize = thislist[swapi].num_bytes;5858- for(mitr = swapi; mitr > i; mitr--) {5959- thislist[mitr].start_adr = thislist[mitr-1].start_adr;6060- thislist[mitr].num_bytes = thislist[mitr-1].num_bytes;6161- }6262- thislist[i].start_adr = tmpaddr;6363- thislist[i].num_bytes = tmpsize;6464- }6565-}6666-6767-/* Initialize the memory lists based upon the prom version. */6868-void __init prom_meminit(void)6969-{7070- int node = 0;7171- unsigned int iter, num_regs;7272-7373- node = prom_finddevice("/memory");7474- num_regs = prom_getproperty(node, "available",7575- (char *) prom_reg_memlist,7676- sizeof(prom_reg_memlist));7777- num_regs = (num_regs/sizeof(struct linux_prom64_registers));7878- for(iter=0; iter<num_regs; iter++) {7979- prom_phys_avail[iter].start_adr =8080- prom_reg_memlist[iter].phys_addr;8181- prom_phys_avail[iter].num_bytes =8282- prom_reg_memlist[iter].reg_size;8383- prom_phys_avail[iter].theres_more =8484- &prom_phys_avail[iter+1];8585- }8686- prom_phys_avail[iter-1].theres_more = NULL;8787-8888- num_regs = prom_getproperty(node, "reg",8989- (char *) prom_reg_memlist,9090- sizeof(prom_reg_memlist));9191- num_regs = (num_regs/sizeof(struct linux_prom64_registers));9292- for(iter=0; iter<num_regs; iter++) {9393- prom_phys_total[iter].start_adr =9494- prom_reg_memlist[iter].phys_addr;9595- prom_phys_total[iter].num_bytes =9696- prom_reg_memlist[iter].reg_size;9797- prom_phys_total[iter].theres_more =9898- &prom_phys_total[iter+1];9999- }100100- prom_phys_total[iter-1].theres_more = NULL;101101-102102- node = prom_finddevice("/virtual-memory");103103- num_regs = prom_getproperty(node, "available",104104- (char *) prom_reg_memlist,105105- sizeof(prom_reg_memlist));106106- num_regs = (num_regs/sizeof(struct linux_prom64_registers));107107-108108- /* Convert available virtual areas to taken virtual109109- * areas. First sort, then convert.110110- */111111- for(iter=0; iter<num_regs; iter++) {112112- prom_prom_taken[iter].start_adr =113113- prom_reg_memlist[iter].phys_addr;114114- prom_prom_taken[iter].num_bytes =115115- prom_reg_memlist[iter].reg_size;116116- prom_prom_taken[iter].theres_more =117117- &prom_prom_taken[iter+1];118118- }119119- prom_prom_taken[iter-1].theres_more = NULL;120120-121121- prom_sortmemlist(prom_prom_taken);122122-123123- /* Finally, convert. */124124- for(iter=0; iter<num_regs; iter++) {125125- prom_prom_taken[iter].start_adr =126126- prom_prom_taken[iter].start_adr +127127- prom_prom_taken[iter].num_bytes;128128- prom_prom_taken[iter].num_bytes =129129- prom_prom_taken[iter+1].start_adr -130130- prom_prom_taken[iter].start_adr;131131- }132132- prom_prom_taken[iter-1].num_bytes =133133- -1UL - prom_prom_taken[iter-1].start_adr;134134-135135- /* Sort the other two lists. */136136- prom_sortmemlist(prom_phys_total);137137- prom_sortmemlist(prom_phys_avail);138138-139139- /* Link all the lists into the top-level descriptor. */140140- prom_memlist.p1275_totphys=&prom_ptot_ptr;141141- prom_memlist.p1275_prommap=&prom_ptak_ptr;142142- prom_memlist.p1275_available=&prom_pavl_ptr;143143-}144144-145145-/* This returns a pointer to our libraries internal p1275 format146146- * memory descriptor.147147- */148148-struct linux_mem_p1275 *149149-prom_meminfo(void)150150-{151151- return &prom_memlist;152152-}
-14
include/asm-sparc64/oplib.h
···9595extern void prom_seek(int device_handle, unsigned int seek_hival,9696 unsigned int seek_lowval);97979898-/* Machine memory configuration routine. */9999-100100-/* This function returns a V0 format memory descriptor table, it has three101101- * entries. One for the total amount of physical ram on the machine, one102102- * for the amount of physical ram available, and one describing the virtual103103- * areas which are allocated by the prom. So, in a sense the physical104104- * available is a calculation of the total physical minus the physical mapped105105- * by the prom with virtual mappings.106106- *107107- * These lists are returned pre-sorted, this should make your life easier108108- * since the prom itself is way too lazy to do such nice things.109109- */110110-extern struct linux_mem_p1275 *prom_meminfo(void);111111-11298/* Miscellaneous routines, don't really fit in any category per se. */11399114100/* Reboot the machine with the command line passed. */