coreboot-v2/util/x86emu/yabel/device.h
<<
>>
Prefs
   1/******************************************************************************
   2 * Copyright (c) 2004, 2008 IBM Corporation
   3 * Copyright (c) 2008, 2009 Pattrick Hueper <phueper@hueper.net>
   4 * All rights reserved.
   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
   9 *
  10 * Contributors:
  11 *     IBM Corporation - initial implementation
  12 *****************************************************************************/
  13
  14#ifndef DEVICE_LIB_H
  15#define DEVICE_LIB_H
  16
  17#include <types.h>
  18#ifdef CONFIG_COREBOOT_V2
  19#include <arch/byteorder.h>
  20#include "compat/of.h"
  21#else
  22#include <cpu.h>
  23#include <byteorder.h>
  24#include "of.h"
  25#endif
  26#include "debug.h"
  27
  28
  29// a Expansion Header Struct as defined in Plug and Play BIOS Spec 1.0a Chapter 3.2
  30typedef struct {
  31        char signature[4];      // signature
  32        u8 structure_revision;
  33        u8 length;              // in 16 byte blocks
  34        u16 next_header_offset; // offset to next Expansion Header as 16bit little-endian value, as offset from the start of the Expansion ROM
  35        u8 reserved;
  36        u8 checksum;    // the sum of all bytes of the Expansion Header must be 0
  37        u32 device_id;  // PnP Device ID as 32bit little-endian value
  38        u16 p_manufacturer_string;      //16bit little-endian offset from start of Expansion ROM
  39        u16 p_product_string;   //16bit little-endian offset from start of Expansion ROM
  40        u8 device_base_type;
  41        u8 device_sub_type;
  42        u8 device_if_type;
  43        u8 device_indicators;
  44        // the following vectors are all 16bit little-endian offsets from start of Expansion ROM
  45        u16 bcv;                // Boot Connection Vector
  46        u16 dv;         // Disconnect Vector
  47        u16 bev;                // Bootstrap Entry Vector
  48        u16 reserved_2;
  49        u16 sriv;               // Static Resource Information Vector
  50} __attribute__ ((__packed__)) exp_header_struct_t;
  51
  52// a PCI Data Struct as defined in PCI 2.3 Spec Chapter 6.3.1.2
  53typedef struct {
  54        u8 signature[4];        // signature, the String "PCIR"
  55        u16 vendor_id;
  56        u16 device_id;
  57        u16 reserved;
  58        u16 pci_ds_length;      // PCI Data Structure Length, 16bit little-endian value
  59        u8 pci_ds_revision;
  60        u8 class_code[3];
  61        u16 img_length; // length of the Exp.ROM Image, 16bit little-endian value in 512 bytes
  62        u16 img_revision;
  63        u8 code_type;
  64        u8 indicator;
  65        u16 reserved_2;
  66} __attribute__ ((__packed__)) pci_data_struct_t;
  67
  68typedef struct {
  69        u8 bus;
  70        u8 devfn;
  71#ifdef CONFIG_PCI_OPTION_ROM_RUN_YABEL
  72        struct device* dev;
  73#else
  74        u64 puid;
  75        phandle_t phandle;
  76        ihandle_t ihandle;
  77#endif
  78        // store the address of the BAR that is used to simulate
  79        // legacy VGA memory accesses
  80        u64 vmem_addr;
  81        u64 vmem_size;
  82        // used to buffer I/O Accesses, that do not access the I/O Range of the device...
  83        // 64k might be overkill, but we can buffer all I/O accesses...
  84        u8 io_buffer[64 * 1024];
  85        u16 pci_vendor_id;
  86        u16 pci_device_id;
  87        // translated address of the "PC-Compatible" Expansion ROM Image for this device
  88        unsigned long img_addr;
  89        u32 img_size;   // size of the Expansion ROM Image (read from the PCI Data Structure)
  90} biosemu_device_t;
  91
  92typedef struct {
  93#ifdef CONFIG_PCI_OPTION_ROM_RUN_YABEL
  94        unsigned long info;
  95#else
  96        u8 info;
  97#endif
  98        u8 bus;
  99        u8 devfn;
 100        u8 cfg_space_offset;
 101        u64 address;
 102        u64 address_offset;
 103        u64 size;
 104} __attribute__ ((__packed__)) translate_address_t;
 105
 106// array to store address translations for this
 107// device. Needed for faster address translation, so
 108// not every I/O or Memory Access needs to call translate_address_dev
 109// and access the device tree
 110// 6 BARs, 1 Exp. ROM, 1 Cfg.Space, and 3 Legacy
 111// translations are supported... this should be enough for
 112// most devices... for VGA it is enough anyways...
 113extern translate_address_t translate_address_array[11];
 114
 115// index of last translate_address_array entry
 116// set by get_dev_addr_info function
 117extern u8 taa_last_entry;
 118
 119/* the device we are working with... */
 120extern biosemu_device_t bios_device;
 121
 122u8 biosemu_dev_init(struct device * device);
 123// NOTE: for dev_check_exprom to work, biosemu_dev_init MUST be called first!
 124u8 biosemu_dev_check_exprom(unsigned long rom_base_addr);
 125
 126u8 biosemu_dev_translate_address(unsigned long * addr);
 127
 128/* endianness swap functions for 16 and 32 bit words
 129 * copied from axon_pciconfig.c
 130 */
 131static inline void
 132out32le(void *addr, u32 val)
 133{
 134#ifdef __i386
 135        *((u32*) addr) = cpu_to_le32(val);
 136#else
 137        asm volatile ("stwbrx  %0, 0, %1"::"r" (val), "r"(addr));
 138#endif
 139}
 140
 141static inline u32
 142in32le(void *addr)
 143{
 144        u32 val;
 145#ifdef __i386
 146        val = cpu_to_le32(*((u32 *) addr));
 147#else
 148        asm volatile ("lwbrx  %0, 0, %1":"=r" (val):"r"(addr));
 149#endif
 150        return val;
 151}
 152
 153static inline void
 154out16le(void *addr, u16 val)
 155{
 156#ifdef __i386
 157        *((u16*) addr) = cpu_to_le16(val);
 158#else
 159        asm volatile ("sthbrx  %0, 0, %1"::"r" (val), "r"(addr));
 160#endif
 161}
 162
 163static inline u16
 164in16le(void *addr)
 165{
 166        u16 val;
 167#ifdef __i386
 168        val = cpu_to_le16(*((u16*) addr));
 169#else
 170        asm volatile ("lhbrx %0, 0, %1":"=r" (val):"r"(addr));
 171#endif
 172        return val;
 173}
 174
 175/* debug function, dumps HID1 and HID4 to detect whether caches are on/off */
 176static inline void
 177dumpHID(void)
 178{
 179        u64 hid;
 180        //HID1 = 1009
 181        __asm__ __volatile__("mfspr %0, 1009":"=r"(hid));
 182        printf("HID1: %016llx\n", hid);
 183        //HID4 = 1012
 184        __asm__ __volatile__("mfspr %0, 1012":"=r"(hid));
 185        printf("HID4: %016llx\n", hid);
 186}
 187
 188#endif
 189
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.