~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/drivers/apm/apm_i2c.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/apm/apm_i2c.c,v 1.7 2002/01/25 21:55:55 tsi Exp $ */
 
2
 
 
3
#include "apm.h"
 
4
#include "apm_regs.h"
 
5
 
 
6
/* Inline functions */
 
7
static __inline__ void
 
8
WaitForFifo(ApmPtr pApm, int slots)
 
9
{
 
10
  if (!pApm->UsePCIRetry) {
 
11
    volatile int i;
 
12
#define MAXLOOP 1000000
 
13
 
 
14
    for(i = 0; i < MAXLOOP; i++) {
 
15
      if ((STATUS_IOP() & STATUS_FIFO) >= slots)
 
16
        break;
 
17
    }
 
18
    if (i == MAXLOOP) {
 
19
      unsigned int status = STATUS_IOP();
 
20
 
 
21
      WRXB_IOP(0x1FF, 0);
 
22
      FatalError("Hung in WaitForFifo() (Status = 0x%08X)\n", status);
 
23
    }
 
24
  }
 
25
}
 
26
 
 
27
static void
 
28
ApmI2CPutBits(I2CBusPtr b, int clock,  int data)
 
29
{
 
30
    unsigned int        reg;
 
31
    unsigned char       lock;
 
32
    ApmPtr pApm = ((ApmPtr)b->DriverPrivate.ptr);
 
33
 
 
34
    lock = rdinx(pApm->xport, 0x10);
 
35
    wrinx(pApm->xport, 0x10, 0x12);
 
36
    WaitForFifo(pApm, 2);
 
37
    reg = (RDXB_IOP(0xD0) & 0x07) | 0x60;
 
38
    if(clock) reg |= 0x08;
 
39
    if(data)  reg |= 0x10;
 
40
    WRXB_IOP(0xD0, reg);
 
41
    if (lock)
 
42
        wrinx(pApm->xport, 0x10, 0);
 
43
}
 
44
 
 
45
static void
 
46
ApmI2CGetBits(I2CBusPtr b, int *clock, int *data)
 
47
{
 
48
    unsigned int        reg;
 
49
    unsigned char       lock;
 
50
    ApmPtr pApm = ((ApmPtr)b->DriverPrivate.ptr);
 
51
    unsigned char       tmp;
 
52
 
 
53
    lock = rdinx(pApm->xport, 0x10);
 
54
    wrinx(pApm->xport, 0x10, 0x12);
 
55
    WaitForFifo(pApm, 2);
 
56
    tmp = RDXB_IOP(0xD0);
 
57
    WRXB_IOP(0xD0, tmp & 0x07);
 
58
    reg = STATUS_IOP();
 
59
    *clock = (reg & STATUS_SCL) != 0;
 
60
    *data  = (reg & STATUS_SDA) != 0;
 
61
    if (lock)
 
62
        wrinx(pApm->xport, 0x10, 0);
 
63
}
 
64
 
 
65
Bool 
 
66
ApmI2CInit(ScrnInfoPtr pScrn)
 
67
{
 
68
    APMDECL(pScrn);
 
69
    I2CBusPtr I2CPtr;
 
70
 
 
71
    I2CPtr = xf86CreateI2CBusRec();
 
72
    if(!I2CPtr) return FALSE;
 
73
 
 
74
    pApm->I2CPtr        = I2CPtr;
 
75
 
 
76
    I2CPtr->BusName    = "Alliance bus";
 
77
    I2CPtr->scrnIndex  = pScrn->scrnIndex;
 
78
    I2CPtr->I2CPutBits = ApmI2CPutBits;
 
79
    I2CPtr->I2CGetBits = ApmI2CGetBits;
 
80
    I2CPtr->DriverPrivate.ptr = pApm;
 
81
    
 
82
    if(!xf86I2CBusInit(I2CPtr))
 
83
       return FALSE;
 
84
 
 
85
    return TRUE;
 
86
}