@ GNU AS assembler header file for PCI
@ Written by DefMod (Dec  9 2012) on Sun Dec  9 15:47:40 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.

#ifndef PCI_Hdr
#  define PCI_Hdr

#  ifndef Get_Types
#    define Get_Types
#    include "oslib/Types.Hdr"
#  endif

#  ifndef Get_OS
#    define Get_OS
#    include "oslib/OS.Hdr"
#  endif

@Symbols for constants
#  define PCI_VendorID 0xffff
#  define PCI_VendorIDShift 0x0
#  define PCI_DeviceID 0xffff0000
#  define PCI_DeviceIDShift 0x10
#  define PCI_AnyID 0xffffffff
#  define PCI_ByteAccess 0x1
#  define PCI_HalfWordAccess 0x2
#  define PCI_WordAccess 0x4
#  define PCI_MemoryReadPrefetchable 0x8
#  define PCI_HardwareAddressAccessReadWrite 0x0
#  define PCI_HardwareAddressAccessReadOnly 0x1
#  define PCI_HardwareAddressAccessNone 0x2
#  define PCI_HardwareAddressAccess 0xf
#  define PCI_HardwareAddressAccessShift 0x0
#  define PCI_HardwareAddressBufferable 0x10
#  define PCI_HardwareAddressCacheable 0x20
#  define PCI_HardwareAddressAccessSet 0x200
#  define PCI_HardwareAddressQueryOnly 0x80000000
#  define PCI_HardwareAddressIsIO 0x1
#  define PCI_HardwareAddressPrefetchable 0x8
#  define PCI_ReadInfoDeviceNumber 0x1
#  define PCI_ReadInfoFunctionNumber 0x1
#  define PCI_ReadInfoBusNumber 0x2
#  define PCI_ReadInfoParentBridgeHandle 0x4
#  define PCI_ReadInfoSlotNumber 0x8
#  define PCI_ReadInfoID 0x10
#  define PCI_ReadInfoRevisionID 0x20
#  define PCI_ReadInfoSubsystemID 0x40
#  define PCI_ReadInfoClass 0x80
#  define PCI_ReadInfoCMOSAddress 0x100
#  define PCI_ReadInfoCMOSSize 0x200
#  define PCI_ReadInfoDescription 0x400
#  define PCI_ReadInfoDeviceVectorNumber 0x800
#  define PCI_ReadInfoEthernetAddressLow 0x1000
#  define PCI_ReadInfoEthernetAddressHigh 0x2000
#  define PCI_ReadInfoLogicalDMAChannel 0x4000
#  define PCI_ReadInfoVendorDescription 0x8000
#  define PCI_LogicalAddressBufferable 0x10
#  define PCI_LogicalAddressIsIO 0x40000000

@Symbols for structure offsets and sizes
        .struct 0
        .skip   Bits
PCI_ID                         : 

        .struct 0
        .skip   Int
PCI_Class                      : 

        .struct 0
        .skip   Int
PCI_Function                   : 

@ abstract type
#  define PCI_AccessSize 4

@ abstract type
#  define PCI_Address 4

@ abstract type
#  define PCI_ConfigurationAddress 4

        .struct 0
        .skip   Bits
PCI_MemoryReadFlags            : 

        .struct 0
        .skip   Bits
PCI_MemoryWriteFlags           : 

        .struct 0
        .skip   Bits
PCI_ReadInfoFlags              : 

        .struct 0
        .skip   Bits
PCI_HardwareAddressInputFlags  : 

        .struct 0
        .skip   Bits
PCI_HardwareAddressOutputFlags : 

        .struct 0
        .skip   Bits
PCI_LogicalAddressFlags        : 


@Symbols for SWI's and SWI reason codes
.set XPCI_ReadID,0x70380
.set PCI_ReadID,0x50380
   @Entry
   @  R3 = function (PCI_Function)
   @Exit
   @  R0 = id (PCI_ID)
   @  R1 = subsystem_id (PCI_ID)

.set XPCI_ReadHeader,0x70381
.set PCI_ReadHeader,0x50381
   @Entry
   @  R1 = buffer (pointer to data)
   @  R2 = size (Int)
   @  R3 = function (PCI_Function)

.set XPCI_ReturnNumber,0x70382
.set PCI_ReturnNumber,0x50382
   @Exit
   @  R0 = used (PCI_Function)

.set XPCI_EnumerateFunctions,0x70383
.set PCI_EnumerateFunctions,0x50383
   @Entry
   @  R3 = previous_function (PCI_Function)
   @Exit
   @  R0 = id (PCI_ID)
   @  R1 = subsystem_id (PCI_ID)
   @  R2 = pciclass (PCI_Class)
   @  R3 = function (PCI_Function)

