1 /******************************************************************************
2 * Copyright (c) 2004, 2008 IBM Corporation
4 * This program and the accompanying materials
5 * are made available under the terms of the BSD License
6 * which accompanies this distribution, and is available at
7 * http://www.opensource.org/licenses/bsd-license.php
10 * IBM Corporation - initial implementation
11 *****************************************************************************/
21 // a Expansion Header Struct as defined in Plug and Play BIOS Spec 1.0a Chapter 3.2
23 char signature[4]; // signature
24 uint8_t structure_revision;
25 uint8_t length; // in 16 byte blocks
26 uint16_t next_header_offset; // offset to next Expansion Header as 16bit little-endian value, as offset from the start of the Expansion ROM
28 uint8_t checksum; // the sum of all bytes of the Expansion Header must be 0
29 uint32_t device_id; // PnP Device ID as 32bit little-endian value
30 uint16_t p_manufacturer_string; //16bit little-endian offset from start of Expansion ROM
31 uint16_t p_product_string; //16bit little-endian offset from start of Expansion ROM
32 uint8_t device_base_type;
33 uint8_t device_sub_type;
34 uint8_t device_if_type;
35 uint8_t device_indicators;
36 // the following vectors are all 16bit little-endian offsets from start of Expansion ROM
37 uint16_t bcv; // Boot Connection Vector
38 uint16_t dv; // Disconnect Vector
39 uint16_t bev; // Bootstrap Entry Vector
41 uint16_t sriv; // Static Resource Information Vector
42 } __attribute__ ((__packed__)) exp_header_struct_t;
44 // a PCI Data Struct as defined in PCI 2.3 Spec Chapter 6.3.1.2
46 uint8_t signature[4]; // signature, the String "PCIR"
50 uint16_t pci_ds_length; // PCI Data Structure Length, 16bit little-endian value
51 uint8_t pci_ds_revision;
52 uint8_t class_code[3];
53 uint16_t img_length; // length of the Exp.ROM Image, 16bit little-endian value in 512 bytes
54 uint16_t img_revision;
58 } __attribute__ ((__packed__)) pci_data_struct_t;
66 // store the address of the BAR that is used to simulate
67 // legacy VGA memory accesses
70 // used to buffer I/O Accesses, that do not access the I/O Range of the device...
71 // 64k might be overkill, but we can buffer all I/O accesses...
72 uint8_t io_buffer[64 * 1024];
73 uint16_t pci_vendor_id;
74 uint16_t pci_device_id;
75 // translated address of the "PC-Compatible" Expansion ROM Image for this device
77 uint32_t img_size; // size of the Expansion ROM Image (read from the PCI Data Structure)
84 uint8_t cfg_space_offset;
86 uint64_t address_offset;
88 } __attribute__ ((__packed__)) translate_address_t;
90 // array to store address translations for this
91 // device. Needed for faster address translation, so
92 // not every I/O or Memory Access needs to call translate_address_dev
93 // and access the device tree
94 // 6 BARs, 1 Exp. ROM, 1 Cfg.Space, and 3 Legacy
95 // translations are supported... this should be enough for
96 // most devices... for VGA it is enough anyways...
97 translate_address_t translate_address_array[11];
99 // index of last translate_address_array entry
100 // set by get_dev_addr_info function
101 uint8_t taa_last_entry;
103 device_t bios_device;
105 uint8_t dev_init(char *device_name);
106 // NOTE: for dev_check_exprom to work, dev_init MUST be called first!
107 uint8_t dev_check_exprom(void);
109 uint8_t dev_translate_address(uint64_t * addr);
111 /* endianness swap functions for 16 and 32 bit words
112 * copied from axon_pciconfig.c
115 out32le(void *addr, uint32_t val)
117 asm volatile ("stwbrx %0, 0, %1"::"r" (val), "r"(addr));
120 static inline uint32_t
124 const uint32_t *zaddr = addr;
125 asm volatile ("lwbrx %0, %y1" : "=r"(val) : "Z"(*zaddr));
130 out16le(void *addr, uint16_t val)
132 asm volatile ("sthbrx %0, 0, %1"::"r" (val), "r"(addr));
135 static inline uint16_t
139 const uint16_t *zaddr = addr;
140 asm volatile ("lhbrx %0, %y1" : "=r"(val) : "Z"(*zaddr));
144 /* debug function, dumps HID1 and HID4 to detect wether caches are on/off */
150 __asm__ __volatile__("mfspr %0, 1009":"=r"(hid));
151 printf("HID1: %016llx\n", hid);
153 __asm__ __volatile__("mfspr %0, 1012":"=r"(hid));
154 printf("HID4: %016llx\n", hid);