source: rtems/c/src/lib/libbsp/powerpc/shared/residual/residual.c @ e79a1947

4.104.114.84.95
Last change on this file since e79a1947 was f05b2ac, checked in by Ralf Corsepius <ralf.corsepius@…>, on 04/21/04 at 16:01:48

Remove duplicate white lines.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 * residual.c : function used to parse residual data.
3 *
4 *  CopyRight (C) 1999 valette@crf.canon.fr
5 *
6 *  This code is heavilly inspired by the public specification of STREAM V2
7 *  that can be found at :
8 *
9 *  The license and distribution terms for this file may be
10 *  found in found in the file LICENSE in this distribution or at
11 *  http://www.rtems.com/license/LICENSE.
12 *
13 *  $Id$
14 */
15
16#include <string.h>
17
18#include <bsp/residual.h>
19#include <libcpu/io.h>
20#include <libcpu/byteorder.h>
21
22static int same_DevID(unsigned short vendor,
23               unsigned short Number,
24               char * str)
25{
26        static unsigned const char hexdigit[]="0123456789ABCDEF";
27        if (strlen(str)!=7) return 0;
28        if ( ( ((vendor>>10)&0x1f)+'A'-1 == str[0])  &&
29             ( ((vendor>>5)&0x1f)+'A'-1 == str[1])   &&
30             ( (vendor&0x1f)+'A'-1 == str[2])        &&
31             (hexdigit[(Number>>12)&0x0f] == str[3]) &&
32             (hexdigit[(Number>>8)&0x0f] == str[4])  &&
33             (hexdigit[(Number>>4)&0x0f] == str[5])  &&
34             (hexdigit[Number&0x0f] == str[6]) ) return 1;
35        return 0;
36}
37
38PPC_DEVICE *residual_find_device(RESIDUAL *res,unsigned long BusMask,
39                                 unsigned char * DevID,
40                                 int BaseType,
41                                 int SubType,
42                                 int Interface,
43                                 int n)
44{
45        int i;
46        if ( !res || !res->ResidualLength ) return NULL;
47        for (i=0; i<res->ActualNumDevices; i++) {
48#define Dev res->Devices[i].DeviceId
49                if ( (Dev.BusId&BusMask)                                  &&
50                     (BaseType==-1 || Dev.BaseType==BaseType)             &&
51                     (SubType==-1 || Dev.SubType==SubType)                &&
52                     (Interface==-1 || Dev.Interface==Interface)          &&
53                     (DevID==NULL || same_DevID((Dev.DevId>>16)&0xffff,
54                                                Dev.DevId&0xffff, DevID)) &&
55                     !(n--) ) return res->Devices+i;
56#undef Dev
57        }
58        return 0;
59}
60
61PnP_TAG_PACKET *PnP_find_packet(unsigned char *p,
62                                unsigned packet_tag,
63                                int n)
64{
65        unsigned mask, masked_tag, size;
66        if(!p) return 0;
67        if (tag_type(packet_tag)) mask=0xff; else mask=0xF8;
68        masked_tag = packet_tag&mask;
69        for(; *p != END_TAG; p+=size) {
70                if ((*p & mask) == masked_tag && !(n--))
71                        return (PnP_TAG_PACKET *) p;
72                if (tag_type(*p))
73                        size=ld_le16((unsigned short *)(p+1))+3;
74                else
75                        size=tag_small_count(*p)+1;
76        }
77        return 0; /* not found */
78}
79
80PnP_TAG_PACKET *PnP_find_small_vendor_packet(unsigned char *p,
81                                             unsigned packet_type,
82                                             int n)
83{
84        int next=0;
85        while (p) {
86                p = (unsigned char *) PnP_find_packet(p, 0x70, next);
87                if (p && p[1]==packet_type && !(n--))
88                        return (PnP_TAG_PACKET *) p;
89                next = 1;
90        };
91        return 0; /* not found */
92}
93
94PnP_TAG_PACKET *PnP_find_large_vendor_packet(unsigned char *p,
95                                           unsigned packet_type,
96                                           int n)
97{
98        int next=0;
99        while (p) {
100                p = (unsigned char *) PnP_find_packet(p, 0x84, next);
101                if (p && p[3]==packet_type && !(n--))
102                        return (PnP_TAG_PACKET *) p;
103                next = 1;
104        };
105        return 0; /* not found */
106}
Note: See TracBrowser for help on using the repository browser.