~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/arm/xen/p2m.c

Version: ~ [ linux-5.3-rc5 ] ~ [ linux-5.2.9 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.67 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.139 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.189 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.189 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.72 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <linux/bootmem.h>
  2 #include <linux/gfp.h>
  3 #include <linux/export.h>
  4 #include <linux/rwlock.h>
  5 #include <linux/slab.h>
  6 #include <linux/types.h>
  7 #include <linux/dma-mapping.h>
  8 #include <linux/vmalloc.h>
  9 #include <linux/swiotlb.h>
 10 
 11 #include <xen/xen.h>
 12 #include <xen/interface/memory.h>
 13 #include <xen/page.h>
 14 #include <xen/swiotlb-xen.h>
 15 
 16 #include <asm/cacheflush.h>
 17 #include <asm/xen/hypercall.h>
 18 #include <asm/xen/interface.h>
 19 
 20 struct xen_p2m_entry {
 21         unsigned long pfn;
 22         unsigned long mfn;
 23         unsigned long nr_pages;
 24         struct rb_node rbnode_phys;
 25 };
 26 
 27 static rwlock_t p2m_lock;
 28 struct rb_root phys_to_mach = RB_ROOT;
 29 EXPORT_SYMBOL_GPL(phys_to_mach);
 30 
 31 static int xen_add_phys_to_mach_entry(struct xen_p2m_entry *new)
 32 {
 33         struct rb_node **link = &phys_to_mach.rb_node;
 34         struct rb_node *parent = NULL;
 35         struct xen_p2m_entry *entry;
 36         int rc = 0;
 37 
 38         while (*link) {
 39                 parent = *link;
 40                 entry = rb_entry(parent, struct xen_p2m_entry, rbnode_phys);
 41 
 42                 if (new->pfn == entry->pfn)
 43                         goto err_out;
 44 
 45                 if (new->pfn < entry->pfn)
 46                         link = &(*link)->rb_left;
 47                 else
 48                         link = &(*link)->rb_right;
 49         }
 50         rb_link_node(&new->rbnode_phys, parent, link);
 51         rb_insert_color(&new->rbnode_phys, &phys_to_mach);
 52         goto out;
 53 
 54 err_out:
 55         rc = -EINVAL;
 56         pr_warn("%s: cannot add pfn=%pa -> mfn=%pa: pfn=%pa -> mfn=%pa already exists\n",
 57                         __func__, &new->pfn, &new->mfn, &entry->pfn, &entry->mfn);
 58 out:
 59         return rc;
 60 }
 61 
 62 unsigned long __pfn_to_mfn(unsigned long pfn)
 63 {
 64         struct rb_node *n = phys_to_mach.rb_node;
 65         struct xen_p2m_entry *entry;
 66         unsigned long irqflags;
 67 
 68         read_lock_irqsave(&p2m_lock, irqflags);
 69         while (n) {
 70                 entry = rb_entry(n, struct xen_p2m_entry, rbnode_phys);
 71                 if (entry->pfn <= pfn &&
 72                                 entry->pfn + entry->nr_pages > pfn) {
 73                         read_unlock_irqrestore(&p2m_lock, irqflags);
 74                         return entry->mfn + (pfn - entry->pfn);
 75                 }
 76                 if (pfn < entry->pfn)
 77                         n = n->rb_left;
 78                 else
 79                         n = n->rb_right;
 80         }
 81         read_unlock_irqrestore(&p2m_lock, irqflags);
 82 
 83         return INVALID_P2M_ENTRY;
 84 }
 85 EXPORT_SYMBOL_GPL(__pfn_to_mfn);
 86 
 87 int set_foreign_p2m_mapping(struct gnttab_map_grant_ref *map_ops,
 88                             struct gnttab_map_grant_ref *kmap_ops,
 89                             struct page **pages, unsigned int count)
 90 {
 91         int i;
 92 
 93         for (i = 0; i < count; i++) {
 94                 if (map_ops[i].status)
 95                         continue;
 96                 set_phys_to_machine(map_ops[i].host_addr >> PAGE_SHIFT,
 97                                     map_ops[i].dev_bus_addr >> PAGE_SHIFT);
 98         }
 99 
100         return 0;
101 }
102 EXPORT_SYMBOL_GPL(set_foreign_p2m_mapping);
103 
104 int clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops,
105                               struct gnttab_unmap_grant_ref *kunmap_ops,
106                               struct page **pages, unsigned int count)
107 {
108         int i;
109 
110         for (i = 0; i < count; i++) {
111                 set_phys_to_machine(unmap_ops[i].host_addr >> PAGE_SHIFT,
112                                     INVALID_P2M_ENTRY);
113         }
114 
115         return 0;
116 }
117 EXPORT_SYMBOL_GPL(clear_foreign_p2m_mapping);
118 
119 bool __set_phys_to_machine_multi(unsigned long pfn,
120                 unsigned long mfn, unsigned long nr_pages)
121 {
122         int rc;
123         unsigned long irqflags;
124         struct xen_p2m_entry *p2m_entry;
125         struct rb_node *n = phys_to_mach.rb_node;
126 
127         if (mfn == INVALID_P2M_ENTRY) {
128                 write_lock_irqsave(&p2m_lock, irqflags);
129                 while (n) {
130                         p2m_entry = rb_entry(n, struct xen_p2m_entry, rbnode_phys);
131                         if (p2m_entry->pfn <= pfn &&
132                                         p2m_entry->pfn + p2m_entry->nr_pages > pfn) {
133                                 rb_erase(&p2m_entry->rbnode_phys, &phys_to_mach);
134                                 write_unlock_irqrestore(&p2m_lock, irqflags);
135                                 kfree(p2m_entry);
136                                 return true;
137                         }
138                         if (pfn < p2m_entry->pfn)
139                                 n = n->rb_left;
140                         else
141                                 n = n->rb_right;
142                 }
143                 write_unlock_irqrestore(&p2m_lock, irqflags);
144                 return true;
145         }
146 
147         p2m_entry = kzalloc(sizeof(struct xen_p2m_entry), GFP_NOWAIT);
148         if (!p2m_entry) {
149                 pr_warn("cannot allocate xen_p2m_entry\n");
150                 return false;
151         }
152         p2m_entry->pfn = pfn;
153         p2m_entry->nr_pages = nr_pages;
154         p2m_entry->mfn = mfn;
155 
156         write_lock_irqsave(&p2m_lock, irqflags);
157         if ((rc = xen_add_phys_to_mach_entry(p2m_entry)) < 0) {
158                 write_unlock_irqrestore(&p2m_lock, irqflags);
159                 return false;
160         }
161         write_unlock_irqrestore(&p2m_lock, irqflags);
162         return true;
163 }
164 EXPORT_SYMBOL_GPL(__set_phys_to_machine_multi);
165 
166 bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn)
167 {
168         return __set_phys_to_machine_multi(pfn, mfn, 1);
169 }
170 EXPORT_SYMBOL_GPL(__set_phys_to_machine);
171 
172 static int p2m_init(void)
173 {
174         rwlock_init(&p2m_lock);
175         return 0;
176 }
177 arch_initcall(p2m_init);
178 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp