MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / bitmap_region_alloc

Function bitmap_region_alloc

components/drivers/pci/endpoint/mem.c:90–205  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90static rt_ubase_t bitmap_region_alloc(struct rt_pci_ep_mem *mem, rt_size_t size)
91{
92 rt_size_t bit, next_bit, end_bit, max_bits;
93
94 size /= mem->page_size;
95 max_bits = mem->bits - size;
96
97 rt_bitmap_for_each_clear_bit(mem->map, bit, max_bits)
98 {
99 end_bit = bit + size;
100
101 for (next_bit = bit + 1; next_bit < end_bit; ++next_bit)
102 {
103 if (rt_bitmap_test_bit(mem->map, next_bit))
104 {
105 bit = next_bit;
106 goto _next;
107 }
108 }
109
110 if (next_bit == end_bit)
111 {
112 while (next_bit --> bit)
113 {
114 rt_bitmap_set_bit(mem->map, next_bit);
115 }
116
117 return mem->cpu_addr + bit * mem->page_size;
118 }
119 _next:
120 }
121
122 return ~0ULL;
123}
124
125static void bitmap_region_free(struct rt_pci_ep_mem *mem,
126 rt_ubase_t cpu_addr, rt_size_t size)
127{
128 rt_size_t bit = (cpu_addr - mem->cpu_addr) / mem->page_size, end_bit;
129
130 size /= mem->page_size;
131 end_bit = bit + size;
132
133 for (; bit < end_bit; ++bit)
134 {
135 rt_bitmap_clear_bit(mem->map, bit);
136 }
137}
138
139void *rt_pci_ep_mem_alloc(struct rt_pci_ep *ep,
140 rt_ubase_t *out_cpu_addr, rt_size_t size)
141{
142 void *vaddr = RT_NULL;
143
144 if (!ep || !out_cpu_addr)
145 {
146 return vaddr;
147 }

Callers 1

rt_pci_ep_mem_allocFunction · 0.85

Calls 2

rt_bitmap_test_bitFunction · 0.85
rt_bitmap_set_bitFunction · 0.85

Tested by

no test coverage detected