.set XPCI_IORead,0x70384
.set PCI_IORead,0x50384
   @Entry
   @  R0 = address (PCI_Address)
   @  R2 = access_size (PCI_AccessSize)
   @Exit
   @  R1 = value (Int)

.set XPCI_IOWrite,0x70385
.set PCI_IOWrite,0x50385
   @Entry
   @  R0 = address (PCI_Address)
   @  R1 = value (Int)
   @  R2 = access_size (PCI_AccessSize)

.set XPCI_MemoryRead,0x70386
.set PCI_MemoryRead,0x50386
   @Entry
   @  R0 = address (PCI_Address)
   @  R1 = size (Int)
   @  R2 = buffer (pointer to data)
   @  R4 = flags (PCI_MemoryReadFlags)

.set XPCI_MemoryWrite,0x70387
.set PCI_MemoryWrite,0x50387
   @Entry
   @  R0 = address (PCI_Address)
   @  R1 = size (Int)
   @  R2 -> buffer (data)
   @  R4 = flags (PCI_MemoryWriteFlags)

.set XPCI_ConfigurationRead,0x70388
.set PCI_ConfigurationRead,0x50388
   @Entry
   @  R0 = address (PCI_ConfigurationAddress)
   @  R2 = access_size (PCI_AccessSize)
   @  R3 = function (PCI_Function)
   @Exit
   @  R1 = value (Int)

.set XPCI_ConfigurationWrite,0x70389
.set PCI_ConfigurationWrite,0x50389
   @Entry
   @  R0 = address (PCI_ConfigurationAddress)
   @  R1 = value (Int)
   @  R2 = access_size (PCI_AccessSize)
   @  R3 = function (PCI_Function)

.set XPCI_HardwareAddress,0x7038a
.set PCI_HardwareAddress,0x5038a
   @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)

.set XPCI_ReadInfo,0x7038b
.set PCI_ReadInfo,0x5038b
   @Entry
   @  R0 = flags (PCI_ReadInfoFlags)
   @  R1 = buffer (pointer to data)
   @  R2 = size (Int)
   @  R3 = function (PCI_Function)
   @Exit
   @  R2 = length (Int)

.set XPCI_SpecialCycle,0x7038c
.set PCI_SpecialCycle,0x5038c
   @Entry
   @  R0 = bus (Int)
   @  R1 -> message (data)

.set XPCI_FindByLocation,0x7038d
.set PCI_FindByLocation,0x5038d
   @Entry
   @  R0 = bus (Int)
   @  R1 = device_or_function (Int)
   @Exit
   @  R3 = function (PCI_Function)

.set XPCI_FindByID,0x7038e
.set PCI_FindByID,0x5038e
   @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)

.set XPCI_FindByClass,0x7038f
.set PCI_FindByClass,0x5038f
   @Entry
   @  R0 = pciclass (PCI_Class)
   @  R1 = class_mask (PCI_Class)
   @  R3 = previous_function (PCI_Function)
   @Exit
   @  R3 = function (PCI_Function)

.set XPCI_RAMAlloc,0x70390
.set PCI_RAMAlloc,0x50390
   @Entry
   @  R0 = size (Int)
   @  R1 = alignment (Int)
   @  R2 = boundary_limitation (Int)
   @Exit
   @  R0 = logical_address (pointer to data)
   @  R1 = pci_address (PCI_Address)

.set XPCI_RAMFree,0x70391
.set PCI_RAMFree,0x50391
   @Entry
   @  R0 = logical_address (pointer to data)

.set XPCI_LogicalAddress,0x70392
.set PCI_LogicalAddress,0x50392
   @Entry
   @  R0 = flags (PCI_LogicalAddressFlags)
   @  R1 = pci_address (PCI_Address)
   @  R2 = length (Int)
   @Exit
   @  R4 = logical_address (pointer to data)

#  define Service_PCILookupDescription 0x0
   @Entry
   @  R1 = &C3
   @  R2 = &0
   @  R3 = function (PCI_Function)
   @Exit
   @  R1 = unclaimed (Bool)
   @  R2 -> description (Char)

#  define Service_PCILookupVendorDescription 0x1
   @Entry
   @  R0 = vendir (PCI_ID)
   @  R1 = &C3
   @  R2 = &1
   @Exit
   @  R1 = unclaimed (Bool)
   @  R2 -> description (Char)

#endif
