13 #include "cdi-osdep.h" 16 #include "pedigree/kernel/LockGuard.h" 17 #include "pedigree/kernel/Log.h" 18 #include "pedigree/kernel/Spinlock.h" 19 #include "pedigree/kernel/compiler.h" 20 #include "pedigree/kernel/machine/IrqHandler.h" 21 #include "pedigree/kernel/machine/IrqManager.h" 22 #include "pedigree/kernel/machine/Machine.h" 23 #include "pedigree/kernel/machine/types.h" 24 #include "pedigree/kernel/process/Semaphore.h" 25 #include "pedigree/kernel/process/Thread.h" 26 #include "pedigree/kernel/processor/MemoryRegion.h" 27 #include "pedigree/kernel/processor/PhysicalMemoryManager.h" 28 #include "pedigree/kernel/processor/Processor.h" 29 #include "pedigree/kernel/processor/ProcessorInformation.h" 30 #include "pedigree/kernel/processor/VirtualAddressSpace.h" 31 #include "pedigree/kernel/processor/state_forward.h" 32 #include "pedigree/kernel/processor/types.h" 33 #include "pedigree/kernel/time/Time.h" 34 #include "pedigree/kernel/utilities/utility.h" 39 virtual bool irq(irq_id_t number, InterruptState &state);
45 #define IRQ_COUNT 0x10 48 static void (*driver_irq_handler[IRQ_COUNT])(
struct cdi_device*) = { NULL };
50 static struct cdi_device* driver_irq_device[IRQ_COUNT] = { NULL };
56 static Semaphore *driver_irq_count[IRQ_COUNT] = {0};
64 if(driver_irq_count[irq])
71 if (driver_irq_handler[irq]) {
72 driver_irq_handler[
irq](driver_irq_device[
irq]);
87 extern "C" EXPORTED_PUBLIC void cdi_register_irq(uint8_t
irq,
void (*handler)(
struct cdi_device*),
88 struct cdi_device* device)
90 if (irq >= IRQ_COUNT) {
97 if (driver_irq_handler[irq]) {
98 NOTICE(
"cdi: Versuch IRQ " << irq <<
" mehrfach zu registrieren");
102 if(driver_irq_count[irq])
103 delete driver_irq_count[
irq];
106 driver_irq_handler[
irq] = handler;
107 driver_irq_device[
irq] = device;
109 Machine::instance().getIrqManager()->
registerIsaIrqHandler(irq, static_cast<IrqHandler*>(&cdi_irq_handler));
121 if (irq > IRQ_COUNT) {
125 if(driver_irq_count[irq])
128 while(driver_irq_count[irq]->tryAcquire())
153 extern "C" EXPORTED_PUBLIC int cdi_wait_irq(uint8_t irq, uint32_t timeout)
155 if (irq > IRQ_COUNT) {
159 if (!driver_irq_handler[irq]) {
168 pSem = driver_irq_count[
irq];
172 driver_irq_count[
irq] = pSem;
178 pSem->
acquire(1, 0, timeout * 1000);
207 extern "C" EXPORTED_PUBLIC struct cdi_mem_area* cdi_mem_alloc(
size_t size, cdi_mem_flags_t flags)
215 *region, (size + (pageSize - 1)) / pageSize,
218 WARNING(
"cdi: cdi_mem_alloc: couldn't allocate memory");
223 struct cdi_mem_area *ret =
new struct cdi_mem_area;
227 ret->paddr.items =
new struct cdi_mem_sg_item;
229 ret->paddr.items->size = size;
230 ret->osdep.pMemRegion =
reinterpret_cast<void*
>(region);
252 extern "C" EXPORTED_PUBLIC struct cdi_mem_area* cdi_mem_map(uintptr_t paddr,
size_t size)
258 *region, (size + (pageSize - 1)) / pageSize,
262 WARNING(
"cdi: cdi_mem_map: couldn't allocate memory");
267 struct cdi_mem_area *ret =
new struct cdi_mem_area;
271 ret->paddr.items =
new struct cdi_mem_sg_item;
273 ret->paddr.items->size = size;
274 ret->osdep.pMemRegion =
reinterpret_cast<void*
>(region);
325 extern "C" EXPORTED_PUBLIC struct cdi_mem_area* cdi_mem_require_flags(
struct cdi_mem_area* p,
326 cdi_mem_flags_t flags)
357 extern "C" EXPORTED_PUBLIC int cdi_mem_copy(
struct cdi_mem_area* dest,
struct cdi_mem_area* src)
359 if(dest && src && dest->size == src->size)
361 if(dest->vaddr != src->vaddr)
362 MemoryCopy(dest->vaddr, src->vaddr, src->size);
374 extern "C" EXPORTED_PUBLIC int cdi_ioports_alloc(uint16_t start, uint16_t count)
385 extern "C" EXPORTED_PUBLIC int cdi_ioports_free(uint16_t start, uint16_t count)
402 return Time::getTimeNanoseconds();
407 cdi_outb(0x70, index);
408 return cdi_inb(0x71);
411 extern "C" EXPORTED_PUBLIC void cdi_cmos_write(uint8_t index, uint8_t value)
413 cdi_outb(0x70, index);
414 cdi_outb(0x71, value);
static size_t getPageSize() PURE
static PhysicalMemoryManager & instance()
bool acquire(size_t n=1, size_t timeoutSecs=0, size_t timeoutUsecs=0)
static const size_t continuous
bool acquire(bool recurse=false, bool safe=true)
static ProcessorInformation & information()
static const size_t Write
Special memory entity in the kernel's virtual address space.
physical_uintptr_t physicalAddress() const
virtual irq_id_t registerIsaIrqHandler(uint8_t irq, IrqHandler *handler, bool bEdge=false)=0
void * virtualAddress() const
virtual bool irq(irq_id_t number, InterruptState &state)