Copyright (c) Hyperion Entertainment and contributors.

Difference between revisions of "PCI"

From AmigaOS Documentation Wiki
Jump to navigation Jump to search
Line 17: Line 17:
 
Each PCI device has a set of up to 6 BARs (Base Address Registers). These can be accessed either by reading from config space, which would involve additional calculation required on the user's side, or by using the GetResourceRange() method of the pci_device. GetResourceRange() returns a read-only pointer to a read-only structure containing information about a specific BAR, including its classification into memory or I/O space, prefetchability, etc. The pointer must be freed with FreeResourceRange() when you are done accessing it.
 
Each PCI device has a set of up to 6 BARs (Base Address Registers). These can be accessed either by reading from config space, which would involve additional calculation required on the user's side, or by using the GetResourceRange() method of the pci_device. GetResourceRange() returns a read-only pointer to a read-only structure containing information about a specific BAR, including its classification into memory or I/O space, prefetchability, etc. The pointer must be freed with FreeResourceRange() when you are done accessing it.
   
A common error has crept into many AmigaOS device drivers when using the GetResourceRange() method. The error is rather subtle and only makes a different when the
+
A common error has crept into many AmigaOS device drivers when using the GetResourceRange() method. The error is rather subtle and only makes a difference when the Amiga hardware uses different addresses for the bus and the CPU access. In essence, two PCI devices may have the same address in PCI space but unique addresses in CPU space.
   
Here is the correct way to obtain the PCI base address assuming the
+
Here is the correct way to obtain the BARs in a device driver:
  +
<syntaxhighlight>
  +
int i;
  +
</syntaxhighlight>

Revision as of 22:50, 1 October 2017

Introduction

Many Amiga computers utilitize the PCI (Peripheral Component Interconnect) local bus standard. Many more support the PCI Express (Peripheral Component Interconnect Express) local bus standard. No matther which flavour of PCI is in use, the pci interface is the way to utilize them.

The Interface and its Functions

Expansion Library contains the "pci" interface. Therefore, you must first open Expansion Library and then obtain the pci interface in order to access the methods. The "pci" interface has methods to find a specific device or allocate resource ranges for a device that has not been configured yet.

Device addressing is done entirely through an abstract interface. There is no bus/device/function number. Instead, a device is represented by means of a library-exported interface of type "pci_device", represented by an interface structure PCIDevice.

Device Access

You access a PCI device by first finding it with the FindDevice() function. Once a device has been located a device driver must also lock the device for as long as it is in use.

Obtaining Base Address Registers (BARs)

Each PCI device has a set of up to 6 BARs (Base Address Registers). These can be accessed either by reading from config space, which would involve additional calculation required on the user's side, or by using the GetResourceRange() method of the pci_device. GetResourceRange() returns a read-only pointer to a read-only structure containing information about a specific BAR, including its classification into memory or I/O space, prefetchability, etc. The pointer must be freed with FreeResourceRange() when you are done accessing it.

A common error has crept into many AmigaOS device drivers when using the GetResourceRange() method. The error is rather subtle and only makes a difference when the Amiga hardware uses different addresses for the bus and the CPU access. In essence, two PCI devices may have the same address in PCI space but unique addresses in CPU space.

Here is the correct way to obtain the BARs in a device driver:

int i;