12 #include <sys/types.h>
19 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
27 #define container_of(ptr, type, member) ({ \
28 const typeof(((type *)0)->member)*__mptr = (ptr); \
29 (type *)((char *)__mptr - offsetof(type, member)); })
45 #define LIST_HEAD_INIT(name) { &(name), &(name) }
47 #define LIST_HEAD(name) \
48 struct list_head name = LIST_HEAD_INIT(name)
62 #ifndef CONFIG_DEBUG_LIST
121 #ifndef CONFIG_DEBUG_LIST
124 __list_del(entry->
prev, entry->
next);
125 entry->
next = (
void *)0xDEADBEEF;
126 entry->
prev = (
void *)0xBEEFDEAD;
141 new->next = old->
next;
142 new->next->prev =
new;
143 new->prev = old->
prev;
144 new->prev->next =
new;
147 static inline void list_replace_init(
struct list_head *old,
150 list_replace(old,
new);
160 __list_del(entry->
prev, entry->
next);
161 INIT_LIST_HEAD(entry);
172 list_add(list, head);
220 static inline int list_empty_careful(
const struct list_head *
head)
223 return (next == head) && (next == head->
prev);
230 static inline int list_is_singular(
const struct list_head *head)
232 return !list_empty(head) && (head->
next == head->
prev);
235 static inline void __list_cut_position(
struct list_head *
list,
244 head->
next = new_first;
266 if (list_empty(head))
268 if (list_is_singular(head) && (head->
next != entry && head != entry))
271 INIT_LIST_HEAD(list);
273 __list_cut_position(list, head, entry);
276 static inline void __list_splice(
const struct list_head *list,
294 static inline void list_splice(
const struct list_head *list,
297 if (!list_empty(list))
298 __list_splice(list, head, head->
next);
306 static inline void list_splice_tail(
struct list_head *list,
309 if (!list_empty(list))
310 __list_splice(list, head->
prev, head);
320 static inline void list_splice_init(
struct list_head *list,
323 if (!list_empty(list)) {
324 __list_splice(list, head, head->
next);
325 INIT_LIST_HEAD(list);
337 static inline void list_splice_tail_init(
struct list_head *list,
340 if (!list_empty(list)) {
341 __list_splice(list, head->
prev, head);
342 INIT_LIST_HEAD(list);
352 #define list_entry(ptr, type, member) \
353 container_of(ptr, type, member)
363 #define list_first_entry(ptr, type, member) \
364 list_entry((ptr)->next, type, member)
371 #define list_for_each(pos, head) \
372 for (pos = (head)->next; prefetch(pos->next), pos != (head); \
385 #define __list_for_each(pos, head) \
386 for (pos = (head)->next; pos != (head); pos = pos->next)
393 #define list_for_each_prev(pos, head) \
394 for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
403 #define list_for_each_safe(pos, n, head) \
404 for (pos = (head)->next, n = pos->next; pos != (head); \
405 pos = n, n = pos->next)
413 #define list_for_each_prev_safe(pos, n, head) \
414 for (pos = (head)->prev, n = pos->prev; \
415 prefetch(pos->prev), pos != (head); \
416 pos = n, n = pos->prev)
424 #define list_for_each_entry(pos, head, member) \
425 for (pos = list_entry((head)->next, typeof(*pos), member); \
426 &pos->member != (head); \
427 pos = list_entry(pos->member.next, typeof(*pos), member))
435 #define list_for_each_entry_reverse(pos, head, member) \
436 for (pos = list_entry((head)->prev, typeof(*pos), member); \
437 prefetch(pos->member.prev), &pos->member != (head); \
438 pos = list_entry(pos->member.prev, typeof(*pos), member))
448 #define list_prepare_entry(pos, head, member) \
449 ((pos) ? : list_entry(head, typeof(*pos), member))
460 #define list_for_each_entry_continue(pos, head, member) \
461 for (pos = list_entry(pos->member.next, typeof(*pos), member); \
462 prefetch(pos->member.next), &pos->member != (head); \
463 pos = list_entry(pos->member.next, typeof(*pos), member))
474 #define list_for_each_entry_continue_reverse(pos, head, member) \
475 for (pos = list_entry(pos->member.prev, typeof(*pos), member); \
476 prefetch(pos->member.prev), &pos->member != (head); \
477 pos = list_entry(pos->member.prev, typeof(*pos), member))
487 #define list_for_each_entry_from(pos, head, member) \
488 for (; prefetch(pos->member.next), &pos->member != (head); \
489 pos = list_entry(pos->member.next, typeof(*pos), member))
498 #define list_for_each_entry_safe(pos, n, head, member) \
499 for (pos = list_entry((head)->next, typeof(*pos), member), \
500 n = list_entry(pos->member.next, typeof(*pos), member); \
501 &pos->member != (head); \
502 pos = n, n = list_entry(n->member.next, typeof(*n), member))
514 #define list_for_each_entry_safe_continue(pos, n, head, member) \
515 for (pos = list_entry(pos->member.next, typeof(*pos), member), \
516 n = list_entry(pos->member.next, typeof(*pos), member); \
517 &pos->member != (head); \
518 pos = n, n = list_entry(n->member.next, typeof(*n), member))
530 #define list_for_each_entry_safe_from(pos, n, head, member) \
531 for (n = list_entry(pos->member.next, typeof(*pos), member); \
532 &pos->member != (head); \
533 pos = n, n = list_entry(n->member.next, typeof(*n), member))
545 #define list_for_each_entry_safe_reverse(pos, n, head, member) \
546 for (pos = list_entry((head)->prev, typeof(*pos), member), \
547 n = list_entry(pos->member.prev, typeof(*pos), member); \
548 &pos->member != (head); \
549 pos = n, n = list_entry(n->member.prev, typeof(*n), member))
564 static struct offset *offset_new(
unsigned o)
568 offset = (
struct offset *)
malloc(
sizeof(
struct offset));
570 INIT_LIST_HEAD(&offset->
list);
581 static void table_init(
struct table *
t)
589 static void table_print(
struct table *
t)
591 unsigned nlloop,
i,
j,
n,
c,
id;
593 nlloop = (t->
nentry + 3) / 4;
597 for (i = 0,
id = 0; i < nlloop; i++) {
602 for (j = 0; j <
n; j++) {
614 static int table_build(
struct table *t)
625 i = (offset->
offset >> 2) / 32;
626 m = (offset->
offset >> 2) & 31;
633 static char gpu_name[10];
634 static int parser_auth(
struct table *t,
const char *
filename)
650 (&mask_rex,
"(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
651 fprintf(stderr,
"Failed to compile regular expression\n");
654 file = fopen(filename,
"r");
656 fprintf(stderr,
"Failed to open: %s\n", filename);
664 if (fgets(buf, 1024, file) ==
NULL) {
671 sscanf(buf,
"%s %s", gpu_name, last_reg_s);
673 last_reg = strtol(last_reg_s,
NULL, 16);
676 if (fgets(buf, 1024, file) ==
NULL) {
681 if (ftell(file) == end)
684 r = regexec(&mask_rex, buf, 4, match, 0);
685 if (r == REG_NOMATCH) {
688 "Error matching regular expression %d in %s\n",
693 buf[match[0].rm_eo] = 0;
694 buf[match[1].rm_eo] = 0;
695 buf[match[2].rm_eo] = 0;
696 o = strtol(&buf[match[1].rm_so],
NULL, 16);
697 offset = offset_new(o);
698 table_offset_add(t, offset);
707 return table_build(t);
715 fprintf(stderr,
"Usage: %s <authfile>\n", argv[0]);
719 if (parser_auth(&t, argv[1])) {
720 fprintf(stderr,
"Failed to parse file %s\n", argv[1]);