diff options
author | Dave Airlie <airlied@redhat.com> | 2009-08-26 21:51:23 -0400 |
---|---|---|
committer | Dave Airlie <airlied@redhat.com> | 2009-08-30 19:09:28 -0400 |
commit | 689d7c2a1127378854c7d7ea8d7c81238a824240 (patch) | |
tree | 207a7ef5234195c0a53277a8a6008ca13ed2e2d3 /drivers/gpu/drm/radeon/mkregtable.c | |
parent | a1a2d1d32250f6fcc317419e9dfb4a5a6946d2e6 (diff) |
drm/radeon: cleanup mkregtable.c
This cleans up the code in mkregtable.c to be more kernel style.
Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'drivers/gpu/drm/radeon/mkregtable.c')
-rw-r--r-- | drivers/gpu/drm/radeon/mkregtable.c | 320 |
1 files changed, 157 insertions, 163 deletions
diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c index 0acd1cf8c361..fb211e585dea 100644 --- a/drivers/gpu/drm/radeon/mkregtable.c +++ b/drivers/gpu/drm/radeon/mkregtable.c | |||
@@ -25,10 +25,8 @@ | |||
25 | * | 25 | * |
26 | */ | 26 | */ |
27 | #define container_of(ptr, type, member) ({ \ | 27 | #define container_of(ptr, type, member) ({ \ |
28 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ | 28 | const typeof(((type *)0)->member)*__mptr = (ptr); \ |
29 | (type *)( (char *)__mptr - offsetof(type,member) );}) | 29 | (type *)((char *)__mptr - offsetof(type, member)); }) |
30 | |||
31 | |||
32 | 30 | ||
33 | /* | 31 | /* |
34 | * Simple doubly linked list implementation. | 32 | * Simple doubly linked list implementation. |
@@ -63,8 +61,7 @@ static inline void INIT_LIST_HEAD(struct list_head *list) | |||
63 | */ | 61 | */ |
64 | #ifndef CONFIG_DEBUG_LIST | 62 | #ifndef CONFIG_DEBUG_LIST |
65 | static inline void __list_add(struct list_head *new, | 63 | static inline void __list_add(struct list_head *new, |
66 | struct list_head *prev, | 64 | struct list_head *prev, struct list_head *next) |
67 | struct list_head *next) | ||
68 | { | 65 | { |
69 | next->prev = new; | 66 | next->prev = new; |
70 | new->next = next; | 67 | new->next = next; |
@@ -73,8 +70,7 @@ static inline void __list_add(struct list_head *new, | |||
73 | } | 70 | } |
74 | #else | 71 | #else |
75 | extern void __list_add(struct list_head *new, | 72 | extern void __list_add(struct list_head *new, |
76 | struct list_head *prev, | 73 | struct list_head *prev, struct list_head *next); |
77 | struct list_head *next); | ||
78 | #endif | 74 | #endif |
79 | 75 | ||
80 | /** | 76 | /** |
@@ -90,7 +86,6 @@ static inline void list_add(struct list_head *new, struct list_head *head) | |||
90 | __list_add(new, head, head->next); | 86 | __list_add(new, head, head->next); |
91 | } | 87 | } |
92 | 88 | ||
93 | |||
94 | /** | 89 | /** |
95 | * list_add_tail - add a new entry | 90 | * list_add_tail - add a new entry |
96 | * @new: new entry to be added | 91 | * @new: new entry to be added |
@@ -111,7 +106,7 @@ static inline void list_add_tail(struct list_head *new, struct list_head *head) | |||
111 | * This is only for internal list manipulation where we know | 106 | * This is only for internal list manipulation where we know |
112 | * the prev/next entries already! | 107 | * the prev/next entries already! |
113 | */ | 108 | */ |
114 | static inline void __list_del(struct list_head * prev, struct list_head * next) | 109 | static inline void __list_del(struct list_head *prev, struct list_head *next) |
115 | { | 110 | { |
116 | next->prev = prev; | 111 | next->prev = prev; |
117 | prev->next = next; | 112 | prev->next = next; |
@@ -127,8 +122,8 @@ static inline void __list_del(struct list_head * prev, struct list_head * next) | |||
127 | static inline void list_del(struct list_head *entry) | 122 | static inline void list_del(struct list_head *entry) |
128 | { | 123 | { |
129 | __list_del(entry->prev, entry->next); | 124 | __list_del(entry->prev, entry->next); |
130 | entry->next = (void*)0xDEADBEEF; | 125 | entry->next = (void *)0xDEADBEEF; |
131 | entry->prev = (void*)0xBEEFDEAD; | 126 | entry->prev = (void *)0xBEEFDEAD; |
132 | } | 127 | } |
133 | #else | 128 | #else |
134 | extern void list_del(struct list_head *entry); | 129 | extern void list_del(struct list_head *entry); |
@@ -141,8 +136,7 @@ extern void list_del(struct list_head *entry); | |||
141 | * | 136 | * |
142 | * If @old was empty, it will be overwritten. | 137 | * If @old was empty, it will be overwritten. |
143 | */ | 138 | */ |
144 | static inline void list_replace(struct list_head *old, | 139 | static inline void list_replace(struct list_head *old, struct list_head *new) |
145 | struct list_head *new) | ||
146 | { | 140 | { |
147 | new->next = old->next; | 141 | new->next = old->next; |
148 | new->next->prev = new; | 142 | new->next->prev = new; |
@@ -151,7 +145,7 @@ static inline void list_replace(struct list_head *old, | |||
151 | } | 145 | } |
152 | 146 | ||
153 | static inline void list_replace_init(struct list_head *old, | 147 | static inline void list_replace_init(struct list_head *old, |
154 | struct list_head *new) | 148 | struct list_head *new) |
155 | { | 149 | { |
156 | list_replace(old, new); | 150 | list_replace(old, new); |
157 | INIT_LIST_HEAD(old); | 151 | INIT_LIST_HEAD(old); |
@@ -196,7 +190,7 @@ static inline void list_move_tail(struct list_head *list, | |||
196 | * @head: the head of the list | 190 | * @head: the head of the list |
197 | */ | 191 | */ |
198 | static inline int list_is_last(const struct list_head *list, | 192 | static inline int list_is_last(const struct list_head *list, |
199 | const struct list_head *head) | 193 | const struct list_head *head) |
200 | { | 194 | { |
201 | return list->next == head; | 195 | return list->next == head; |
202 | } | 196 | } |
@@ -239,7 +233,8 @@ static inline int list_is_singular(const struct list_head *head) | |||
239 | } | 233 | } |
240 | 234 | ||
241 | static inline void __list_cut_position(struct list_head *list, | 235 | static inline void __list_cut_position(struct list_head *list, |
242 | struct list_head *head, struct list_head *entry) | 236 | struct list_head *head, |
237 | struct list_head *entry) | ||
243 | { | 238 | { |
244 | struct list_head *new_first = entry->next; | 239 | struct list_head *new_first = entry->next; |
245 | list->next = head->next; | 240 | list->next = head->next; |
@@ -265,12 +260,12 @@ static inline void __list_cut_position(struct list_head *list, | |||
265 | * | 260 | * |
266 | */ | 261 | */ |
267 | static inline void list_cut_position(struct list_head *list, | 262 | static inline void list_cut_position(struct list_head *list, |
268 | struct list_head *head, struct list_head *entry) | 263 | struct list_head *head, |
264 | struct list_head *entry) | ||
269 | { | 265 | { |
270 | if (list_empty(head)) | 266 | if (list_empty(head)) |
271 | return; | 267 | return; |
272 | if (list_is_singular(head) && | 268 | if (list_is_singular(head) && (head->next != entry && head != entry)) |
273 | (head->next != entry && head != entry)) | ||
274 | return; | 269 | return; |
275 | if (entry == head) | 270 | if (entry == head) |
276 | INIT_LIST_HEAD(list); | 271 | INIT_LIST_HEAD(list); |
@@ -279,8 +274,7 @@ static inline void list_cut_position(struct list_head *list, | |||
279 | } | 274 | } |
280 | 275 | ||
281 | static inline void __list_splice(const struct list_head *list, | 276 | static inline void __list_splice(const struct list_head *list, |
282 | struct list_head *prev, | 277 | struct list_head *prev, struct list_head *next) |
283 | struct list_head *next) | ||
284 | { | 278 | { |
285 | struct list_head *first = list->next; | 279 | struct list_head *first = list->next; |
286 | struct list_head *last = list->prev; | 280 | struct list_head *last = list->prev; |
@@ -298,7 +292,7 @@ static inline void __list_splice(const struct list_head *list, | |||
298 | * @head: the place to add it in the first list. | 292 | * @head: the place to add it in the first list. |
299 | */ | 293 | */ |
300 | static inline void list_splice(const struct list_head *list, | 294 | static inline void list_splice(const struct list_head *list, |
301 | struct list_head *head) | 295 | struct list_head *head) |
302 | { | 296 | { |
303 | if (!list_empty(list)) | 297 | if (!list_empty(list)) |
304 | __list_splice(list, head, head->next); | 298 | __list_splice(list, head, head->next); |
@@ -310,7 +304,7 @@ static inline void list_splice(const struct list_head *list, | |||
310 | * @head: the place to add it in the first list. | 304 | * @head: the place to add it in the first list. |
311 | */ | 305 | */ |
312 | static inline void list_splice_tail(struct list_head *list, | 306 | static inline void list_splice_tail(struct list_head *list, |
313 | struct list_head *head) | 307 | struct list_head *head) |
314 | { | 308 | { |
315 | if (!list_empty(list)) | 309 | if (!list_empty(list)) |
316 | __list_splice(list, head->prev, head); | 310 | __list_splice(list, head->prev, head); |
@@ -376,7 +370,7 @@ static inline void list_splice_tail_init(struct list_head *list, | |||
376 | */ | 370 | */ |
377 | #define list_for_each(pos, head) \ | 371 | #define list_for_each(pos, head) \ |
378 | for (pos = (head)->next; prefetch(pos->next), pos != (head); \ | 372 | for (pos = (head)->next; prefetch(pos->next), pos != (head); \ |
379 | pos = pos->next) | 373 | pos = pos->next) |
380 | 374 | ||
381 | /** | 375 | /** |
382 | * __list_for_each - iterate over a list | 376 | * __list_for_each - iterate over a list |
@@ -398,7 +392,7 @@ static inline void list_splice_tail_init(struct list_head *list, | |||
398 | */ | 392 | */ |
399 | #define list_for_each_prev(pos, head) \ | 393 | #define list_for_each_prev(pos, head) \ |
400 | for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \ | 394 | for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \ |
401 | pos = pos->prev) | 395 | pos = pos->prev) |
402 | 396 | ||
403 | /** | 397 | /** |
404 | * list_for_each_safe - iterate over a list safe against removal of list entry | 398 | * list_for_each_safe - iterate over a list safe against removal of list entry |
@@ -555,172 +549,172 @@ static inline void list_splice_tail_init(struct list_head *list, | |||
555 | pos = n, n = list_entry(n->member.prev, typeof(*n), member)) | 549 | pos = n, n = list_entry(n->member.prev, typeof(*n), member)) |
556 | 550 | ||
557 | struct offset { | 551 | struct offset { |
558 | struct list_head list; | 552 | struct list_head list; |
559 | unsigned offset; | 553 | unsigned offset; |
560 | }; | 554 | }; |
561 | 555 | ||
562 | struct table { | 556 | struct table { |
563 | struct list_head offsets; | 557 | struct list_head offsets; |
564 | unsigned offset_max; | 558 | unsigned offset_max; |
565 | unsigned nentry; | 559 | unsigned nentry; |
566 | unsigned *table; | 560 | unsigned *table; |
567 | char *gpu_prefix; | 561 | char *gpu_prefix; |
568 | }; | 562 | }; |
569 | 563 | ||
570 | struct offset* offset_new(unsigned o) | 564 | struct offset *offset_new(unsigned o) |
571 | { | 565 | { |
572 | struct offset *offset; | 566 | struct offset *offset; |
573 | 567 | ||
574 | offset = (struct offset*)malloc(sizeof(struct offset)); | 568 | offset = (struct offset *)malloc(sizeof(struct offset)); |
575 | if (offset) { | 569 | if (offset) { |
576 | INIT_LIST_HEAD(&offset->list); | 570 | INIT_LIST_HEAD(&offset->list); |
577 | offset->offset = o; | 571 | offset->offset = o; |
578 | } | 572 | } |
579 | return offset; | 573 | return offset; |
580 | } | 574 | } |
581 | 575 | ||
582 | void table_offset_add(struct table *t, struct offset *offset) | 576 | void table_offset_add(struct table *t, struct offset *offset) |
583 | { | 577 | { |
584 | list_add_tail(&offset->list, &t->offsets); | 578 | list_add_tail(&offset->list, &t->offsets); |
585 | } | 579 | } |
586 | 580 | ||
587 | void table_init(struct table *t) | 581 | void table_init(struct table *t) |
588 | { | 582 | { |
589 | INIT_LIST_HEAD(&t->offsets); | 583 | INIT_LIST_HEAD(&t->offsets); |
590 | t->offset_max = 0; | 584 | t->offset_max = 0; |
591 | t->nentry = 0; | 585 | t->nentry = 0; |
592 | t->table = NULL; | 586 | t->table = NULL; |
593 | } | 587 | } |
594 | 588 | ||
595 | void table_print(struct table *t) | 589 | void table_print(struct table *t) |
596 | { | 590 | { |
597 | unsigned nlloop, i, j, n, c, id; | 591 | unsigned nlloop, i, j, n, c, id; |
598 | 592 | ||
599 | nlloop = (t->nentry + 3) / 4; | 593 | nlloop = (t->nentry + 3) / 4; |
600 | c = t->nentry; | 594 | c = t->nentry; |
601 | printf("static const unsigned %s_reg_safe_bm[%d] = {\n", t->gpu_prefix, t->nentry); | 595 | printf("static const unsigned %s_reg_safe_bm[%d] = {\n", t->gpu_prefix, |
602 | for(i = 0, id = 0; i < nlloop; i++) { | 596 | t->nentry); |
603 | n = 4; | 597 | for (i = 0, id = 0; i < nlloop; i++) { |
604 | if (n > c) { | 598 | n = 4; |
605 | n = c; | 599 | if (n > c) |
606 | } | 600 | n = c; |
607 | c -= n; | 601 | c -= n; |
608 | for(j = 0; j < n; j++) { | 602 | for (j = 0; j < n; j++) { |
609 | if (j == 0) printf("\t"); | 603 | if (j == 0) |
610 | else printf(" "); | 604 | printf("\t"); |
611 | printf("0x%08X,", t->table[id++]); | 605 | else |
612 | } | 606 | printf(" "); |
613 | printf("\n"); | 607 | printf("0x%08X,", t->table[id++]); |
614 | } | 608 | } |
615 | printf("};\n"); | 609 | printf("\n"); |
610 | } | ||
611 | printf("};\n"); | ||
616 | } | 612 | } |
617 | 613 | ||
618 | int table_build(struct table *t) | 614 | int table_build(struct table *t) |
619 | { | 615 | { |
620 | struct offset *offset; | 616 | struct offset *offset; |
621 | unsigned i, m; | 617 | unsigned i, m; |
622 | 618 | ||
623 | t->nentry = ((t->offset_max >> 2) + 31) / 32; | 619 | t->nentry = ((t->offset_max >> 2) + 31) / 32; |
624 | t->table = (unsigned*)malloc(sizeof(unsigned) * t->nentry); | 620 | t->table = (unsigned *)malloc(sizeof(unsigned) * t->nentry); |
625 | if (t->table == NULL) { | 621 | if (t->table == NULL) |
626 | return -1; | 622 | return -1; |
627 | } | 623 | memset(t->table, 0xff, sizeof(unsigned) * t->nentry); |
628 | memset(t->table, 0xff, sizeof(unsigned) * t->nentry); | 624 | list_for_each_entry(offset, &t->offsets, list) { |
629 | list_for_each_entry(offset, &t->offsets, list) { | 625 | i = (offset->offset >> 2) / 32; |
630 | i = (offset->offset >> 2) / 32; | 626 | m = (offset->offset >> 2) & 31; |
631 | m = (offset->offset >> 2) & 31; | 627 | m = 1 << m; |
632 | m = 1 << m; | 628 | t->table[i] ^= m; |
633 | t->table[i] ^= m; | 629 | } |
634 | } | 630 | return 0; |
635 | return 0; | ||
636 | } | 631 | } |
637 | 632 | ||
638 | static char gpu_name[10]; | 633 | static char gpu_name[10]; |
639 | int parser_auth(struct table *t, const char *filename) | 634 | int parser_auth(struct table *t, const char *filename) |
640 | { | 635 | { |
641 | FILE *file; | 636 | FILE *file; |
642 | regex_t mask_rex; | 637 | regex_t mask_rex; |
643 | regmatch_t match[4]; | 638 | regmatch_t match[4]; |
644 | char buf[1024]; | 639 | char buf[1024]; |
645 | size_t end; | 640 | size_t end; |
646 | int len; | 641 | int len; |
647 | int done = 0; | 642 | int done = 0; |
648 | int r; | 643 | int r; |
649 | unsigned o; | 644 | unsigned o; |
650 | struct offset *offset; | 645 | struct offset *offset; |
651 | char last_reg_s[10]; | 646 | char last_reg_s[10]; |
652 | int last_reg; | 647 | int last_reg; |
653 | 648 | ||
654 | if (regcomp(&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) { | 649 | if (regcomp |
655 | fprintf(stderr, "Failed to compile regular expression\n"); | 650 | (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) { |
656 | return -1; | 651 | fprintf(stderr, "Failed to compile regular expression\n"); |
657 | } | 652 | return -1; |
658 | file = fopen(filename, "r"); | 653 | } |
659 | if (file == NULL) { | 654 | file = fopen(filename, "r"); |
660 | fprintf(stderr, "Failed to open: %s\n", filename); | 655 | if (file == NULL) { |
661 | return -1; | 656 | fprintf(stderr, "Failed to open: %s\n", filename); |
662 | } | 657 | return -1; |
663 | fseek(file, 0, SEEK_END); | 658 | } |
664 | end = ftell(file); | 659 | fseek(file, 0, SEEK_END); |
665 | fseek(file, 0, SEEK_SET); | 660 | end = ftell(file); |
666 | 661 | fseek(file, 0, SEEK_SET); | |
667 | /* get header */ | 662 | |
668 | if (fgets(buf, 1024, file) == NULL) | 663 | /* get header */ |
669 | return -1; | 664 | if (fgets(buf, 1024, file) == NULL) |
670 | 665 | return -1; | |
671 | /* first line will contain the last register | 666 | |
672 | * and gpu name */ | 667 | /* first line will contain the last register |
673 | sscanf(buf, "%s %s", gpu_name, last_reg_s); | 668 | * and gpu name */ |
674 | t->gpu_prefix = gpu_name; | 669 | sscanf(buf, "%s %s", gpu_name, last_reg_s); |
675 | last_reg = strtol(last_reg_s, NULL, 16); | 670 | t->gpu_prefix = gpu_name; |
676 | 671 | last_reg = strtol(last_reg_s, NULL, 16); | |
677 | do { | 672 | |
678 | if (fgets(buf, 1024, file) == NULL) | 673 | do { |
679 | return -1; | 674 | if (fgets(buf, 1024, file) == NULL) |
680 | len = strlen(buf); | 675 | return -1; |
681 | if (ftell(file) == end) { | 676 | len = strlen(buf); |
682 | done = 1; | 677 | if (ftell(file) == end) |
683 | } | 678 | done = 1; |
684 | if (len) { | 679 | if (len) { |
685 | r = regexec(&mask_rex, buf, 4, match, 0); | 680 | r = regexec(&mask_rex, buf, 4, match, 0); |
686 | if (r == REG_NOMATCH) { | 681 | if (r == REG_NOMATCH) { |
687 | } else if (r) { | 682 | } else if (r) { |
688 | fprintf(stderr, "Error matching regular expression %d in %s\n", | 683 | fprintf(stderr, |
689 | r, filename); | 684 | "Error matching regular expression %d in %s\n", |
690 | return -1; | 685 | r, filename); |
691 | } else { | 686 | return -1; |
692 | buf[match[0].rm_eo] = 0; | 687 | } else { |
693 | buf[match[1].rm_eo] = 0; | 688 | buf[match[0].rm_eo] = 0; |
694 | buf[match[2].rm_eo] = 0; | 689 | buf[match[1].rm_eo] = 0; |
695 | o = strtol(&buf[match[1].rm_so], NULL, 16); | 690 | buf[match[2].rm_eo] = 0; |
696 | offset = offset_new(o); | 691 | o = strtol(&buf[match[1].rm_so], NULL, 16); |
697 | table_offset_add(t, offset); | 692 | offset = offset_new(o); |
698 | if (o > t->offset_max) { | 693 | table_offset_add(t, offset); |
699 | t->offset_max = o; | 694 | if (o > t->offset_max) |
700 | } | 695 | t->offset_max = o; |
701 | } | 696 | } |
702 | } | 697 | } |
703 | } while (!done); | 698 | } while (!done); |
704 | fclose(file); | 699 | fclose(file); |
705 | if (t->offset_max < last_reg) | 700 | if (t->offset_max < last_reg) |
706 | t->offset_max = last_reg; | 701 | t->offset_max = last_reg; |
707 | return table_build(t); | 702 | return table_build(t); |
708 | } | 703 | } |
709 | 704 | ||
710 | int main(int argc, char *argv[]) | 705 | int main(int argc, char *argv[]) |
711 | { | 706 | { |
712 | struct table t; | 707 | struct table t; |
713 | 708 | ||
714 | if (argc != 2) { | 709 | if (argc != 2) { |
715 | fprintf(stderr, "Usage: %s <authfile>\n", | 710 | fprintf(stderr, "Usage: %s <authfile>\n", argv[0]); |
716 | argv[0]); | 711 | exit(1); |
717 | exit(1); | 712 | } |
718 | } | 713 | table_init(&t); |
719 | table_init(&t); | 714 | if (parser_auth(&t, argv[1])) { |
720 | if (parser_auth(&t, argv[1])) { | 715 | fprintf(stderr, "Failed to parse file %s\n", argv[1]); |
721 | fprintf(stderr, "Failed to parse file %s\n", argv[1]); | 716 | return -1; |
722 | return -1; | 717 | } |
723 | } | 718 | table_print(&t); |
724 | table_print(&t); | 719 | return 0; |
725 | return 0; | ||
726 | } | 720 | } |