; Assembler header file for PCI
; Written by DefMod (Dec  9 2012) on Sun Dec  9 15:43:51 2012
; Tom Hughes, tom@compton.nu, 21 Dec 2002

; OSLib---efficient, type-safe, transparent, extensible,
; register-safe API coverage of RISC OS
; 
; Copyright (c) 1994-2012 Jonathan Coxhead and OSLib maintainers
; 
; Licence:
; 
;    OSLib is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 1, or (at your option)
; any later version - and this with the following clarification and
; special exception:
; 
;    Linking this library statically or dynamically with other modules
; is making a combined work based on this library. Thus, the terms
; and conditions of the GNU General Public License cover the whole
; combination.
; 
;    As a special exception, the copyright holders of this library
; give you permission to link this library with independent modules
; to produce an executable, regardless of the license terms of these
; independent modules, and to copy and distribute the resulting
; executable under terms of your choice, provided that you also meet,
; for each linked independent module, the terms and conditions of the
; license of that module. An independent module is a module which is
; not derived from or based on this library. If you modify this
; library, you may extend this exception to your version of the library,
; but you are not obliged to do so. If you do not wish to do so, delete
; this exception statement from your version.
; 
;    OSLib is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
; 
;    You should have received a copy of the GNU General Public License
; along with this programme; if not, write to the Free Software
; Foundation, Inc, 675 Mass Ave, Cambridge, MA 02139, USA.

        [       :LNOT: :DEF: PCI_Hdr
        GBLS    PCI_Hdr

        [       :LNOT: :DEF: Get_Types
        GBLS    Get_Types
        ]
        [       :LNOT: :DEF: Types_Hdr
Get_Types                       SETS    "GET oslib/Types.Hdr"
        |
Get_Types                       SETS    ""
        ]
        $Get_Types

        [       :LNOT: :DEF: Get_OS
        GBLS    Get_OS
        ]
        [       :LNOT: :DEF: OS_Hdr
Get_OS                          SETS    "GET oslib/OS.Hdr"
        |
Get_OS                          SETS    ""
        ]
        $Get_OS

;Symbols for constants
PCI_VendorID                    *       &FFFF
PCI_VendorIDShift               *       0
PCI_DeviceID                    *       &FFFF0000
PCI_DeviceIDShift               *       16
PCI_AnyID                       *       &FFFFFFFF
PCI_ByteAccess                  *       &1
PCI_HalfWordAccess              *       &2
PCI_WordAccess                  *       &4
PCI_MemoryReadPrefetchable      *       &8
PCI_HardwareAddressAccessReadWrite *       &0
PCI_HardwareAddressAccessReadOnly *       &1
PCI_HardwareAddressAccessNone   *       &2
PCI_HardwareAddressAccess       *       &F
PCI_HardwareAddressAccessShift  *       0
PCI_HardwareAddressBufferable   *       &10
PCI_HardwareAddressCacheable    *       &20
PCI_HardwareAddressAccessSet    *       &200
PCI_HardwareAddressQueryOnly    *       &80000000
PCI_HardwareAddressIsIO         *       &1
PCI_HardwareAddressPrefetchable *       &8
PCI_ReadInfoDeviceNumber        *       &1
PCI_ReadInfoFunctionNumber      *       &1
PCI_ReadInfoBusNumber           *       &2
PCI_ReadInfoParentBridgeHandle  *       &4
PCI_ReadInfoSlotNumber          *       &8
PCI_ReadInfoID                  *       &10
PCI_ReadInfoRevisionID          *       &20
PCI_ReadInfoSubsystemID         *       &40
PCI_ReadInfoClass               *       &80
PCI_ReadInfoCMOSAddress         *       &100
PCI_ReadInfoCMOSSize            *       &200
PCI_ReadInfoDescription         *       &400
PCI_ReadInfoDeviceVectorNumber  *       &800
PCI_ReadInfoEthernetAddressLow  *       &1000
PCI_ReadInfoEthernetAddressHigh *       &2000
PCI_ReadInfoLogicalDMAChannel   *       &4000
PCI_ReadInfoVendorDescription   *       &8000
PCI_LogicalAddressBufferable    *       &10
PCI_LogicalAddressIsIO          *       &40000000

;Symbols for structure offsets and sizes
        ^       0
        #       Bits
PCI_ID                          *       @

        ^       0
        #       Int
PCI_Class                       *       @

        ^       0
        #       Int
PCI_Function                    *       @

PCI_AccessSize                  *       4 ;abstract type
PCI_Address                     *       4 ;abstract type
PCI_ConfigurationAddress        *       4 ;abstract type
        ^       0
        #       Bits
PCI_MemoryReadFlags             *       @

        ^       0
        #       Bits
PCI_MemoryWriteFlags            *       @

        ^       0
        #       Bits
PCI_ReadInfoFlags               *       @

        ^       0
        #       Bits
PCI_HardwareAddressInputFlags   *       @

        ^       0
        #       Bits
PCI_HardwareAddressOutputFlags  *       @

        ^       0
        #       Bits
PCI_LogicalAddressFlags         *       @


;Symbols for SWI's and SWI reason codes
XPCI_ReadID                     *       &70380
PCI_ReadID                      *       &50380
   ;Entry
   ;  R3 = function (PCI_Function)
   ;Exit
   ;  R0 = id (PCI_ID)
   ;  R1 = subsystem_id (PCI_ID)

XPCI_ReadHeader                 *       &70381
PCI_ReadHeader                  *       &50381
   ;Entry
   ;  R1 = buffer (pointer to data)
   ;  R2 = size (Int)
   ;  R3 = function (PCI_Function)

XPCI_ReturnNumber               *       &70382
PCI_ReturnNumber                *       &50382
   ;Exit
   ;  R0 = used (PCI_Function)

XPCI_EnumerateFunctions         *       &70383
PCI_EnumerateFunctions          *       &50383
   ;Entry
   ;  R3 = previous_function (PCI_Function)
   ;Exit
   ;  R0 = id (PCI_ID)
   ;  R1 = subsystem_id (PCI_ID)
   ;  R2 = pciclass (PCI_Class)
   ;  R3 = function (PCI_Function)

XPCI_IORead                     *       &70384
PCI_IORead                      *       &50384
   ;Entry
   ;  R0 = address (PCI_Address)
   ;  R2 = access_size (PCI_AccessSize)
   ;Exit
   ;  R1 = value (Int)

XPCI_IOWrite                    *       &70385
PCI_IOWrite                     *       &50385
   ;Entry
   ;  R0 = address (PCI_Address)
   ;  R1 = value (Int)
   ;  R2 = access_size (PCI_AccessSize)

XPCI_MemoryRead                 *       &70386
PCI_MemoryRead                  *       &50386
   ;Entry
   ;  R0 = address (PCI_Address)
   ;  R1 = size (Int)
   ;  R2 = buffer (pointer to data)
   ;  R4 = flags (PCI_MemoryReadFlags)

XPCI_MemoryWrite                *       &70387
PCI_MemoryWrite                 *       &50387
   ;Entry
   ;  R0 = address (PCI_Address)
   ;  R1 = size (Int)
   ;  R2 -> buffer (data)
   ;  R4 = flags (PCI_MemoryWriteFlags)

XPCI_ConfigurationRead          *       &70388
PCI_ConfigurationRead           *       &50388
   ;Entry
   ;  R0 = address (PCI_ConfigurationAddress)
   ;  R2 = access_size (PCI_AccessSize)
   ;  R3 = function (PCI_Function)
   ;Exit
   ;  R1 = value (Int)

XPCI_ConfigurationWrite         *       &70389
PCI_ConfigurationWrite          *       &50389
   ;Entry
   ;  R0 = address (PCI_ConfigurationAddress)
   ;  R1 = value (Int)
   ;  R2 = access_size (PCI_AccessSize)
   ;  R3 = function (PCI_Function)

XPCI_HardwareAddress            *       &7038A
PCI_HardwareAddress             *       &5038A
   ;Entry
   ;  R0 = flags (PCI_HardwareAddressInputFlags)
   ;  R1 = address_index (Int)
   ;  R3 = function (PCI_Function)
   ;Exit
   ;  R0 = flags_out (PCI_HardwareAddressOutputFlags)
   ;  R1 = pci_address (PCI_Address)
   ;  R2 = length (Int)
   ;  R4 = logical_address (pointer to data)

XPCI_ReadInfo                   *       &7038B
PCI_ReadInfo                    *       &5038B
   ;Entry
   ;  R0 = flags (PCI_ReadInfoFlags)
   ;  R1 = buffer (pointer to data)
   ;  R2 = size (Int)
   ;  R3 = function (PCI_Function)
   ;Exit
   ;  R2 = length (Int)

XPCI_SpecialCycle               *       &7038C
PCI_SpecialCycle                *       &5038C
   ;Entry
   ;  R0 = bus (Int)
   ;  R1 -> message (data)

XPCI_FindByLocation             *       &7038D
PCI_FindByLocation              *       &5038D
   ;Entry
   ;  R0 = bus (Int)
   ;  R1 = device_or_function (Int)
   ;Exit
   ;  R3 = function (PCI_Function)

XPCI_FindByID                   *       &7038E
PCI_FindByID                    *       &5038E
   ;Entry
   ;  R0 = vendor_id (PCI_ID)
   ;  R1 = device_id (PCI_ID)
   ;  R2 = subsystem_vendor_id (PCI_ID)
   ;  R3 = previous_function (PCI_Function)
   ;  R4 = subsystem_id (PCI_ID)
   ;Exit
   ;  R3 = function (PCI_Function)

XPCI_FindByClass                *       &7038F
PCI_FindByClass                 *       &5038F
   ;Entry
   ;  R0 = pciclass (PCI_Class)
   ;  R1 = class_mask (PCI_Class)
   ;  R3 = previous_function (PCI_Function)
   ;Exit
   ;  R3 = function (PCI_Function)

XPCI_RAMAlloc                   *       &70390
PCI_RAMAlloc                    *       &50390
   ;Entry
   ;  R0 = size (Int)
   ;  R1 = alignment (Int)
   ;  R2 = boundary_limitation (Int)
   ;Exit
   ;  R0 = logical_address (pointer to data)
   ;  R1 = pci_address (PCI_Address)

XPCI_RAMFree                    *       &70391
PCI_RAMFree                     *       &50391
   ;Entry
   ;  R0 = logical_address (pointer to data)

XPCI_LogicalAddress             *       &70392
PCI_LogicalAddress              *       &50392
   ;Entry
   ;  R0 = flags (PCI_LogicalAddressFlags)
   ;  R1 = pci_address (PCI_Address)
   ;  R2 = length (Int)
   ;Exit
   ;  R4 = logical_address (pointer to data)

Service_PCILookupDescription    *       &0
   ;Entry
   ;  R1 = &C3
   ;  R2 = &0
   ;  R3 = function (PCI_Function)
   ;Exit
   ;  R1 = unclaimed (Bool)
   ;  R2 -> description (Char)

Service_PCILookupVendorDescription *       &1
   ;Entry
   ;  R0 = vendir (PCI_ID)
   ;  R1 = &C3
   ;  R2 = &1
   ;Exit
   ;  R1 = unclaimed (Bool)
   ;  R2 -> description (Char)

        ]
        END
