Author: marcel
Date: Sat Jul 16 19:56:07 2011
New Revision: 224112
URL: http://svn.freebsd.org/changeset/base/224112

Log:
  Add a few more helper functions for working with memory descriptors:
  o   efi_md_find() - returns the md that covers the given address
  o   efi_md_last() - returns the last md in the list
  o   efi_md_prev() - returns the md that preceeds the given md.

Modified:
  head/sys/ia64/ia64/efi.c
  head/sys/ia64/include/efi.h

Modified: head/sys/ia64/ia64/efi.c
==============================================================================
--- head/sys/ia64/ia64/efi.c    Sat Jul 16 19:38:08 2011        (r224111)
+++ head/sys/ia64/ia64/efi.c    Sat Jul 16 19:56:07 2011        (r224112)
@@ -161,20 +161,67 @@ efi_get_time(struct efi_tm *tm)
 struct efi_md *
 efi_md_first(void)
 {
+       struct efi_md *md;
 
        if (bootinfo->bi_memmap == 0)
                return (NULL);
-       return ((struct efi_md *)bootinfo->bi_memmap);
+       md = (struct efi_md *)bootinfo->bi_memmap;
+       return (md);
+}
+
+struct efi_md *
+efi_md_last(void)
+{
+       struct efi_md *md;
+
+       if (bootinfo->bi_memmap == 0)
+               return (NULL);
+       md = (struct efi_md *)(bootinfo->bi_memmap + bootinfo->bi_memmap_size -
+           bootinfo->bi_memdesc_size);
+       return (md);
 }
 
 struct efi_md *
 efi_md_next(struct efi_md *md)
 {
-       uint64_t plim;
+       struct efi_md *lim;
 
-       plim = bootinfo->bi_memmap + bootinfo->bi_memmap_size;
+       lim = efi_md_last();
        md = (struct efi_md *)((uintptr_t)md + bootinfo->bi_memdesc_size);
-       return ((md >= (struct efi_md *)plim) ? NULL : md);
+       return ((md > lim) ? NULL : md);
+}
+
+struct efi_md *
+efi_md_prev(struct efi_md *md)
+{
+       struct efi_md *lim;
+
+       lim = efi_md_first();
+       md = (struct efi_md *)((uintptr_t)md - bootinfo->bi_memdesc_size);
+       return ((md < lim) ? NULL : md);
+}
+
+struct efi_md *
+efi_md_find(vm_paddr_t pa)
+{
+       static struct efi_md *last = NULL;
+       struct efi_md *md, *p0, *p1;
+
+       md = (last != NULL) ? last : efi_md_first();
+       p1 = p0 = NULL;
+       while (md != NULL && md != p1) {
+               if (pa >= md->md_phys &&
+                   pa < md->md_phys + md->md_pages * EFI_PAGE_SIZE) {
+                       last = md;
+                       return (md);
+               }
+
+               p1 = p0;
+               p0 = md;
+               md = (pa < md->md_phys) ? efi_md_prev(md) : efi_md_next(md);
+       }
+
+       return (NULL);
 }
 
 void

Modified: head/sys/ia64/include/efi.h
==============================================================================
--- head/sys/ia64/include/efi.h Sat Jul 16 19:38:08 2011        (r224111)
+++ head/sys/ia64/include/efi.h Sat Jul 16 19:56:07 2011        (r224112)
@@ -161,8 +161,11 @@ void efi_boot_finish(void);
 int efi_boot_minimal(uint64_t);
 void *efi_get_table(struct uuid *);
 void efi_get_time(struct efi_tm *);
+struct efi_md *efi_md_find(vm_paddr_t);
 struct efi_md *efi_md_first(void);
+struct efi_md *efi_md_last(void);
 struct efi_md *efi_md_next(struct efi_md *);
+struct efi_md *efi_md_prev(struct efi_md *);
 void efi_reset_system(void);
 int efi_set_time(struct efi_tm *);
 int efi_var_get(efi_char *, struct uuid *, uint32_t *, size_t *, void *);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to