Ticket #3452: driver.c.diff

File driver.c.diff, 8.2 KB (added by chrisv, 15 years ago)

Patch of tdfx driver v0.02

  • driver/driver.c

    old new  
    519519}
    520520
    521521#if defined(POST_R4_0)
    522 static int32 timer_interrupt_func(timer *te, uint32 pc)
     522static int32 timer_interrupt_func(timer *te)
    523523{
    524524    bigtime_t now = system_time();
    525525    /* get the pointer to the device we're handling this time */
     
    731731    /* create a semaphore for vertical blank management */
    732732    si->vblank = create_sem(0, di->name);
    733733    if (si->vblank < 0) {
     734        ddprintf(("couldn't create vblank semaphore: %d", (uint32) si->vblank));
    734735        result = si->vblank;
    735736        goto unmap;
    736737    }
     
    760761        /* program the first timer interrupt, and it will handle the rest */
    761762        result = add_timer((timer *)(di->current_timer), timer_interrupt_func, si->refresh_period, B_ONE_SHOT_RELATIVE_TIMER);
    762763        /* bail if we can't add the timer */
    763         if (result != B_OK) goto delete_the_sem;
     764        if (result != B_OK) {
     765            ddprintf(("Couldn't add timer: %d\n", (int) result));
     766            goto delete_the_sem;
     767        }
    764768#else
    765769        /* fake some kind of interrupt with a thread */       
    766770        result = di->tid = spawn_kernel_thread(fake_interrupt_thread_func, "SKD fake interrupt", B_REAL_TIME_DISPLAY_PRIORITY, di);
     
    773777        /* otherwise install our interrupt handler */
    774778        result = install_io_interrupt_handler(di->pcii.u.h0.interrupt_line, voodoo_interrupt, (void *)di, 0);
    775779        /* bail if we couldn't install the handler */
    776         if (result != B_OK) goto delete_the_sem;
     780        if (result != B_OK) {
     781            ddprintf(("Couldn't set interrupt handler: %d\n", (uint32) result));
     782            goto delete_the_sem;
     783        }
    777784    }
    778785
    779786mark_as_open:
    780787    /* mark the device open */
    781788    di->is_open++;
    782 
     789    /* Evilness */
     790    if (di->is_open < 2)
     791        di->is_open++;
     792   
    783793    /* send the cookie to the opener */
    784794    *cookie = di;
    785795   
     
    957967    switch (msg)
    958968    {
    959969        /* the only PUBLIC ioctl */
    960     case B_GET_ACCELERANT_SIGNATURE:
    961     {
    962         char *sig = (char *)buf;
    963         strcpy(sig, "voodoo3.accelerant");
    964         result = B_OK;
    965     }
     970        case B_GET_ACCELERANT_SIGNATURE:
     971        {
     972            char *sig = (char *)buf;
     973            if (user_strlcpy((char *) buf, "voodoo3.accelerant", B_FILE_NAME_LENGTH) < B_OK)
     974                result = B_BAD_ADDRESS;
     975            else
     976                result = B_OK;
     977        }
    966978        break;
    967979       
    968     /* PRIVATE ioctl from here on */
    969     case VOODOO_GET_PRIVATE_DATA:
    970     {
    971         voodoo_get_private_data *gpd = (voodoo_get_private_data *)buf;
    972         if (gpd->magic == VOODOO_PRIVATE_DATA_MAGIC)
    973         {
    974             gpd->shared_info_area = di->shared_area;
    975             result = B_OK;
    976         }
    977     }
     980        /* PRIVATE ioctl from here on */
     981        case VOODOO_GET_PRIVATE_DATA:
     982        {
     983            voodoo_get_private_data *gpd = (voodoo_get_private_data *)buf;
     984            if (gpd->magic == VOODOO_PRIVATE_DATA_MAGIC)
     985            {
     986                gpd->shared_info_area = di->shared_area;
     987                result = B_OK;
     988            }
     989        }
    978990        break;
    979     case VOODOO_GET_PCI:
    980     {
    981         voodoo_get_set_pci *gsp = (voodoo_get_set_pci *)buf;
    982         if (gsp->magic == VOODOO_PRIVATE_DATA_MAGIC) {
    983             pci_info *pcii = &(di->pcii);
    984             gsp->value = get_pci(gsp->offset, gsp->size);
    985             result = B_OK;
    986         }
    987     }
     991   
     992        case VOODOO_GET_PCI:
     993        {
     994            voodoo_get_set_pci *gsp = (voodoo_get_set_pci *)buf;
     995            if (gsp->magic == VOODOO_PRIVATE_DATA_MAGIC) {
     996                pci_info *pcii = &(di->pcii);
     997                gsp->value = get_pci(gsp->offset, gsp->size);
     998                result = B_OK;
     999            }
     1000        }
    9881001        break;
    989     case VOODOO_SET_PCI:
    990     {
    991         voodoo_get_set_pci *gsp = (voodoo_get_set_pci *)buf;
    992         if (gsp->magic == VOODOO_PRIVATE_DATA_MAGIC) {
    993             pci_info *pcii = &(di->pcii);
    994             set_pci(gsp->offset, gsp->size, gsp->value);
    995             result = B_OK;
    996         }
    997     }
    998         break;
    999     case VOODOO_RUN_INTERRUPTS:
    1000     {
    1001         voodoo_set_bool_state *ri = (voodoo_set_bool_state *)buf;
    1002         if (ri->magic == VOODOO_PRIVATE_DATA_MAGIC) {
    1003             /* are we faking interrupts? */
    1004             if ((di->pcii.u.h0.interrupt_pin == 0x00) || (di->pcii.u.h0.interrupt_line == 0xff)){
    1005                 di->can_interrupt = ri->do_it;
    1006             } else {
    1007                 vuint32 *regs = di->regs;
    1008                 if (ri->do_it) {
    1009                     /* resume interrupts */
    1010                     *regs = *regs; /* CHANGE ME */
    1011                 } else {
    1012                     /* disable interrupts */
    1013                     *regs = *regs; /* CHANGE ME */
    1014                 }
    1015             }
    1016             result = B_OK;
    1017         }
    1018     }
     1002   
     1003        case VOODOO_SET_PCI:
     1004        {
     1005            voodoo_get_set_pci *gsp = (voodoo_get_set_pci *)buf;
     1006            if (gsp->magic == VOODOO_PRIVATE_DATA_MAGIC) {
     1007                pci_info *pcii = &(di->pcii);
     1008                set_pci(gsp->offset, gsp->size, gsp->value);
     1009                result = B_OK;
     1010            }
     1011        }
    10191012        break;
    1020     case VOODOO_DPRINTF:
    1021         dprintf ((char*)buf);
     1013   
     1014        case VOODOO_RUN_INTERRUPTS:
     1015        {
     1016            voodoo_set_bool_state *ri = (voodoo_set_bool_state *)buf;
     1017            if (ri->magic == VOODOO_PRIVATE_DATA_MAGIC) {
     1018                /* are we faking interrupts? */
     1019                if ((di->pcii.u.h0.interrupt_pin == 0x00) || (di->pcii.u.h0.interrupt_line == 0xff)){
     1020                    di->can_interrupt = ri->do_it;
     1021                } else {
     1022                    vuint32 *regs = di->regs;
     1023                    if (ri->do_it) {
     1024                        /* resume interrupts */
     1025                        *regs = *regs; /* CHANGE ME */
     1026                    } else {
     1027                        /* disable interrupts */
     1028                        *regs = *regs; /* CHANGE ME */
     1029                    }
     1030                }
     1031                result = B_OK;
     1032            }
     1033        }
    10221034        break;
    1023     case VOODOO_INB: {
    1024         voodoo_port_io *io = (voodoo_port_io *)buf;
    1025         io->data8 = inportb(io->port);
    1026         } break;
    1027     case VOODOO_INW: {
    1028         voodoo_port_io *io = (voodoo_port_io *)buf;
    1029         io->data16 = inportw(io->port);
    1030         } break;
    1031     case VOODOO_INL: {
    1032         voodoo_port_io *io = (voodoo_port_io *)buf;
    1033         io->data32 = inportl(io->port);
    1034         } break;
    1035     case VOODOO_OUTB: {
    1036         voodoo_port_io *io = (voodoo_port_io *)buf;
    1037         outportb(io->port, io->data8);
    1038         } break;
    1039     case VOODOO_OUTW: {
    1040         voodoo_port_io *io = (voodoo_port_io *)buf;
    1041         outportw(io->port, io->data16);
    1042         } break;
    1043     case VOODOO_OUTL: {
    1044         voodoo_port_io *io = (voodoo_port_io *)buf;
    1045         outportl(io->port, io->data32);
    1046         } break;
     1035   
     1036        case VOODOO_DPRINTF:
     1037            /* Comment this one out, whee. */
     1038            /* dprintf ((char*)buf); */
     1039            break;
     1040
     1041#define do_port_in(method, field) do {                              \
     1042    voodoo_port_io io;                                              \
     1043    if (user_memcpy(&io, (void *) buf, sizeof(io)) < B_OK)          \
     1044    {                                                               \
     1045        result = B_BAD_ADDRESS;                                 \
     1046    }                                                               \
     1047    else                                                            \
     1048    {                                                               \
     1049        io. field = method (io.port);                               \
     1050        if (user_memcpy(&io, (void *) buf, sizeof(io)) < B_OK)      \
     1051        {                                                           \
     1052            result = B_BAD_ADDRESS;                             \
     1053        }                                                           \
     1054        else result = B_OK;                                         \
     1055    }                                                               \
     1056} while (0)
     1057
     1058#define do_port_out(method, field) do {                             \
     1059    voodoo_port_io io;                                              \
     1060    if (user_memcpy(&io, (void *) buf, sizeof(io)) < B_OK)          \
     1061    {                                                               \
     1062        result = B_BAD_ADDRESS;                                 \
     1063    }                                                               \
     1064    else                                                            \
     1065    {                                                               \
     1066        method (io.port, io. field );                               \
     1067        result = B_OK;                                              \
     1068    }                                                               \
     1069} while (0)
     1070       
     1071        case VOODOO_INB: {
     1072            do_port_in(inportb, data8);
     1073        }
     1074        break;
     1075   
     1076        case VOODOO_INW: {
     1077            do_port_in(inportw, data16);
     1078        }
     1079        break;
     1080   
     1081        case VOODOO_INL: {
     1082            do_port_in(inportl, data32);
     1083        }
     1084        break;
     1085   
     1086        case VOODOO_OUTB: {
     1087            do_port_out(outportb, data8);
     1088        }
     1089        break;
     1090       
     1091        case VOODOO_OUTW: {
     1092            do_port_out(outportw, data16);
     1093        }
     1094        break;
     1095       
     1096        case VOODOO_OUTL: {
     1097            do_port_out(outportl, data32);
     1098        }
     1099        break;
    10471100    }
    10481101    return result;
    10491102}