aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorStefan Richter <stefanr@s5r6.in-berlin.de>2007-03-13 19:26:38 -0400
committerStefan Richter <stefanr@s5r6.in-berlin.de>2007-04-29 18:00:28 -0400
commitc868ae2a1d1ad3a474d2a17295ac1ab190b30061 (patch)
tree03910a0be52b1ab251e719dfac86cf167d68bc94 /drivers
parentfd2f3bddaeb20564f32e59f64e5063fbe0c8f4cc (diff)
ieee1394: csr1212: coding style
Whitespace, line breaks, braces... Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ieee1394/csr1212.c215
-rw-r--r--drivers/ieee1394/csr1212.h31
2 files changed, 133 insertions, 113 deletions
diff --git a/drivers/ieee1394/csr1212.c b/drivers/ieee1394/csr1212.c
index 2fd465ec94ec..4887e4895fd7 100644
--- a/drivers/ieee1394/csr1212.c
+++ b/drivers/ieee1394/csr1212.c
@@ -143,10 +143,9 @@ csr1212_find_keyval(struct csr1212_keyval *dir, struct csr1212_keyval *kv)
143 struct csr1212_dentry *pos; 143 struct csr1212_dentry *pos;
144 144
145 for (pos = dir->value.directory.dentries_head; 145 for (pos = dir->value.directory.dentries_head;
146 pos != NULL; pos = pos->next) { 146 pos != NULL; pos = pos->next)
147 if (pos->kv == kv) 147 if (pos->kv == kv)
148 return pos; 148 return pos;
149 }
150 return NULL; 149 return NULL;
151} 150}
152 151
@@ -155,10 +154,9 @@ csr1212_find_keyval_offset(struct csr1212_keyval *kv_list, u32 offset)
155{ 154{
156 struct csr1212_keyval *kv; 155 struct csr1212_keyval *kv;
157 156
158 for (kv = kv_list->next; kv && (kv != kv_list); kv = kv->next) { 157 for (kv = kv_list->next; kv && (kv != kv_list); kv = kv->next)
159 if (kv->offset == offset) 158 if (kv->offset == offset)
160 return kv; 159 return kv;
161 }
162 return NULL; 160 return NULL;
163} 161}
164 162
@@ -238,8 +236,9 @@ static struct csr1212_keyval *csr1212_new_keyval(u8 type, u8 key)
238 236
239struct csr1212_keyval *csr1212_new_immediate(u8 key, u32 value) 237struct csr1212_keyval *csr1212_new_immediate(u8 key, u32 value)
240{ 238{
241 struct csr1212_keyval *kv = csr1212_new_keyval(CSR1212_KV_TYPE_IMMEDIATE, key); 239 struct csr1212_keyval *kv;
242 240
241 kv = csr1212_new_keyval(CSR1212_KV_TYPE_IMMEDIATE, key);
243 if (!kv) 242 if (!kv)
244 return NULL; 243 return NULL;
245 244
@@ -251,8 +250,9 @@ struct csr1212_keyval *csr1212_new_immediate(u8 key, u32 value)
251static struct csr1212_keyval * 250static struct csr1212_keyval *
252csr1212_new_leaf(u8 key, const void *data, size_t data_len) 251csr1212_new_leaf(u8 key, const void *data, size_t data_len)
253{ 252{
254 struct csr1212_keyval *kv = csr1212_new_keyval(CSR1212_KV_TYPE_LEAF, key); 253 struct csr1212_keyval *kv;
255 254
255 kv = csr1212_new_keyval(CSR1212_KV_TYPE_LEAF, key);
256 if (!kv) 256 if (!kv)
257 return NULL; 257 return NULL;
258 258
@@ -279,8 +279,9 @@ csr1212_new_leaf(u8 key, const void *data, size_t data_len)
279static struct csr1212_keyval * 279static struct csr1212_keyval *
280csr1212_new_csr_offset(u8 key, u32 csr_offset) 280csr1212_new_csr_offset(u8 key, u32 csr_offset)
281{ 281{
282 struct csr1212_keyval *kv = csr1212_new_keyval(CSR1212_KV_TYPE_CSR_OFFSET, key); 282 struct csr1212_keyval *kv;
283 283
284 kv = csr1212_new_keyval(CSR1212_KV_TYPE_CSR_OFFSET, key);
284 if (!kv) 285 if (!kv)
285 return NULL; 286 return NULL;
286 287
@@ -293,8 +294,9 @@ csr1212_new_csr_offset(u8 key, u32 csr_offset)
293 294
294struct csr1212_keyval *csr1212_new_directory(u8 key) 295struct csr1212_keyval *csr1212_new_directory(u8 key)
295{ 296{
296 struct csr1212_keyval *kv = csr1212_new_keyval(CSR1212_KV_TYPE_DIRECTORY, key); 297 struct csr1212_keyval *kv;
297 298
299 kv = csr1212_new_keyval(CSR1212_KV_TYPE_DIRECTORY, key);
298 if (!kv) 300 if (!kv)
299 return NULL; 301 return NULL;
300 302
@@ -316,7 +318,7 @@ void csr1212_associate_keyval(struct csr1212_keyval *kv,
316 associate->key.id != CSR1212_KV_ID_EXTENDED_DATA && 318 associate->key.id != CSR1212_KV_ID_EXTENDED_DATA &&
317 associate->key.id < 0x30) || 319 associate->key.id < 0x30) ||
318 (kv->key.id == CSR1212_KV_ID_EXTENDED_KEY_SPECIFIER_ID && 320 (kv->key.id == CSR1212_KV_ID_EXTENDED_KEY_SPECIFIER_ID &&
319 associate->key.id != CSR1212_KV_ID_EXTENDED_KEY) || 321 associate->key.id != CSR1212_KV_ID_EXTENDED_KEY) ||
320 (kv->key.id == CSR1212_KV_ID_EXTENDED_KEY && 322 (kv->key.id == CSR1212_KV_ID_EXTENDED_KEY &&
321 associate->key.id != CSR1212_KV_ID_EXTENDED_DATA) || 323 associate->key.id != CSR1212_KV_ID_EXTENDED_DATA) ||
322 (associate->key.id == CSR1212_KV_ID_EXTENDED_KEY && 324 (associate->key.id == CSR1212_KV_ID_EXTENDED_KEY &&
@@ -543,11 +545,13 @@ static void csr1212_destroy_keyval(struct csr1212_keyval *kv)
543 a = k->associate; 545 a = k->associate;
544 546
545 if (k->key.type == CSR1212_KV_TYPE_DIRECTORY) { 547 if (k->key.type == CSR1212_KV_TYPE_DIRECTORY) {
546 /* If the current entry is a directory, then move all 548 /* If the current entry is a directory, move all
547 * the entries to the destruction list. */ 549 * the entries to the destruction list. */
548 if (k->value.directory.dentries_head) { 550 if (k->value.directory.dentries_head) {
549 tail->next = k->value.directory.dentries_head; 551 tail->next =
550 k->value.directory.dentries_head->prev = tail; 552 k->value.directory.dentries_head;
553 k->value.directory.dentries_head->prev =
554 tail;
551 tail = k->value.directory.dentries_tail; 555 tail = k->value.directory.dentries_tail;
552 } 556 }
553 } 557 }
@@ -557,12 +561,12 @@ static void csr1212_destroy_keyval(struct csr1212_keyval *kv)
557 561
558 head = head->next; 562 head = head->next;
559 if (head) { 563 if (head) {
560 if (head->prev && head->prev != &dentry) { 564 if (head->prev && head->prev != &dentry)
561 CSR1212_FREE(head->prev); 565 CSR1212_FREE(head->prev);
562 }
563 head->prev = NULL; 566 head->prev = NULL;
564 } else if (tail != &dentry) 567 } else if (tail != &dentry) {
565 CSR1212_FREE(tail); 568 CSR1212_FREE(tail);
569 }
566 } 570 }
567} 571}
568 572
@@ -611,30 +615,34 @@ static int csr1212_append_new_cache(struct csr1212_csr *csr, size_t romsize)
611 /* ROM size must be a multiple of csr->max_rom */ 615 /* ROM size must be a multiple of csr->max_rom */
612 romsize = (romsize + (csr->max_rom - 1)) & ~(csr->max_rom - 1); 616 romsize = (romsize + (csr->max_rom - 1)) & ~(csr->max_rom - 1);
613 617
614 csr_addr = csr->ops->allocate_addr_range(romsize, csr->max_rom, csr->private); 618 csr_addr = csr->ops->allocate_addr_range(romsize, csr->max_rom,
615 if (csr_addr == CSR1212_INVALID_ADDR_SPACE) { 619 csr->private);
620 if (csr_addr == CSR1212_INVALID_ADDR_SPACE)
616 return -ENOMEM; 621 return -ENOMEM;
617 } 622
618 if (csr_addr < CSR1212_REGISTER_SPACE_BASE) { 623 if (csr_addr < CSR1212_REGISTER_SPACE_BASE) {
619 /* Invalid address returned from allocate_addr_range(). */ 624 /* Invalid address returned from allocate_addr_range(). */
620 csr->ops->release_addr(csr_addr, csr->private); 625 csr->ops->release_addr(csr_addr, csr->private);
621 return -ENOMEM; 626 return -ENOMEM;
622 } 627 }
623 628
624 cache = csr1212_rom_cache_malloc(csr_addr - CSR1212_REGISTER_SPACE_BASE, romsize); 629 cache = csr1212_rom_cache_malloc(csr_addr - CSR1212_REGISTER_SPACE_BASE,
630 romsize);
625 if (!cache) { 631 if (!cache) {
626 csr->ops->release_addr(csr_addr, csr->private); 632 csr->ops->release_addr(csr_addr, csr->private);
627 return -ENOMEM; 633 return -ENOMEM;
628 } 634 }
629 635
630 cache->ext_rom = csr1212_new_keyval(CSR1212_KV_TYPE_LEAF, CSR1212_KV_ID_EXTENDED_ROM); 636 cache->ext_rom = csr1212_new_keyval(CSR1212_KV_TYPE_LEAF,
637 CSR1212_KV_ID_EXTENDED_ROM);
631 if (!cache->ext_rom) { 638 if (!cache->ext_rom) {
632 csr->ops->release_addr(csr_addr, csr->private); 639 csr->ops->release_addr(csr_addr, csr->private);
633 CSR1212_FREE(cache); 640 CSR1212_FREE(cache);
634 return -ENOMEM; 641 return -ENOMEM;
635 } 642 }
636 643
637 if (csr1212_attach_keyval_to_directory(csr->root_kv, cache->ext_rom) != CSR1212_SUCCESS) { 644 if (csr1212_attach_keyval_to_directory(csr->root_kv, cache->ext_rom) !=
645 CSR1212_SUCCESS) {
638 csr1212_release_keyval(cache->ext_rom); 646 csr1212_release_keyval(cache->ext_rom);
639 csr->ops->release_addr(csr_addr, csr->private); 647 csr->ops->release_addr(csr_addr, csr->private);
640 CSR1212_FREE(cache); 648 CSR1212_FREE(cache);
@@ -665,7 +673,8 @@ static void csr1212_remove_cache(struct csr1212_csr *csr,
665 cache->next->prev = cache->prev; 673 cache->next->prev = cache->prev;
666 674
667 if (cache->ext_rom) { 675 if (cache->ext_rom) {
668 csr1212_detach_keyval_from_directory(csr->root_kv, cache->ext_rom); 676 csr1212_detach_keyval_from_directory(csr->root_kv,
677 cache->ext_rom);
669 csr1212_release_keyval(cache->ext_rom); 678 csr1212_release_keyval(cache->ext_rom);
670 } 679 }
671 680
@@ -685,28 +694,29 @@ static int csr1212_generate_layout_subdir(struct csr1212_keyval *dir,
685 dentry = dentry->next) { 694 dentry = dentry->next) {
686 for (dkv = dentry->kv; dkv; dkv = dkv->associate) { 695 for (dkv = dentry->kv; dkv; dkv = dkv->associate) {
687 /* Special Case: Extended Key Specifier_ID */ 696 /* Special Case: Extended Key Specifier_ID */
688 if (dkv->key.id == CSR1212_KV_ID_EXTENDED_KEY_SPECIFIER_ID) { 697 if (dkv->key.id ==
689 if (last_extkey_spec == NULL) { 698 CSR1212_KV_ID_EXTENDED_KEY_SPECIFIER_ID) {
699 if (last_extkey_spec == NULL)
690 last_extkey_spec = dkv; 700 last_extkey_spec = dkv;
691 } else if (dkv->value.immediate != last_extkey_spec->value.immediate) { 701 else if (dkv->value.immediate !=
702 last_extkey_spec->value.immediate)
692 last_extkey_spec = dkv; 703 last_extkey_spec = dkv;
693 } else { 704 else
694 continue; 705 continue;
695 }
696 /* Special Case: Extended Key */ 706 /* Special Case: Extended Key */
697 } else if (dkv->key.id == CSR1212_KV_ID_EXTENDED_KEY) { 707 } else if (dkv->key.id == CSR1212_KV_ID_EXTENDED_KEY) {
698 if (last_extkey == NULL) { 708 if (last_extkey == NULL)
699 last_extkey = dkv; 709 last_extkey = dkv;
700 } else if (dkv->value.immediate != last_extkey->value.immediate) { 710 else if (dkv->value.immediate !=
711 last_extkey->value.immediate)
701 last_extkey = dkv; 712 last_extkey = dkv;
702 } else { 713 else
703 continue; 714 continue;
704 }
705 } 715 }
706 716
707 num_entries += 1; 717 num_entries += 1;
708 718
709 switch(dkv->key.type) { 719 switch (dkv->key.type) {
710 default: 720 default:
711 case CSR1212_KV_TYPE_IMMEDIATE: 721 case CSR1212_KV_TYPE_IMMEDIATE:
712 case CSR1212_KV_TYPE_CSR_OFFSET: 722 case CSR1212_KV_TYPE_CSR_OFFSET:
@@ -724,8 +734,9 @@ static int csr1212_generate_layout_subdir(struct csr1212_keyval *dir,
724 /* Special case: Extended ROM leafs */ 734 /* Special case: Extended ROM leafs */
725 if (dkv->key.id == CSR1212_KV_ID_EXTENDED_ROM) { 735 if (dkv->key.id == CSR1212_KV_ID_EXTENDED_ROM) {
726 dkv->value.leaf.len = -1; 736 dkv->value.leaf.len = -1;
727 /* Don't add Extended ROM leafs in the layout list, 737 /* Don't add Extended ROM leafs in the
728 * they are handled differently. */ 738 * layout list, they are handled
739 * differently. */
729 break; 740 break;
730 } 741 }
731 742
@@ -746,15 +757,16 @@ static size_t csr1212_generate_layout_order(struct csr1212_keyval *kv)
746 struct csr1212_keyval *ltail = kv; 757 struct csr1212_keyval *ltail = kv;
747 size_t agg_size = 0; 758 size_t agg_size = 0;
748 759
749 while(kv) { 760 while (kv) {
750 switch(kv->key.type) { 761 switch (kv->key.type) {
751 case CSR1212_KV_TYPE_LEAF: 762 case CSR1212_KV_TYPE_LEAF:
752 /* Add 1 quadlet for crc/len field */ 763 /* Add 1 quadlet for crc/len field */
753 agg_size += kv->value.leaf.len + 1; 764 agg_size += kv->value.leaf.len + 1;
754 break; 765 break;
755 766
756 case CSR1212_KV_TYPE_DIRECTORY: 767 case CSR1212_KV_TYPE_DIRECTORY:
757 kv->value.directory.len = csr1212_generate_layout_subdir(kv, &ltail); 768 kv->value.directory.len =
769 csr1212_generate_layout_subdir(kv, &ltail);
758 /* Add 1 quadlet for crc/len field */ 770 /* Add 1 quadlet for crc/len field */
759 agg_size += kv->value.directory.len + 1; 771 agg_size += kv->value.directory.len + 1;
760 break; 772 break;
@@ -775,13 +787,12 @@ csr1212_generate_positions(struct csr1212_csr_rom_cache *cache,
775 787
776 cache->layout_head = kv; 788 cache->layout_head = kv;
777 789
778 while(kv && pos < cache->size) { 790 while (kv && pos < cache->size) {
779 /* Special case: Extended ROM leafs */ 791 /* Special case: Extended ROM leafs */
780 if (kv->key.id != CSR1212_KV_ID_EXTENDED_ROM) { 792 if (kv->key.id != CSR1212_KV_ID_EXTENDED_ROM)
781 kv->offset = cache->offset + pos; 793 kv->offset = cache->offset + pos;
782 }
783 794
784 switch(kv->key.type) { 795 switch (kv->key.type) {
785 case CSR1212_KV_TYPE_LEAF: 796 case CSR1212_KV_TYPE_LEAF:
786 kv_len = kv->value.leaf.len; 797 kv_len = kv->value.leaf.len;
787 break; 798 break;
@@ -805,7 +816,7 @@ csr1212_generate_positions(struct csr1212_csr_rom_cache *cache,
805 } 816 }
806 817
807 cache->layout_tail = okv; 818 cache->layout_tail = okv;
808 cache->len = (okv->offset - cache->offset) + quads_to_bytes(okv_len + 1); 819 cache->len = okv->offset - cache->offset + quads_to_bytes(okv_len + 1);
809 820
810 return kv; 821 return kv;
811} 822}
@@ -823,33 +834,37 @@ csr1212_generate_tree_subdir(struct csr1212_keyval *dir, u32 *data_buffer)
823 struct csr1212_keyval *last_extkey = NULL; 834 struct csr1212_keyval *last_extkey = NULL;
824 int index = 0; 835 int index = 0;
825 836
826 for (dentry = dir->value.directory.dentries_head; dentry; dentry = dentry->next) { 837 for (dentry = dir->value.directory.dentries_head;
838 dentry;
839 dentry = dentry->next) {
827 struct csr1212_keyval *a; 840 struct csr1212_keyval *a;
828 841
829 for (a = dentry->kv; a; a = a->associate) { 842 for (a = dentry->kv; a; a = a->associate) {
830 u32 value = 0; 843 u32 value = 0;
831 844
832 /* Special Case: Extended Key Specifier_ID */ 845 /* Special Case: Extended Key Specifier_ID */
833 if (a->key.id == CSR1212_KV_ID_EXTENDED_KEY_SPECIFIER_ID) { 846 if (a->key.id ==
834 if (last_extkey_spec == NULL) { 847 CSR1212_KV_ID_EXTENDED_KEY_SPECIFIER_ID) {
848 if (last_extkey_spec == NULL)
835 last_extkey_spec = a; 849 last_extkey_spec = a;
836 } else if (a->value.immediate != last_extkey_spec->value.immediate) { 850 else if (a->value.immediate !=
851 last_extkey_spec->value.immediate)
837 last_extkey_spec = a; 852 last_extkey_spec = a;
838 } else { 853 else
839 continue; 854 continue;
840 } 855
841 /* Special Case: Extended Key */ 856 /* Special Case: Extended Key */
842 } else if (a->key.id == CSR1212_KV_ID_EXTENDED_KEY) { 857 } else if (a->key.id == CSR1212_KV_ID_EXTENDED_KEY) {
843 if (last_extkey == NULL) { 858 if (last_extkey == NULL)
844 last_extkey = a; 859 last_extkey = a;
845 } else if (a->value.immediate != last_extkey->value.immediate) { 860 else if (a->value.immediate !=
861 last_extkey->value.immediate)
846 last_extkey = a; 862 last_extkey = a;
847 } else { 863 else
848 continue; 864 continue;
849 }
850 } 865 }
851 866
852 switch(a->key.type) { 867 switch (a->key.type) {
853 case CSR1212_KV_TYPE_IMMEDIATE: 868 case CSR1212_KV_TYPE_IMMEDIATE:
854 value = a->value.immediate; 869 value = a->value.immediate;
855 break; 870 break;
@@ -871,9 +886,11 @@ csr1212_generate_tree_subdir(struct csr1212_keyval *dir, u32 *data_buffer)
871 break; /* GDB breakpoint */ 886 break; /* GDB breakpoint */
872 } 887 }
873 888
874 value |= (a->key.id & CSR1212_KV_KEY_ID_MASK) << CSR1212_KV_KEY_SHIFT; 889 value |= (a->key.id & CSR1212_KV_KEY_ID_MASK) <<
890 CSR1212_KV_KEY_SHIFT;
875 value |= (a->key.type & CSR1212_KV_KEY_TYPE_MASK) << 891 value |= (a->key.type & CSR1212_KV_KEY_TYPE_MASK) <<
876 (CSR1212_KV_KEY_SHIFT + CSR1212_KV_KEY_TYPE_SHIFT); 892 (CSR1212_KV_KEY_SHIFT +
893 CSR1212_KV_KEY_TYPE_SHIFT);
877 data_buffer[index] = cpu_to_be32(value); 894 data_buffer[index] = cpu_to_be32(value);
878 index++; 895 index++;
879 } 896 }
@@ -893,10 +910,12 @@ static void csr1212_fill_cache(struct csr1212_csr_rom_cache *cache)
893 struct csr1212_keyval *kv, *nkv; 910 struct csr1212_keyval *kv, *nkv;
894 struct csr1212_keyval_img *kvi; 911 struct csr1212_keyval_img *kvi;
895 912
896 for (kv = cache->layout_head; kv != cache->layout_tail->next; kv = nkv) { 913 for (kv = cache->layout_head;
897 kvi = (struct csr1212_keyval_img *) 914 kv != cache->layout_tail->next;
898 (cache->data + bytes_to_quads(kv->offset - cache->offset)); 915 kv = nkv) {
899 switch(kv->key.type) { 916 kvi = (struct csr1212_keyval_img *)(cache->data +
917 bytes_to_quads(kv->offset - cache->offset));
918 switch (kv->key.type) {
900 default: 919 default:
901 case CSR1212_KV_TYPE_IMMEDIATE: 920 case CSR1212_KV_TYPE_IMMEDIATE:
902 case CSR1212_KV_TYPE_CSR_OFFSET: 921 case CSR1212_KV_TYPE_CSR_OFFSET:
@@ -918,7 +937,8 @@ static void csr1212_fill_cache(struct csr1212_csr_rom_cache *cache)
918 csr1212_generate_tree_subdir(kv, kvi->data); 937 csr1212_generate_tree_subdir(kv, kvi->data);
919 938
920 kvi->length = cpu_to_be16(kv->value.directory.len); 939 kvi->length = cpu_to_be16(kv->value.directory.len);
921 kvi->crc = csr1212_crc16(kvi->data, kv->value.directory.len); 940 kvi->crc = csr1212_crc16(kvi->data,
941 kv->value.directory.len);
922 break; 942 break;
923 } 943 }
924 944
@@ -962,7 +982,9 @@ int csr1212_generate_csr_image(struct csr1212_csr *csr)
962 982
963 init_offset = csr->bus_info_len; 983 init_offset = csr->bus_info_len;
964 984
965 for (kv = csr->root_kv, cache = csr->cache_head; kv; cache = cache->next) { 985 for (kv = csr->root_kv, cache = csr->cache_head;
986 kv;
987 cache = cache->next) {
966 if (!cache) { 988 if (!cache) {
967 /* Estimate approximate number of additional cache 989 /* Estimate approximate number of additional cache
968 * regions needed (it assumes that the cache holding 990 * regions needed (it assumes that the cache holding
@@ -973,7 +995,8 @@ int csr1212_generate_csr_image(struct csr1212_csr *csr)
973 /* Add additional cache regions, extras will be 995 /* Add additional cache regions, extras will be
974 * removed later */ 996 * removed later */
975 for (; est_c; est_c--) { 997 for (; est_c; est_c--) {
976 ret = csr1212_append_new_cache(csr, CSR1212_EXTENDED_ROM_SIZE); 998 ret = csr1212_append_new_cache(csr,
999 CSR1212_EXTENDED_ROM_SIZE);
977 if (ret != CSR1212_SUCCESS) 1000 if (ret != CSR1212_SUCCESS)
978 return ret; 1001 return ret;
979 } 1002 }
@@ -998,7 +1021,7 @@ int csr1212_generate_csr_image(struct csr1212_csr *csr)
998 1021
999 /* Go through the list backward so that when done, the correct CRC 1022 /* Go through the list backward so that when done, the correct CRC
1000 * will be calculated for the Extended ROM areas. */ 1023 * will be calculated for the Extended ROM areas. */
1001 for(cache = csr->cache_tail; cache; cache = cache->prev) { 1024 for (cache = csr->cache_tail; cache; cache = cache->prev) {
1002 /* Only Extended ROM caches should have this set. */ 1025 /* Only Extended ROM caches should have this set. */
1003 if (cache->ext_rom) { 1026 if (cache->ext_rom) {
1004 int leaf_size; 1027 int leaf_size;
@@ -1046,15 +1069,15 @@ int csr1212_read(struct csr1212_csr *csr, u32 offset, void *buffer, u32 len)
1046{ 1069{
1047 struct csr1212_csr_rom_cache *cache; 1070 struct csr1212_csr_rom_cache *cache;
1048 1071
1049 for (cache = csr->cache_head; cache; cache = cache->next) { 1072 for (cache = csr->cache_head; cache; cache = cache->next)
1050 if (offset >= cache->offset && 1073 if (offset >= cache->offset &&
1051 (offset + len) <= (cache->offset + cache->size)) { 1074 (offset + len) <= (cache->offset + cache->size)) {
1052 memcpy(buffer, 1075 memcpy(buffer, &cache->data[
1053 &cache->data[bytes_to_quads(offset - cache->offset)], 1076 bytes_to_quads(offset - cache->offset)],
1054 len); 1077 len);
1055 return CSR1212_SUCCESS; 1078 return CSR1212_SUCCESS;
1056 } 1079 }
1057 } 1080
1058 return -ENOENT; 1081 return -ENOENT;
1059} 1082}
1060 1083
@@ -1075,9 +1098,8 @@ static int csr1212_parse_bus_info_block(struct csr1212_csr *csr)
1075 * ConfigROM will be read according to the max_rom field. */ 1098 * ConfigROM will be read according to the max_rom field. */
1076 for (i = 0; i < csr->bus_info_len; i += sizeof(u32)) { 1099 for (i = 0; i < csr->bus_info_len; i += sizeof(u32)) {
1077 ret = csr->ops->bus_read(csr, CSR1212_CONFIG_ROM_SPACE_BASE + i, 1100 ret = csr->ops->bus_read(csr, CSR1212_CONFIG_ROM_SPACE_BASE + i,
1078 sizeof(u32), 1101 sizeof(u32), &csr->cache_head->data[bytes_to_quads(i)],
1079 &csr->cache_head->data[bytes_to_quads(i)], 1102 csr->private);
1080 csr->private);
1081 if (ret != CSR1212_SUCCESS) 1103 if (ret != CSR1212_SUCCESS)
1082 return ret; 1104 return ret;
1083 1105
@@ -1091,13 +1113,13 @@ static int csr1212_parse_bus_info_block(struct csr1212_csr *csr)
1091 bi = (struct csr1212_bus_info_block_img*)csr->cache_head->data; 1113 bi = (struct csr1212_bus_info_block_img*)csr->cache_head->data;
1092 csr->crc_len = quads_to_bytes(bi->crc_length); 1114 csr->crc_len = quads_to_bytes(bi->crc_length);
1093 1115
1094 /* IEEE 1212 recommends that crc_len be equal to bus_info_len, but that is not 1116 /* IEEE 1212 recommends that crc_len be equal to bus_info_len, but that
1095 * always the case, so read the rest of the crc area 1 quadlet at a time. */ 1117 * is not always the case, so read the rest of the crc area 1 quadlet at
1118 * a time. */
1096 for (i = csr->bus_info_len; i <= csr->crc_len; i += sizeof(u32)) { 1119 for (i = csr->bus_info_len; i <= csr->crc_len; i += sizeof(u32)) {
1097 ret = csr->ops->bus_read(csr, CSR1212_CONFIG_ROM_SPACE_BASE + i, 1120 ret = csr->ops->bus_read(csr, CSR1212_CONFIG_ROM_SPACE_BASE + i,
1098 sizeof(u32), 1121 sizeof(u32), &csr->cache_head->data[bytes_to_quads(i)],
1099 &csr->cache_head->data[bytes_to_quads(i)], 1122 csr->private);
1100 csr->private);
1101 if (ret != CSR1212_SUCCESS) 1123 if (ret != CSR1212_SUCCESS)
1102 return ret; 1124 return ret;
1103 } 1125 }
@@ -1131,14 +1153,14 @@ static int csr1212_parse_bus_info_block(struct csr1212_csr *csr)
1131#define CSR1212_KV_VAL_MASK 0xffffff 1153#define CSR1212_KV_VAL_MASK 0xffffff
1132#define CSR1212_KV_VAL(q) (be32_to_cpu(q) & CSR1212_KV_VAL_MASK) 1154#define CSR1212_KV_VAL(q) (be32_to_cpu(q) & CSR1212_KV_VAL_MASK)
1133 1155
1134static int csr1212_parse_dir_entry(struct csr1212_keyval *dir, 1156static int
1135 u32 ki, u32 kv_pos) 1157csr1212_parse_dir_entry(struct csr1212_keyval *dir, u32 ki, u32 kv_pos)
1136{ 1158{
1137 int ret = CSR1212_SUCCESS; 1159 int ret = CSR1212_SUCCESS;
1138 struct csr1212_keyval *k = NULL; 1160 struct csr1212_keyval *k = NULL;
1139 u32 offset; 1161 u32 offset;
1140 1162
1141 switch(CSR1212_KV_KEY_TYPE(ki)) { 1163 switch (CSR1212_KV_KEY_TYPE(ki)) {
1142 case CSR1212_KV_TYPE_IMMEDIATE: 1164 case CSR1212_KV_TYPE_IMMEDIATE:
1143 k = csr1212_new_immediate(CSR1212_KV_KEY_ID(ki), 1165 k = csr1212_new_immediate(CSR1212_KV_KEY_ID(ki),
1144 CSR1212_KV_VAL(ki)); 1166 CSR1212_KV_VAL(ki));
@@ -1176,11 +1198,11 @@ static int csr1212_parse_dir_entry(struct csr1212_keyval *dir,
1176 if (k) 1198 if (k)
1177 break; /* Found it. */ 1199 break; /* Found it. */
1178 1200
1179 if (CSR1212_KV_KEY_TYPE(ki) == CSR1212_KV_TYPE_DIRECTORY) { 1201 if (CSR1212_KV_KEY_TYPE(ki) == CSR1212_KV_TYPE_DIRECTORY)
1180 k = csr1212_new_directory(CSR1212_KV_KEY_ID(ki)); 1202 k = csr1212_new_directory(CSR1212_KV_KEY_ID(ki));
1181 } else { 1203 else
1182 k = csr1212_new_leaf(CSR1212_KV_KEY_ID(ki), NULL, 0); 1204 k = csr1212_new_leaf(CSR1212_KV_KEY_ID(ki), NULL, 0);
1183 } 1205
1184 if (!k) { 1206 if (!k) {
1185 ret = -ENOMEM; 1207 ret = -ENOMEM;
1186 goto fail; 1208 goto fail;
@@ -1210,8 +1232,8 @@ int csr1212_parse_keyval(struct csr1212_keyval *kv,
1210 int ret = CSR1212_SUCCESS; 1232 int ret = CSR1212_SUCCESS;
1211 int kvi_len; 1233 int kvi_len;
1212 1234
1213 kvi = (struct csr1212_keyval_img*)&cache->data[bytes_to_quads(kv->offset - 1235 kvi = (struct csr1212_keyval_img*)
1214 cache->offset)]; 1236 &cache->data[bytes_to_quads(kv->offset - cache->offset)];
1215 kvi_len = be16_to_cpu(kvi->length); 1237 kvi_len = be16_to_cpu(kvi->length);
1216 1238
1217#if 0 1239#if 0
@@ -1224,7 +1246,7 @@ int csr1212_parse_keyval(struct csr1212_keyval *kv,
1224 } 1246 }
1225#endif 1247#endif
1226 1248
1227 switch(kv->key.type) { 1249 switch (kv->key.type) {
1228 case CSR1212_KV_TYPE_DIRECTORY: 1250 case CSR1212_KV_TYPE_DIRECTORY:
1229 for (i = 0; i < kvi_len; i++) { 1251 for (i = 0; i < kvi_len; i++) {
1230 u32 ki = kvi->data[i]; 1252 u32 ki = kvi->data[i];
@@ -1235,22 +1257,23 @@ int csr1212_parse_keyval(struct csr1212_keyval *kv,
1235 if (ki == 0x0) 1257 if (ki == 0x0)
1236 continue; 1258 continue;
1237 ret = csr1212_parse_dir_entry(kv, ki, 1259 ret = csr1212_parse_dir_entry(kv, ki,
1238 (kv->offset + 1260 kv->offset + quads_to_bytes(i + 1));
1239 quads_to_bytes(i + 1)));
1240 } 1261 }
1241 kv->value.directory.len = kvi_len; 1262 kv->value.directory.len = kvi_len;
1242 break; 1263 break;
1243 1264
1244 case CSR1212_KV_TYPE_LEAF: 1265 case CSR1212_KV_TYPE_LEAF:
1245 if (kv->key.id != CSR1212_KV_ID_EXTENDED_ROM) { 1266 if (kv->key.id != CSR1212_KV_ID_EXTENDED_ROM) {
1246 kv->value.leaf.data = CSR1212_MALLOC(quads_to_bytes(kvi_len)); 1267 size_t size = quads_to_bytes(kvi_len);
1268
1269 kv->value.leaf.data = CSR1212_MALLOC(size);
1247 if (!kv->value.leaf.data) { 1270 if (!kv->value.leaf.data) {
1248 ret = -ENOMEM; 1271 ret = -ENOMEM;
1249 goto fail; 1272 goto fail;
1250 } 1273 }
1251 1274
1252 kv->value.leaf.len = kvi_len; 1275 kv->value.leaf.len = kvi_len;
1253 memcpy(kv->value.leaf.data, kvi->data, quads_to_bytes(kvi_len)); 1276 memcpy(kv->value.leaf.data, kvi->data, size);
1254 } 1277 }
1255 break; 1278 break;
1256 } 1279 }
@@ -1276,11 +1299,10 @@ csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv)
1276 1299
1277 /* First find which cache the data should be in (or go in if not read 1300 /* First find which cache the data should be in (or go in if not read
1278 * yet). */ 1301 * yet). */
1279 for (cache = csr->cache_head; cache; cache = cache->next) { 1302 for (cache = csr->cache_head; cache; cache = cache->next)
1280 if (kv->offset >= cache->offset && 1303 if (kv->offset >= cache->offset &&
1281 kv->offset < (cache->offset + cache->size)) 1304 kv->offset < (cache->offset + cache->size))
1282 break; 1305 break;
1283 }
1284 1306
1285 if (!cache) { 1307 if (!cache) {
1286 u32 q, cache_size; 1308 u32 q, cache_size;
@@ -1291,9 +1313,8 @@ csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv)
1291 1313
1292 if (csr->ops->bus_read(csr, 1314 if (csr->ops->bus_read(csr,
1293 CSR1212_REGISTER_SPACE_BASE + kv->offset, 1315 CSR1212_REGISTER_SPACE_BASE + kv->offset,
1294 sizeof(u32), &q, csr->private)) { 1316 sizeof(u32), &q, csr->private))
1295 return -EIO; 1317 return -EIO;
1296 }
1297 1318
1298 kv->value.leaf.len = be32_to_cpu(q) >> 16; 1319 kv->value.leaf.len = be32_to_cpu(q) >> 16;
1299 1320
@@ -1311,9 +1332,8 @@ csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv)
1311 csr->cache_tail = cache; 1332 csr->cache_tail = cache;
1312 cache->filled_head = 1333 cache->filled_head =
1313 CSR1212_MALLOC(sizeof(*cache->filled_head)); 1334 CSR1212_MALLOC(sizeof(*cache->filled_head));
1314 if (!cache->filled_head) { 1335 if (!cache->filled_head)
1315 return -ENOMEM; 1336 return -ENOMEM;
1316 }
1317 1337
1318 cache->filled_head->offset_start = 0; 1338 cache->filled_head->offset_start = 0;
1319 cache->filled_head->offset_end = sizeof(u32); 1339 cache->filled_head->offset_end = sizeof(u32);
@@ -1349,8 +1369,9 @@ csr1212_read_keyval(struct csr1212_csr *csr, struct csr1212_keyval *kv)
1349 (&cache->data[bytes_to_quads(cache_index)]); 1369 (&cache->data[bytes_to_quads(cache_index)]);
1350 kv_len = quads_to_bytes(be16_to_cpu(kvi->length) + 1); 1370 kv_len = quads_to_bytes(be16_to_cpu(kvi->length) + 1);
1351 break; 1371 break;
1352 } else if (cache_index == cr->offset_end) 1372 } else if (cache_index == cr->offset_end) {
1353 break; 1373 break;
1374 }
1354 } 1375 }
1355 1376
1356 if (!cr) { 1377 if (!cr) {
@@ -1446,9 +1467,9 @@ int csr1212_parse_csr(struct csr1212_csr *csr)
1446 if (ret != CSR1212_SUCCESS) 1467 if (ret != CSR1212_SUCCESS)
1447 return ret; 1468 return ret;
1448 1469
1449 if (!csr->ops->get_max_rom) 1470 if (!csr->ops->get_max_rom) {
1450 csr->max_rom = mr_map[0]; /* default value */ 1471 csr->max_rom = mr_map[0]; /* default value */
1451 else { 1472 } else {
1452 int i = csr->ops->get_max_rom(csr->bus_info_data, 1473 int i = csr->ops->get_max_rom(csr->bus_info_data,
1453 csr->private); 1474 csr->private);
1454 if (i & ~0x3) 1475 if (i & ~0x3)
diff --git a/drivers/ieee1394/csr1212.h b/drivers/ieee1394/csr1212.h
index cc23f3abe0cd..df909ce66304 100644
--- a/drivers/ieee1394/csr1212.h
+++ b/drivers/ieee1394/csr1212.h
@@ -224,7 +224,8 @@ struct csr1212_bus_ops {
224#define CSR1212_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u32)) 224#define CSR1212_DESCRIPTOR_LEAF_OVERHEAD (1 * sizeof(u32))
225 225
226#define CSR1212_DESCRIPTOR_LEAF_TYPE(kv) \ 226#define CSR1212_DESCRIPTOR_LEAF_TYPE(kv) \
227 (be32_to_cpu((kv)->value.leaf.data[0]) >> CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT) 227 (be32_to_cpu((kv)->value.leaf.data[0]) >> \
228 CSR1212_DESCRIPTOR_LEAF_TYPE_SHIFT)
228#define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) \ 229#define CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID(kv) \
229 (be32_to_cpu((kv)->value.leaf.data[0]) & \ 230 (be32_to_cpu((kv)->value.leaf.data[0]) & \
230 CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK) 231 CSR1212_DESCRIPTOR_LEAF_SPECIFIER_ID_MASK)
@@ -364,24 +365,22 @@ extern void csr1212_release_keyval(struct csr1212_keyval *kv);
364 * This macro allows for looping over the keyval entries in a directory and it 365 * This macro allows for looping over the keyval entries in a directory and it
365 * ensures that keyvals from remote ConfigROMs are parsed properly. 366 * ensures that keyvals from remote ConfigROMs are parsed properly.
366 * 367 *
367 * _csr is a struct csr1212_csr * that points to CSR associated with dir. 368 * struct csr1212_csr *_csr points to the CSR associated with dir.
368 * _kv is a struct csr1212_keyval * that'll point to the current keyval (loop index). 369 * struct csr1212_keyval *_kv points to the current keyval (loop index).
369 * _dir is a struct csr1212_keyval * that points to the directory to be looped. 370 * struct csr1212_keyval *_dir points to the directory to be looped.
370 * _pos is a struct csr1212_dentry * that is used internally for indexing. 371 * struct csr1212_dentry *_pos is used internally for indexing.
371 * 372 *
372 * kv will be NULL upon exit of the loop. 373 * kv will be NULL upon exit of the loop.
373 */ 374 */
374#define csr1212_for_each_dir_entry(_csr, _kv, _dir, _pos) \ 375#define csr1212_for_each_dir_entry(_csr, _kv, _dir, _pos) \
375 for (csr1212_get_keyval((_csr), (_dir)), \ 376 for (csr1212_get_keyval((_csr), (_dir)), \
376 _pos = (_dir)->value.directory.dentries_head, \ 377 _pos = (_dir)->value.directory.dentries_head, \
377 _kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : NULL; \ 378 _kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : NULL;\
378 (_kv) && (_pos); \ 379 (_kv) && (_pos); \
379 (_kv->associate == NULL) ? \ 380 (_kv->associate == NULL) ? \
380 ((_pos = _pos->next), \ 381 ((_pos = _pos->next), (_kv = (_pos) ? \
381 (_kv = (_pos) ? csr1212_get_keyval((_csr), _pos->kv) : \ 382 csr1212_get_keyval((_csr), _pos->kv) : \
382 NULL)) : \ 383 NULL)) : \
383 (_kv = csr1212_get_keyval((_csr), _kv->associate))) 384 (_kv = csr1212_get_keyval((_csr), _kv->associate)))
384 385
385
386
387#endif /* __CSR1212_H__ */ 386#endif /* __CSR1212_H__ */