- Implemented execp*.
[planlOS.git] / system / include / ke / pci.h
blobd797cf56f2389c31798165afc0120ff3a30207f0
1 /*
2 Copyright (C) 2008 Mathias Gottschlag
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 /**
22 * \file pci.h
23 * PCI functions.
26 #ifndef KE_PCI_H_INCLUDED
27 #define KE_PCI_H_INCLUDED
29 #include <stdint.h>
31 #define KE_ADDR_MEMORY 0
32 #define KE_ADDR_PORT 1
34 /**
35 * PCI device resource. Can be either a port address or a memory address.
37 typedef struct
39 /**
40 * Base address of the resource.
42 uintptr_t addr;
43 /**
44 * Approximated size of the resource.
46 uint32_t size;
47 /**
48 * Type of the resource.
50 uint8_t type;
51 } KePCIResource;
53 /**
54 * Struct holding the information about a PCI device.
56 typedef struct
58 uint8_t bus;
59 uint8_t slot;
60 uint8_t func;
62 /**
63 * Device class.
65 uint8_t devclass;
66 /**
67 * Device subclass.
69 uint8_t subclass;
70 /**
71 * Device revision.
73 uint16_t revision;
75 /**
76 * Device ID.
78 uint16_t device;
79 /**
80 * Vendor ID.
82 uint16_t vendor;
84 /**
85 * Number of valid resources.
87 uint32_t rescount;
88 /**
89 * Resources. Only rescount entries are valid.
91 KePCIResource res[6];
92 /**
93 * Device IRQ.
95 uint8_t irq;
96 } KePCIDevice;
98 /**
99 * Initializes the PCI functions.
101 int keInitPCI(void);
104 * Fills device with the info about the device at the given address.
105 * \param device Pointer to the struct to be filled.
106 * \param bus Bus of the device.
107 * \param slot Slot of the device on the given bus.
108 * \param func Function number.
109 * \return Returns 0 if the device is available.
111 int keGetPCIDevice(KePCIDevice *device, uint8_t bus, uint8_t slot, uint8_t func);
113 * Returns the number of PCI devices in the system.
115 int keGetPCIDeviceCount(void);
117 * Returns a pointer to structs holding the information about the PCI devices
118 * in the system. The returned buffer holds keGetPCIDeviceCount() devices.
120 KePCIDevice *keGetPCIDevices(void);
122 #endif