Rename drivers to their right name
[reactos.git] / reactos / drivers / usb / miniport / linux / boot.h
1 #ifndef _Boot_H_
2 #define _Boot_H_
3
4 #include "config.h"
5
6 /***************************************************************************
7 Includes used by XBox boot code
8 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 /////////////////////////////////
19 // configuration
20
21 #include "consts.h"
22 #include "stdint.h"
23 #include "cromwell_types.h"
24
25
26 unsigned int cromwell_config;
27 unsigned int cromwell_retryload;
28 unsigned int cromwell_loadbank;
29 unsigned int cromwell_Biostype;
30
31 unsigned int xbox_ram;
32
33 #define XROMWELL 0
34 #define CROMWELL 1
35
36 #define ICON_WIDTH 64
37 #define ICON_HEIGHT 64
38 /*
39 static double min (double a, double b)
40 {
41 if (a < b) return a; else return b;
42 }
43
44 static inline double max (double a, double b)
45 {
46 if (a > b) return a; else return b;
47 }
48 */
49 //#include "iso_fs.h"
50 //#include "BootVideo.h"
51
52 //#define ASSERT(exp) { if(!(exp)) { bprintf("Assert failed file " __FILE__ " line %d\n", __LINE__); } }
53
54 #if 0
55 extern volatile CURRENT_VIDEO_MODE_DETAILS vmode;
56 unsigned int video_encoder;
57
58 volatile u32 VIDEO_CURSOR_POSX;
59 volatile u32 VIDEO_CURSOR_POSY;
60 volatile u32 VIDEO_ATTR;
61 volatile u32 VIDEO_LUMASCALING;
62 volatile u32 VIDEO_RSCALING;
63 volatile u32 VIDEO_BSCALING;
64 volatile u32 BIOS_TICK_COUNT;
65 volatile u32 VIDEO_VSYNC_POSITION;
66 volatile u32 VIDEO_VSYNC_DIR;
67 volatile u32 DVD_TRAY_STATE;
68
69 u8 VIDEO_AV_MODE ;
70
71 #define DVD_CLOSED 0
72 #define DVD_CLOSING 1
73 #define DVD_OPEN 2
74 #define DVD_OPENING 3
75
76 /////////////////////////////////
77 // Superfunky i386 internal structures
78
79 typedef struct gdt_t {
80 unsigned short m_wSize __attribute__ ((packed));
81 unsigned long m_dwBase32 __attribute__ ((packed));
82 unsigned short m_wDummy __attribute__ ((packed));
83 } ts_descriptor_pointer;
84
85 typedef struct { // inside an 8-byte protected mode interrupt vector
86 u16 m_wHandlerHighAddressLow16;
87 u16 m_wSelector;
88 u16 m_wType;
89 u16 m_wHandlerLinearAddressHigh16;
90 } ts_pm_interrupt;
91
92 typedef enum {
93 EDT_UNKNOWN= 0,
94 EDT_XBOXFS
95 } enumDriveType;
96
97 typedef struct tsHarddiskInfo { // this is the retained knowledge about an IDE device after init
98 unsigned short m_fwPortBase;
99 unsigned short m_wCountHeads;
100 unsigned short m_wCountCylinders;
101 unsigned short m_wCountSectorsPerTrack;
102 unsigned long m_dwCountSectorsTotal; /* total */
103 unsigned char m_bLbaMode; /* am i lba (0x40) or chs (0x00) */
104 unsigned char m_szIdentityModelNumber[40];
105 unsigned char term_space_1[2];
106 unsigned char m_szSerial[20];
107 unsigned char term_space_2[2];
108 char m_szFirmware[8];
109 unsigned char term_space_3[2];
110 unsigned char m_fDriveExists;
111 unsigned char m_fAtapi; // true if a CDROM, etc
112 enumDriveType m_enumDriveType;
113 unsigned char m_bCableConductors; // valid for device 0 if present
114 unsigned short m_wAtaRevisionSupported;
115 unsigned char s_length;
116 unsigned char m_length;
117 unsigned char m_fHasMbr;
118 unsigned short m_securitySettings; //This contains the contents of the ATA security regs
119 } tsHarddiskInfo;
120
121 /////////////////////////////////
122 // LED-flashing codes
123 // or these together as argument to I2cSetFrontpanelLed
124
125 enum {
126 I2C_LED_RED0 = 0x80,
127 I2C_LED_RED1 = 0x40,
128 I2C_LED_RED2 = 0x20,
129 I2C_LED_RED3 = 0x10,
130 I2C_LED_GREEN0 = 0x08,
131 I2C_LED_GREEN1 = 0x04,
132 I2C_LED_GREEN2 = 0x02,
133 I2C_LED_GREEN3 = 0x01
134 };
135
136 ///////////////////////////////
137 /* BIOS-wide error codes all have b31 set */
138
139 enum {
140 ERR_SUCCESS = 0, // completed without error
141
142 ERR_I2C_ERROR_TIMEOUT = 0x80000001, // I2C action failed because it did not complete in a reasonable time
143 ERR_I2C_ERROR_BUS = 0x80000002, // I2C action failed due to non retryable bus error
144
145 ERR_BOOT_PIC_ALG_BROKEN = 0x80000101 // PIC algorithm did not pass its self-test
146 };
147
148 /////////////////////////////////
149 // some Boot API prototypes
150
151 //////// BootPerformPicChallengeResponseAction.c
152
153 /* ---------------------------- IO primitives -----------------------------------------------------------
154 */
155
156 static __inline void IoOutputByte(u16 wAds, u8 bValue) {
157 // __asm__ (" out %%al,%%dx" : : "edx" (dwAds), "al" (bValue) );
158 __asm__ __volatile__ ("outb %b0,%w1": :"a" (bValue), "Nd" (wAds));
159 }
160
161 static __inline void IoOutputWord(u16 wAds, u16 wValue) {
162 // __asm__ (" out %%ax,%%dx " : : "edx" (dwAds), "ax" (wValue) );
163 __asm__ __volatile__ ("outw %0,%w1": :"a" (wValue), "Nd" (wAds));
164 }
165
166 static __inline void IoOutputDword(u16 wAds, u32 dwValue) {
167 // __asm__ (" out %%eax,%%dx " : : "edx" (dwAds), "ax" (wValue) );
168 __asm__ __volatile__ ("outl %0,%w1": :"a" (dwValue), "Nd" (wAds));
169 }
170
171
172 static __inline u8 IoInputByte(u16 wAds) {
173 unsigned char _v;
174
175 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (wAds));
176 return _v;
177 }
178
179 static __inline u16 IoInputWord(u16 wAds) {
180 u16 _v;
181
182 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (wAds));
183 return _v;
184 }
185
186 static __inline u32 IoInputDword(u16 wAds) {
187 u32 _v;
188
189 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (wAds));
190 return _v;
191 }
192
193 #define rdmsr(msr,val1,val2) \
194 __asm__ __volatile__("rdmsr" \
195 : "=a" (val1), "=d" (val2) \
196 : "c" (msr))
197
198 #define wrmsr(msr,val1,val2) \
199 __asm__ __volatile__("wrmsr" \
200 : /* no outputs */ \
201 : "c" (msr), "a" (val1), "d" (val2))
202
203
204 void BootPciInterruptEnable(void);
205
206 // boot process
207 int BootPerformPicChallengeResponseAction(void);
208 // LED control (see associated enum above)
209 int I2cSetFrontpanelLed(u8 b);
210
211 #define bprintf(...)
212
213 #if PRINT_TRACE
214 #define TRACE bprintf(__FILE__ " :%d\n\r",__LINE__);
215 #else
216 #define TRACE
217 #endif
218
219 typedef struct _LIST_ENTRY {
220 struct _LIST_ENTRY *m_plistentryNext;
221 struct _LIST_ENTRY *m_plistentryPrevious;
222 } LIST_ENTRY;
223
224 void ListEntryInsertAfterCurrent(LIST_ENTRY *plistentryCurrent, LIST_ENTRY *plistentryNew);
225 void ListEntryRemove(LIST_ENTRY *plistentryCurrent);
226
227 ////////// BootPerformXCodeActions.c
228
229 int BootPerformXCodeActions(void);
230
231 #include "BootEEPROM.h"
232 #include "BootParser.h"
233
234 ////////// BootStartBios.c
235
236 void StartBios(CONFIGENTRY *config,int nActivePartition, int nFATXPresent,int bootfrom);
237 int BootMenu(CONFIGENTRY *config,int nDrive,int nActivePartition, int nFATXPresent);
238
239 ////////// BootResetActions.c
240 void ClearIDT (void);
241 void BootResetAction(void);
242 void BootCpuCache(bool fEnable) ;
243 int printk(const char *szFormat, ...);
244 void BiosCmosWrite(u8 bAds, u8 bData);
245 u8 BiosCmosRead(u8 bAds);
246
247
248 ///////// BootPciPeripheralInitialization.c
249 void BootPciPeripheralInitialization(void);
250 void BootAGPBUSInitialization(void);
251 void BootDetectMemorySize(void);
252 extern void ReadPCIByte(unsigned int bus, unsigned int dev, unsigned intfunc, unsigned int reg_off, unsigned char *pbyteval);
253 extern void WritePCIByte(unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg_off, unsigned char byteval);
254 extern void ReadPCIDword(unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg_off, unsigned int *pdwordval);
255 extern void WritePCIDword(unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg_off, unsigned int dwordval);
256 extern void ReadPCIBlock(unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg_off, unsigned char *buf, unsigned int nbytes);
257 extern void WritePCIBlock(unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg_off, unsigned char *buf, unsigned int nbytes);
258
259 void PciWriteByte (unsigned int bus, unsigned int dev, unsigned int func,
260 unsigned int reg_off, unsigned char byteval);
261 u8 PciReadByte(unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg_off);
262 u32 PciWriteDword(unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg_off, u32 dw);
263 u32 PciReadDword(unsigned int bus, unsigned int dev, unsigned int func, unsigned int reg_off);
264
265 ///////// BootPerformPicChallengeResponseAction.c
266
267 int I2CTransmitWord(u8 bPicAddressI2cFormat, u16 wDataToWrite);
268 int I2CTransmitByteGetReturn(u8 bPicAddressI2cFormat, u8 bDataToWrite);
269 bool I2CGetTemperature(int *, int *);
270 void I2CModifyBits(u8 bAds, u8 bReg, u8 bData, u8 bMask);
271
272 ///////// BootIde.c
273
274 extern tsHarddiskInfo tsaHarddiskInfo[]; // static struct stores data about attached drives
275 int BootIdeInit(void);
276 int BootIdeReadSector(int nDriveIndex, void * pbBuffer, unsigned int block, int byte_offset, int n_bytes);
277 int BootIdeBootSectorHddOrElTorito(int nDriveIndex, u8 * pbaResult);
278 int BootIdeAtapiAdditionalSenseCode(int nDrive, u8 * pba, int nLengthMaxReturn);
279 int BootIdeSetTransferMode(int nIndexDrive, int nMode);
280 int BootIdeWaitNotBusy(unsigned uIoBase);
281 bool BootIdeAtapiReportFriendlyError(int nDriveIndex, char * szErrorReturn, int nMaxLengthError);
282 void BootIdeAtapiPrintkFriendlyError(int nDriveIndex);
283
284 ///////// BootUSB.c
285
286 void BootStopUSB(void);
287 void BootStartUSB(void);
288 void USBGetEvents(void);
289
290 #include "xpad.h"
291
292 extern struct xpad_data XPAD_current[4];
293 extern struct xpad_data XPAD_last[4];
294
295 extern void wait_ms(u32 ticks);
296 extern void wait_us(u32 ticks);
297 extern void wait_smalldelay(void);
298
299
300 void * memcpy(void *dest, const void *src, size_t size);
301 void * memset(void *dest, int data, size_t size);
302 int memcmp(const void *buffer1, const void *buffer2, size_t num);
303 int _strncmp(const char *sz1, const char *sz2, int nMax);
304 char * strcpy(char *sz, const char *szc);
305 char * _strncpy (char * dest, const char * src, size_t n);
306 void chrreplace(char *string, char search, char ch);
307
308 #define printf printk
309 #define sleep wait_ms
310 int tolower(int ch);
311 int isspace (int c);
312
313 void MemoryManagementInitialization(void * pvStartAddress, u32 dwTotalMemoryAllocLength);
314 void * malloc(size_t size);
315 void free(void *);
316
317 extern volatile int nCountI2cinterrupts, nCountUnusedInterrupts, nCountUnusedInterruptsPic2, nCountInterruptsSmc, nCountInterruptsIde;
318 extern volatile bool fSeenPowerdown;
319 typedef enum {
320 ETS_OPEN_OR_OPENING=0,
321 ETS_CLOSING,
322 ETS_CLOSED
323 } TRAY_STATE;
324 extern volatile TRAY_STATE traystate;
325
326
327 extern void BootInterruptsWriteIdt(void);
328 #endif
329 int copy_swap_trim(unsigned char *dst, unsigned char *src, int len);
330 void HMAC_SHA1( unsigned char *result,
331 unsigned char *key, int key_length,
332 unsigned char *text1, int text1_length,
333 unsigned char *text2, int text2_length );
334
335 char *strrchr0(char *string, char ch);
336
337 #endif // _Boot_H_