Rev 1321 | Rev 1963 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1321 | Rev 1404 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | * The list_sort function is (presumably) licensed under the GPL (see the |
- | |
3 | * top level "COPYING" file for details). |
- | |
4 | * |
- | |
5 | * The remainder of this file is: |
- | |
6 | * |
- | |
7 | * Copyright © 1997-2003 by The XFree86 Project, Inc. |
2 | * Copyright © 1997-2003 by The XFree86 Project, Inc. |
8 | * Copyright © 2007 Dave Airlie |
3 | * Copyright © 2007 Dave Airlie |
9 | * Copyright © 2007-2008 Intel Corporation |
4 | * Copyright © 2007-2008 Intel Corporation |
10 | * Jesse Barnes |
5 | * Jesse Barnes |
11 | * Copyright 2005-2006 Luc Verhaegen |
6 | * Copyright 2005-2006 Luc Verhaegen |
Line 34... | Line 29... | ||
34 | * the sale, use or other dealings in this Software without prior written |
29 | * the sale, use or other dealings in this Software without prior written |
35 | * authorization from the copyright holder(s) and author(s). |
30 | * authorization from the copyright holder(s) and author(s). |
36 | */ |
31 | */ |
Line 37... | Line 32... | ||
37 | 32 | ||
- | 33 | #include |
|
38 | #include |
34 | #include |
39 | #include "drmP.h" |
35 | #include "drmP.h" |
40 | #include "drm.h" |
36 | #include "drm.h" |
Line 41... | Line 37... | ||
41 | #include "drm_crtc.h" |
37 | #include "drm_crtc.h" |
Line 853... | Line 849... | ||
853 | } |
849 | } |
854 | EXPORT_SYMBOL(drm_mode_prune_invalid); |
850 | EXPORT_SYMBOL(drm_mode_prune_invalid); |
Line 855... | Line 851... | ||
855 | 851 | ||
856 | /** |
852 | /** |
- | 853 | * drm_mode_compare - compare modes for favorability |
|
857 | * drm_mode_compare - compare modes for favorability |
854 | * @priv: unused |
858 | * @lh_a: list_head for first mode |
855 | * @lh_a: list_head for first mode |
859 | * @lh_b: list_head for second mode |
856 | * @lh_b: list_head for second mode |
860 | * |
857 | * |
861 | * LOCKING: |
858 | * LOCKING: |
Line 866... | Line 863... | ||
866 | * |
863 | * |
867 | * RETURNS: |
864 | * RETURNS: |
868 | * Negative if @lh_a is better than @lh_b, zero if they're equivalent, or |
865 | * Negative if @lh_a is better than @lh_b, zero if they're equivalent, or |
869 | * positive if @lh_b is better than @lh_a. |
866 | * positive if @lh_b is better than @lh_a. |
870 | */ |
867 | */ |
871 | static int drm_mode_compare(struct list_head *lh_a, struct list_head *lh_b) |
868 | static int drm_mode_compare(void *priv, struct list_head *lh_a, struct list_head *lh_b) |
872 | { |
869 | { |
873 | struct drm_display_mode *a = list_entry(lh_a, struct drm_display_mode, head); |
870 | struct drm_display_mode *a = list_entry(lh_a, struct drm_display_mode, head); |
874 | struct drm_display_mode *b = list_entry(lh_b, struct drm_display_mode, head); |
871 | struct drm_display_mode *b = list_entry(lh_b, struct drm_display_mode, head); |
875 | int diff; |
872 | int diff; |
Line 883... | Line 880... | ||
883 | return diff; |
880 | return diff; |
884 | diff = b->clock - a->clock; |
881 | diff = b->clock - a->clock; |
885 | return diff; |
882 | return diff; |
886 | } |
883 | } |
Line 887... | Line -... | ||
887 | - | ||
888 | /* FIXME: what we don't have a list sort function? */ |
- | |
889 | /* list sort from Mark J Roberts (mjr@znex.org) */ |
- | |
890 | void list_sort(struct list_head *head, |
- | |
891 | int (*cmp)(struct list_head *a, struct list_head *b)) |
- | |
892 | { |
- | |
893 | struct list_head *p, *q, *e, *list, *tail, *oldhead; |
- | |
894 | int insize, nmerges, psize, qsize, i; |
- | |
895 | - | ||
896 | list = head->next; |
- | |
897 | list_del(head); |
- | |
898 | insize = 1; |
- | |
899 | for (;;) { |
- | |
900 | p = oldhead = list; |
- | |
901 | list = tail = NULL; |
- | |
902 | nmerges = 0; |
- | |
903 | - | ||
904 | while (p) { |
- | |
905 | nmerges++; |
- | |
906 | q = p; |
- | |
907 | psize = 0; |
- | |
908 | for (i = 0; i < insize; i++) { |
- | |
909 | psize++; |
- | |
910 | q = q->next == oldhead ? NULL : q->next; |
- | |
911 | if (!q) |
- | |
912 | break; |
- | |
913 | } |
- | |
914 | - | ||
915 | qsize = insize; |
- | |
916 | while (psize > 0 || (qsize > 0 && q)) { |
- | |
917 | if (!psize) { |
- | |
918 | e = q; |
- | |
919 | q = q->next; |
- | |
920 | qsize--; |
- | |
921 | if (q == oldhead) |
- | |
922 | q = NULL; |
- | |
923 | } else if (!qsize || !q) { |
- | |
924 | e = p; |
- | |
925 | p = p->next; |
- | |
926 | psize--; |
- | |
927 | if (p == oldhead) |
- | |
928 | p = NULL; |
- | |
929 | } else if (cmp(p, q) <= 0) { |
- | |
930 | e = p; |
- | |
931 | p = p->next; |
- | |
932 | psize--; |
- | |
933 | if (p == oldhead) |
- | |
934 | p = NULL; |
- | |
935 | } else { |
- | |
936 | e = q; |
- | |
937 | q = q->next; |
- | |
938 | qsize--; |
- | |
939 | if (q == oldhead) |
- | |
940 | q = NULL; |
- | |
941 | } |
- | |
942 | if (tail) |
- | |
943 | tail->next = e; |
- | |
944 | else |
- | |
945 | list = e; |
- | |
946 | e->prev = tail; |
- | |
947 | tail = e; |
- | |
948 | } |
- | |
949 | p = q; |
- | |
950 | } |
- | |
951 | - | ||
952 | tail->next = list; |
- | |
953 | list->prev = tail; |
- | |
954 | - | ||
955 | if (nmerges <= 1) |
- | |
956 | break; |
- | |
957 | - | ||
958 | insize *= 2; |
- | |
959 | } |
- | |
960 | - | ||
961 | head->next = list; |
- | |
962 | head->prev = list->prev; |
- | |
963 | list->prev->next = head; |
- | |
964 | list->prev = head; |
- | |
965 | } |
- | |
966 | 884 | ||
967 | /** |
885 | /** |
968 | * drm_mode_sort - sort mode list |
886 | * drm_mode_sort - sort mode list |
969 | * @mode_list: list to sort |
887 | * @mode_list: list to sort |
970 | * |
888 | * |
Line 973... | Line 891... | ||
973 | * |
891 | * |
974 | * Sort @mode_list by favorability, putting good modes first. |
892 | * Sort @mode_list by favorability, putting good modes first. |
975 | */ |
893 | */ |
976 | void drm_mode_sort(struct list_head *mode_list) |
894 | void drm_mode_sort(struct list_head *mode_list) |
977 | { |
895 | { |
978 | list_sort(mode_list, drm_mode_compare); |
896 | list_sort(NULL, mode_list, drm_mode_compare); |
979 | } |
897 | } |
980 | EXPORT_SYMBOL(drm_mode_sort); |
898 | EXPORT_SYMBOL(drm_mode_sort); |
Line 981... | Line 899... | ||
981 | 899 | ||
982 | /** |
900 | /** |