Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/pciintel/pci.c

    raf6b5157 r99e6bfb  
    5151#include <ipc/devman.h>
    5252#include <ipc/dev_iface.h>
     53#include <ipc/irc.h>
     54#include <ipc/ns.h>
     55#include <ipc/services.h>
     56#include <sysinfo.h>
    5357#include <ops/hw_res.h>
    5458#include <device/hw_res.h>
    5559#include <ddi.h>
    5660#include <libarch/ddi.h>
     61#include <pci_dev_iface.h>
    5762
    5863#include "pci.h"
     
    8388static bool pciintel_enable_interrupt(ddf_fun_t *fnode)
    8489{
    85         /* TODO */
    86        
    87         return false;
    88 }
     90        /* This is an old ugly way, copied from ne2000 driver */
     91        assert(fnode);
     92        pci_fun_t *dev_data = (pci_fun_t *) fnode->driver_data;
     93
     94  sysarg_t apic;
     95  sysarg_t i8259;
     96        int irc_phone = -1;
     97        int irc_service = 0;
     98
     99  if ((sysinfo_get_value("apic", &apic) == EOK) && (apic)) {
     100    irc_service = SERVICE_APIC;
     101        } else if ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259)) {
     102    irc_service = SERVICE_I8259;
     103        }
     104
     105  if (irc_service) {
     106    while (irc_phone < 0)
     107      irc_phone = service_connect_blocking(irc_service, 0, 0);
     108  } else {
     109                return false;
     110        }
     111
     112        size_t i;
     113  for (i = 0; i < dev_data->hw_resources.count; i++) {
     114                if (dev_data->hw_resources.resources[i].type == INTERRUPT) {
     115                        int irq = dev_data->hw_resources.resources[i].res.interrupt.irq;
     116                        async_msg_1(irc_phone, IRC_ENABLE_INTERRUPT, irq);
     117                }
     118        }
     119
     120        async_hangup(irc_phone);
     121        return true;
     122}
     123
     124static int pci_config_space_write_16(ddf_fun_t *fun, uint32_t address, uint16_t data)
     125{
     126        if (address > 254)
     127                return EINVAL;
     128        pci_conf_write_16(PCI_FUN(fun), address, data);
     129        return EOK;
     130}
     131
    89132
    90133static hw_res_ops_t pciintel_hw_res_ops = {
     
    93136};
    94137
    95 static ddf_dev_ops_t pci_fun_ops;
     138static pci_dev_iface_t pci_dev_ops = {
     139        .config_space_read_8 = NULL,
     140        .config_space_read_16 = NULL,
     141        .config_space_read_32 = NULL,
     142        .config_space_write_8 = NULL,
     143        .config_space_write_16 = &pci_config_space_write_16,
     144        .config_space_write_32 = NULL
     145};
     146
     147static ddf_dev_ops_t pci_fun_ops = {
     148        .interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops,
     149        .interfaces[PCI_DEV_IFACE] = &pci_dev_ops
     150};
    96151
    97152static int pci_add_device(ddf_dev_t *);
     
    287342        /* Get the value of the BAR. */
    288343        val = pci_conf_read_32(fun, addr);
     344
     345#define IO_MASK  (~0x3)
     346#define MEM_MASK (~0xf)
    289347       
    290348        io = (bool) (val & 1);
    291349        if (io) {
    292350                addrw64 = false;
     351                mask = IO_MASK;
    293352        } else {
     353                mask = MEM_MASK;
    294354                switch ((val >> 1) & 3) {
    295355                case 0:
     
    307367        /* Get the address mask. */
    308368        pci_conf_write_32(fun, addr, 0xffffffff);
    309         mask = pci_conf_read_32(fun, addr);
     369        mask &= pci_conf_read_32(fun, addr);
    310370       
    311371        /* Restore the original value. */
     
    555615{
    556616        pci_fun_ops.interfaces[HW_RES_DEV_IFACE] = &pciintel_hw_res_ops;
     617        pci_fun_ops.interfaces[PCI_DEV_IFACE] = &pci_dev_ops;
    557618}
    558619
     
    626687size_t pci_bar_mask_to_size(uint32_t mask)
    627688{
    628         return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
     689        size_t size = mask & ~(mask - 1);
     690        return size;
    629691}
    630692
Note: See TracChangeset for help on using the changeset viewer.