1 /******************************************************************************
2 * Copyright (c) 2004, 2008 IBM Corporation
3 * Copyright (c) 2008, 2009 Pattrick Hueper <phueper@hueper.net>
5 * This program and the accompanying materials
6 * are made available under the terms of the BSD License
7 * which accompanies this distribution, and is available at
8 * http://www.opensource.org/licenses/bsd-license.php
11 * IBM Corporation - initial implementation
12 *****************************************************************************/
18 #include <arch/byteorder.h>
19 #include "compat/of.h"
23 // a Expansion Header Struct as defined in Plug and Play BIOS Spec 1.0a Chapter 3.2
25 char signature[4]; // signature
26 u8 structure_revision;
27 u8 length; // in 16 byte blocks
28 u16 next_header_offset; // offset to next Expansion Header as 16bit little-endian value, as offset from the start of the Expansion ROM
30 u8 checksum; // the sum of all bytes of the Expansion Header must be 0
31 u32 device_id; // PnP Device ID as 32bit little-endian value
32 u16 p_manufacturer_string; //16bit little-endian offset from start of Expansion ROM
33 u16 p_product_string; //16bit little-endian offset from start of Expansion ROM
38 // the following vectors are all 16bit little-endian offsets from start of Expansion ROM
39 u16 bcv; // Boot Connection Vector
40 u16 dv; // Disconnect Vector
41 u16 bev; // Bootstrap Entry Vector
43 u16 sriv; // Static Resource Information Vector
44 } __attribute__ ((__packed__)) exp_header_struct_t;
46 // a PCI Data Struct as defined in PCI 2.3 Spec Chapter 6.3.1.2
48 u8 signature[4]; // signature, the String "PCIR"
52 u16 pci_ds_length; // PCI Data Structure Length, 16bit little-endian value
55 u16 img_length; // length of the Exp.ROM Image, 16bit little-endian value in 512 bytes
60 } __attribute__ ((__packed__)) pci_data_struct_t;
65 #ifdef CONFIG_PCI_OPTION_ROM_RUN_YABEL
72 // store the address of the BAR that is used to simulate
73 // legacy VGA memory accesses
76 // used to buffer I/O Accesses, that do not access the I/O Range of the device...
77 // 64k might be overkill, but we can buffer all I/O accesses...
78 u8 io_buffer[64 * 1024];
81 // translated address of the "PC-Compatible" Expansion ROM Image for this device
82 unsigned long img_addr;
83 u32 img_size; // size of the Expansion ROM Image (read from the PCI Data Structure)
87 #ifdef CONFIG_PCI_OPTION_ROM_RUN_YABEL
98 } __attribute__ ((__packed__)) translate_address_t;
100 // array to store address translations for this
101 // device. Needed for faster address translation, so
102 // not every I/O or Memory Access needs to call translate_address_dev
103 // and access the device tree
104 // 6 BARs, 1 Exp. ROM, 1 Cfg.Space, and 3 Legacy, plus 2 "special"
105 // translations are supported... this should be enough for
106 // most devices... for VGA it is enough anyways...
107 extern translate_address_t translate_address_array[13];
109 // index of last translate_address_array entry
110 // set by get_dev_addr_info function
111 extern u8 taa_last_entry;
113 // add 1:1 mapped memory regions to translation table
114 void biosemu_add_special_memory(u32 start, u32 size);
116 /* the device we are working with... */
117 extern biosemu_device_t bios_device;
119 u8 biosemu_dev_init(struct device * device);
120 // NOTE: for dev_check_exprom to work, biosemu_dev_init MUST be called first!
121 u8 biosemu_dev_check_exprom(unsigned long rom_base_addr);
123 u8 biosemu_dev_translate_address(int type, unsigned long * addr);
125 /* endianness swap functions for 16 and 32 bit words
126 * copied from axon_pciconfig.c
129 out32le(void *addr, u32 val)
132 *((u32*) addr) = cpu_to_le32(val);
134 asm volatile ("stwbrx %0, 0, %1"::"r" (val), "r"(addr));
143 val = cpu_to_le32(*((u32 *) addr));
145 asm volatile ("lwbrx %0, 0, %1":"=r" (val):"r"(addr));
151 out16le(void *addr, u16 val)
154 *((u16*) addr) = cpu_to_le16(val);
156 asm volatile ("sthbrx %0, 0, %1"::"r" (val), "r"(addr));
165 val = cpu_to_le16(*((u16*) addr));
167 asm volatile ("lhbrx %0, 0, %1":"=r" (val):"r"(addr));
172 /* debug function, dumps HID1 and HID4 to detect whether caches are on/off */
178 __asm__ __volatile__("mfspr %0, 1009":"=r"(hid));
179 printf("HID1: %016llx\n", hid);
181 __asm__ __volatile__("mfspr %0, 1012":"=r"(hid));
182 printf("HID4: %016llx\n", hid);