Annotation of qemu/roms/SLOF/clients/net-snk/app/biosemu/device.h, revision 1.1

1.1     ! root        1: /******************************************************************************
        !             2:  * Copyright (c) 2004, 2008 IBM Corporation
        !             3:  * All rights reserved.
        !             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
        !             8:  *
        !             9:  * Contributors:
        !            10:  *     IBM Corporation - initial implementation
        !            11:  *****************************************************************************/
        !            12: 
        !            13: #ifndef DEVICE_LIB_H
        !            14: #define DEVICE_LIB_H
        !            15: 
        !            16: #include <stdint.h>
        !            17: #include <cpu.h>
        !            18: #include "of.h"
        !            19: #include <stdio.h>
        !            20: 
        !            21: // a Expansion Header Struct as defined in Plug and Play BIOS Spec 1.0a Chapter 3.2
        !            22: typedef struct {
        !            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
        !            27:        uint8_t reserved;
        !            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
        !            40:        uint16_t reserved_2;
        !            41:        uint16_t sriv;          // Static Resource Information Vector
        !            42: } __attribute__ ((__packed__)) exp_header_struct_t;
        !            43: 
        !            44: // a PCI Data Struct as defined in PCI 2.3 Spec Chapter 6.3.1.2
        !            45: typedef struct {
        !            46:        uint8_t signature[4];   // signature, the String "PCIR"
        !            47:        uint16_t vendor_id;
        !            48:        uint16_t device_id;
        !            49:        uint16_t reserved;
        !            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;
        !            55:        uint8_t code_type;
        !            56:        uint8_t indicator;
        !            57:        uint16_t reserved_2;
        !            58: } __attribute__ ((__packed__)) pci_data_struct_t;
        !            59: 
        !            60: typedef struct {
        !            61:        uint8_t bus;
        !            62:        uint8_t devfn;
        !            63:        uint64_t puid;
        !            64:        phandle_t phandle;
        !            65:        ihandle_t ihandle;
        !            66:        // store the address of the BAR that is used to simulate
        !            67:        // legacy VGA memory accesses
        !            68:        uint64_t vmem_addr;
        !            69:        uint64_t vmem_size;
        !            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
        !            76:        uint64_t img_addr;
        !            77:        uint32_t img_size;      // size of the Expansion ROM Image (read from the PCI Data Structure)
        !            78: } device_t;
        !            79: 
        !            80: typedef struct {
        !            81:        uint8_t info;
        !            82:        uint8_t bus;
        !            83:        uint8_t devfn;
        !            84:        uint8_t cfg_space_offset;
        !            85:        uint64_t address;
        !            86:        uint64_t address_offset;
        !            87:        uint64_t size;
        !            88: } __attribute__ ((__packed__)) translate_address_t;
        !            89: 
        !            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];
        !            98: 
        !            99: // index of last translate_address_array entry
        !           100: // set by get_dev_addr_info function
        !           101: uint8_t taa_last_entry;
        !           102: 
        !           103: device_t bios_device;
        !           104: 
        !           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();
        !           108: 
        !           109: uint8_t dev_translate_address(uint64_t * addr);
        !           110: 
        !           111: /* endianness swap functions for 16 and 32 bit words
        !           112:  * copied from axon_pciconfig.c
        !           113:  */
        !           114: static inline void
        !           115: out32le(void *addr, uint32_t val)
        !           116: {
        !           117:        asm volatile ("stwbrx  %0, 0, %1"::"r" (val), "r"(addr));
        !           118: }
        !           119: 
        !           120: static inline uint32_t
        !           121: in32le(void *addr)
        !           122: {
        !           123:        uint32_t val;
        !           124:        asm volatile ("lwbrx  %0, 0, %1":"=r" (val):"r"(addr));
        !           125:        return val;
        !           126: }
        !           127: 
        !           128: static inline void
        !           129: out16le(void *addr, uint16_t val)
        !           130: {
        !           131:        asm volatile ("sthbrx  %0, 0, %1"::"r" (val), "r"(addr));
        !           132: }
        !           133: 
        !           134: static inline uint16_t
        !           135: in16le(void *addr)
        !           136: {
        !           137:        uint16_t val;
        !           138:        asm volatile ("lhbrx %0, 0, %1":"=r" (val):"r"(addr));
        !           139:        return val;
        !           140: }
        !           141: 
        !           142: /* debug function, dumps HID1 and HID4 to detect wether caches are on/off */
        !           143: static inline void
        !           144: dumpHID()
        !           145: {
        !           146:        uint64_t hid;
        !           147:        //HID1 = 1009
        !           148:        __asm__ __volatile__("mfspr %0, 1009":"=r"(hid));
        !           149:        printf("HID1: %016llx\n", hid);
        !           150:        //HID4 = 1012
        !           151:        __asm__ __volatile__("mfspr %0, 1012":"=r"(hid));
        !           152:        printf("HID4: %016llx\n", hid);
        !           153: }
        !           154: 
        !           155: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.