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

Last change on this file since 116633f was 116633f, checked in by Joel Sherrill <joel.sherrill@…>, on 09/04/03 at 18:45:20

2003-09-04 Joel Sherrill <joel@…>

  • bootloader/bootldr.h, bootloader/em86.c, bootloader/em86real.S, bootloader/exception.S, bootloader/head.S, bootloader/lib.c, bootloader/misc.c, bootloader/mm.c, bootloader/pci.c, clock/p_clock.c, console/console.c, console/consoleIo.h, console/inch.c, console/keyboard.h, console/polled_io.c, include/bsp.h, irq/i8259.c, irq/irq.c, irq/irq.h, irq/irq_asm.S, irq/irq_init.c, motorola/motorola.c, motorola/motorola.h, openpic/openpic.c, openpic/openpic.h, pci/pci.c, residual/residual.c, start/start.S, startup/bspstart.c, vectors/vectors.h, vectors/vectors_init.c: URL for license changed.
  • 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
22
23static int same_DevID(unsigned short vendor,
24               unsigned short Number,
25               char * str)
26{
27        static unsigned const char hexdigit[]="0123456789ABCDEF";
28        if (strlen(str)!=7) return 0;
29        if ( ( ((vendor>>10)&0x1f)+'A'-1 == str[0])  &&
30             ( ((vendor>>5)&0x1f)+'A'-1 == str[1])   &&
31             ( (vendor&0x1f)+'A'-1 == str[2])        &&
32             (hexdigit[(Number>>12)&0x0f] == str[3]) &&
33             (hexdigit[(Number>>8)&0x0f] == str[4])  &&
34             (hexdigit[(Number>>4)&0x0f] == str[5])  &&
35             (hexdigit[Number&0x0f] == str[6]) ) return 1;
36        return 0;
37}
38
39PPC_DEVICE *residual_find_device(RESIDUAL *res,unsigned long BusMask,
40                                 unsigned char * DevID,
41                                 int BaseType,
42                                 int SubType,
43                                 int Interface,
44                                 int n)
45{
46        int i;
47        if ( !res || !res->ResidualLength ) return NULL;
48        for (i=0; i<res->ActualNumDevices; i++) {
49#define Dev res->Devices[i].DeviceId
50                if ( (Dev.BusId&BusMask)                                  &&
51                     (BaseType==-1 || Dev.BaseType==BaseType)             &&
52                     (SubType==-1 || Dev.SubType==SubType)                &&
53                     (Interface==-1 || Dev.Interface==Interface)          &&
54                     (DevID==NULL || same_DevID((Dev.DevId>>16)&0xffff,
55                                                Dev.DevId&0xffff, DevID)) &&
56                     !(n--) ) return res->Devices+i;
57#undef Dev
58        }
59        return 0;
60}
61
62PnP_TAG_PACKET *PnP_find_packet(unsigned char *p,
63                                unsigned packet_tag,
64                                int n)
65{
66        unsigned mask, masked_tag, size;
67        if(!p) return 0;
68        if (tag_type(packet_tag)) mask=0xff; else mask=0xF8;
69        masked_tag = packet_tag&mask;
70        for(; *p != END_TAG; p+=size) {
71                if ((*p & mask) == masked_tag && !(n--))
72                        return (PnP_TAG_PACKET *) p;
73                if (tag_type(*p))
74                        size=ld_le16((unsigned short *)(p+1))+3;
75                else
76                        size=tag_small_count(*p)+1;
77        }
78        return 0; /* not found */
79}
80
81PnP_TAG_PACKET *PnP_find_small_vendor_packet(unsigned char *p,
82                                             unsigned packet_type,
83                                             int n)
84{
85        int next=0;
86        while (p) {
87                p = (unsigned char *) PnP_find_packet(p, 0x70, next);
88                if (p && p[1]==packet_type && !(n--))
89                        return (PnP_TAG_PACKET *) p;
90                next = 1;
91        };
92        return 0; /* not found */
93}
94
95PnP_TAG_PACKET *PnP_find_large_vendor_packet(unsigned char *p,
96                                           unsigned packet_type,
97                                           int n)
98{
99        int next=0;
100        while (p) {
101                p = (unsigned char *) PnP_find_packet(p, 0x84, next);
102                if (p && p[3]==packet_type && !(n--))
103                        return (PnP_TAG_PACKET *) p;
104                next = 1;
105        };
106        return 0; /* not found */
107}
108
Note: See TracBrowser for help on using the repository browser.