This source file includes following definitions.
- pvrdma_uar_table_init
- pvrdma_uar_table_cleanup
- pvrdma_uar_alloc
- pvrdma_uar_free
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 #include <linux/bitmap.h>
47 #include <linux/errno.h>
48 #include <linux/slab.h>
49
50 #include "pvrdma.h"
51
52 int pvrdma_uar_table_init(struct pvrdma_dev *dev)
53 {
54 u32 num = dev->dsr->caps.max_uar;
55 u32 mask = num - 1;
56 struct pvrdma_id_table *tbl = &dev->uar_table.tbl;
57
58 if (!is_power_of_2(num))
59 return -EINVAL;
60
61 tbl->last = 0;
62 tbl->top = 0;
63 tbl->max = num;
64 tbl->mask = mask;
65 spin_lock_init(&tbl->lock);
66 tbl->table = kcalloc(BITS_TO_LONGS(num), sizeof(long), GFP_KERNEL);
67 if (!tbl->table)
68 return -ENOMEM;
69
70
71 set_bit(0, tbl->table);
72
73 return 0;
74 }
75
76 void pvrdma_uar_table_cleanup(struct pvrdma_dev *dev)
77 {
78 struct pvrdma_id_table *tbl = &dev->uar_table.tbl;
79
80 kfree(tbl->table);
81 }
82
83 int pvrdma_uar_alloc(struct pvrdma_dev *dev, struct pvrdma_uar_map *uar)
84 {
85 struct pvrdma_id_table *tbl;
86 unsigned long flags;
87 u32 obj;
88
89 tbl = &dev->uar_table.tbl;
90
91 spin_lock_irqsave(&tbl->lock, flags);
92 obj = find_next_zero_bit(tbl->table, tbl->max, tbl->last);
93 if (obj >= tbl->max) {
94 tbl->top = (tbl->top + tbl->max) & tbl->mask;
95 obj = find_first_zero_bit(tbl->table, tbl->max);
96 }
97
98 if (obj >= tbl->max) {
99 spin_unlock_irqrestore(&tbl->lock, flags);
100 return -ENOMEM;
101 }
102
103 set_bit(obj, tbl->table);
104 obj |= tbl->top;
105
106 spin_unlock_irqrestore(&tbl->lock, flags);
107
108 uar->index = obj;
109 uar->pfn = (pci_resource_start(dev->pdev, PVRDMA_PCI_RESOURCE_UAR) >>
110 PAGE_SHIFT) + uar->index;
111
112 return 0;
113 }
114
115 void pvrdma_uar_free(struct pvrdma_dev *dev, struct pvrdma_uar_map *uar)
116 {
117 struct pvrdma_id_table *tbl = &dev->uar_table.tbl;
118 unsigned long flags;
119 u32 obj;
120
121 obj = uar->index & (tbl->max - 1);
122 spin_lock_irqsave(&tbl->lock, flags);
123 clear_bit(obj, tbl->table);
124 tbl->last = min(tbl->last, obj);
125 tbl->top = (tbl->top + tbl->max) & tbl->mask;
126 spin_unlock_irqrestore(&tbl->lock, flags);
127 }