ADR(9)                                                     ADR(9)

     NAME
          adr - physical address map

     SYNOPSIS
          cat '#P/adr'

          #include "adr.h"
          enum {
               Anone,
               Amemory,
               Areserved,
               Aacpireclaim,
               Aacpinvs,
               Aunusable,
               Adisable,

               Aapic,
               Apcibar,
               Ammio,
               Alast          = Ammio,
          };

          enum {
               Mfree,
               Mktext,
               Mkpage,
               Mupage,
               Mvmap,
               Mlast          = Mvmap,
          };

          uintmem   adralloc(uintmem base, uintmem len, int align,
                    int type, int use, uint flags)
          void  adrdump(void)
          void  adrinit(void)
          void  adrmapck(uintmem base, uintmem len,
                    int type, int use)
          int   adrmapenc(uintmem *base, uintmem *len,
                    int type, int use)
          void  adrmapinit(uintmem base, uintmem len,
                    int type, int use)
          uint  adrmemflags(uintmem pa)
          void  adrfree(uintmem base, uintmem len)
          uintmem   adrmemtype(uintmem pa, uintmem *len,
                    int *type, int *use)

     DESCRIPTION
          The physical address map is managed by adr. Map entries con-
          sist of a base, length address type (e.g. memory, mmio,
          etc.), current use and caching flags.  The map is

     Page 1                       Plan 9             (printed 4/26/24)

     ADR(9)                                                     ADR(9)

          initlialized from the *e820 configuration variable (see
          plan9.ini(8)), PCI mappings, ACPI and other memory-mapped
          devices such as I/O APICs and LAPICs.  Address ranges may be
          allocated by address type; adr splits address ranges as nec-
          essary.  Allocated maps are indicated by a non- Mfree value
          of use.  When maps are freed, they are merged with adjacent
          maps of the same address type.

          The functions for accessing maps are as follows

          adralloc(base, len, align, type, use, flags)
               Allocate from existing memory maps with the given
               alignment.  A matching map must exist and be free, but
               will be split to fit the allocation.  The memory type
               for the range is set to type.

          adrdump()
               Dump all maps to the console for debugging.  (See
               #P/adr.)

          adrinit()
               Set up the address map.  This is called early in main.

          adrmapinit(base, len, type, use)
               Enter a new physical mapping to be entered into the adr
               map.  The map must not overlap existing maps.

          adrmapck(base, len, type, use)
               Ensure that the given map exists and is the correct
               type.  Correct the map if necessary.  This is useful to
               work around machines that do not reserve memory for I/O
               APICs and such.

          adrfree(base, len)
               Delete the given mapping.

          adrmapenc(*base, *len, type, use)
               Find the enclosing map, and convert it to the type and
               use.  Return 0 if successful, and -1 otherwise.

          adrmemtype(pa, *len, *type, *use)
               Find the enclosing map, and return the base address.
               Also return the size, type, and use, if the correspond-
               ing pointers are not nil.

          adrmemflags(pa)
               Return the memory flags for the enclosing region.  This
               is used by vmap(9nix) to maintain consistent caching
               flags.

     SOURCE
          /sys/src/nix/k10/adr.c

     Page 2                       Plan 9             (printed 4/26/24)

     ADR(9)                                                     ADR(9)

     SEE ALSO
          plan9.ini(8), vmap(9nix).

     Page 3                       Plan 9             (printed 4/26/24)