2 Copyright 1999, Be Incorporated. All Rights Reserved.
3 This file may be used under the terms of the Be Sample Code License.
7 Rudolf Cornelissen 3/2002-4/2006.
10 /* standard kernel driver stuff */
11 #include <KernelExport.h>
15 #include <directories.h>
16 #include <driver_settings.h>
18 #include <stdlib.h> // for strtoXX
21 /* this is for the standardized portion of the driver API */
22 /* currently only one operation is defined: B_GET_ACCELERANT_SIGNATURE */
23 #include <graphic_driver.h>
25 /* this is for sprintf() */
28 /* this is for string compares */
31 /* The private interface between the accelerant and the kernel driver. */
32 #include "DriverInterface.h"
35 #define get_pci(o, s) (*pci_bus->read_pci_config)(pcii->bus, pcii->device, pcii->function, (o), (s))
36 #define set_pci(o, s, v) (*pci_bus->write_pci_config)(pcii->bus, pcii->device, pcii->function, (o), (s), (v))
40 #define DEVICE_FORMAT "%04x_%04x_%02x%02x%02x" // apsed
42 /* Tell the kernel what revision of the driver API we support */
43 int32 api_version
= B_CUR_DRIVER_API_VERSION
; // apsed, was 2, is 2 in R5
45 /* these structures are private to the kernel driver */
46 typedef struct device_info device_info
;
49 timer te
; /* timer entry for add_timer() */
50 device_info
*di
; /* pointer to the owning device */
51 bigtime_t when_target
; /* when we're supposed to wake up */
55 uint32 is_open
; /* a count of how many times the devices has been opened */
56 area_id shared_area
; /* the area shared between the driver and all of the accelerants */
57 shared_info
*si
; /* a pointer to the shared area, for convenience */
58 vuint32
*regs
; /* kernel's pointer to memory mapped registers */
59 pci_info pcii
; /* a convenience copy of the pci info for this device */
60 char name
[B_OS_NAME_LENGTH
]; /* where we keep the name of the device for publishing and comparing */
64 uint32 count
; /* number of devices actually found */
65 benaphore kernel
; /* for serializing opens/closes */
66 char *device_names
[MAX_DEVICES
+1]; /* device name pointer storage */
67 device_info di
[MAX_DEVICES
]; /* device specific stuff */
70 /* prototypes for our private functions */
71 static status_t
open_hook (const char* name
, uint32 flags
, void** cookie
);
72 static status_t
close_hook (void* dev
);
73 static status_t
free_hook (void* dev
);
74 static status_t
read_hook (void* dev
, off_t pos
, void* buf
, size_t* len
);
75 static status_t
write_hook (void* dev
, off_t pos
, const void* buf
, size_t* len
);
76 static status_t
control_hook (void* dev
, uint32 msg
, void *buf
, size_t len
);
77 static status_t
map_device(device_info
*di
);
78 static void unmap_device(device_info
*di
);
79 static void probe_devices(void);
80 static int32
eng_interrupt(void *data
);
82 static DeviceData
*pd
;
83 static isa_module_info
*isa_bus
= NULL
;
84 static pci_module_info
*pci_bus
= NULL
;
85 static agp_module_info
*agp_bus
= NULL
;
86 static device_hooks graphics_device_hooks
= {
99 #define VENDOR_ID_NVIDIA 0x1106 /* Via */
101 static uint16 nvidia_device_list
[] = {
109 } SupportedDevices
[] = {
110 // {VENDOR_ID_NVIDIA, nvidia_device_list},
114 static settings current_settings
= { // see comments in skel.settings
116 DRIVER_PREFIX
".accelerant",
119 0x00000000, // logmask
129 static void dumprom (void *rom
, uint32 size
)
134 fd
= open (kUserDirectory
"/" DRIVER_PREFIX
".rom",
135 O_WRONLY
| O_CREAT
, 0666);
138 /* apparantly max. 32kb may be written at once;
139 * the ROM size is a multiple of that anyway. */
140 for (cnt
= 0; (cnt
< size
); cnt
+= 32768)
141 write (fd
, ((void *)(((uint8
*)rom
) + cnt
)), 32768);
145 /* return 1 if vblank interrupt has occured */
146 static int caused_vbi(vuint32
* regs
)
148 // return (ENG_RG32(RG32_CRTC_INTS) & 0x00000001);
152 /* clear the vblank interrupt */
153 static void clear_vbi(vuint32
* regs
)
155 // ENG_RG32(RG32_CRTC_INTS) = 0x00000001;
158 static void enable_vbi(vuint32
* regs
)
160 /* clear the vblank interrupt */
161 // ENG_RG32(RG32_CRTC_INTS) = 0x00000001;
162 /* enable nVidia interrupt source vblank */
163 // ENG_RG32(RG32_CRTC_INTE) |= 0x00000001;
164 /* enable nVidia interrupt system hardware (b0-1) */
165 // ENG_RG32(RG32_MAIN_INTE) = 0x00000001;
168 static void disable_vbi(vuint32
* regs
)
170 /* disable nVidia interrupt source vblank */
171 // ENG_RG32(RG32_CRTC_INTE) &= 0xfffffffe;
172 /* clear the vblank interrupt */
173 // ENG_RG32(RG32_CRTC_INTS) = 0x00000001;
174 /* disable nVidia interrupt system hardware (b0-1) */
175 // ENG_RG32(RG32_MAIN_INTE) = 0x00000000;
179 init_hardware() - Returns B_OK if one is
180 found, otherwise returns B_ERROR so the driver will be unloaded.
183 init_hardware(void) {
186 bool found_one
= false;
188 /* choke if we can't find the PCI bus */
189 if (get_module(B_PCI_MODULE_NAME
, (module_info
**)&pci_bus
) != B_OK
)
192 /* choke if we can't find the ISA bus */
193 if (get_module(B_ISA_MODULE_NAME
, (module_info
**)&isa_bus
) != B_OK
)
195 put_module(B_PCI_MODULE_NAME
);
199 /* while there are more pci devices */
200 while ((*pci_bus
->get_nth_pci_info
)(pci_index
, &pcii
) == B_NO_ERROR
) {
203 /* if we match a supported vendor */
204 while (SupportedDevices
[vendor
].vendor
) {
205 if (SupportedDevices
[vendor
].vendor
== pcii
.vendor_id
) {
206 uint16
*devices
= SupportedDevices
[vendor
].devices
;
207 /* while there are more supported devices */
209 /* if we match a supported device */
210 if (*devices
== pcii
.device_id
) {
215 /* next supported device */
221 /* next pci_info struct, please */
226 /* put away the module manager */
227 put_module(B_PCI_MODULE_NAME
);
228 return (found_one
? B_OK
: B_ERROR
);
233 void *settings_handle
;
235 // get driver/accelerant settings, apsed
236 settings_handle
= load_driver_settings (DRIVER_PREFIX
".settings");
237 if (settings_handle
!= NULL
) {
243 item
= get_driver_parameter (settings_handle
, "accelerant", "", "");
244 if ((strlen (item
) > 0) && (strlen (item
) < sizeof (current_settings
.accelerant
) - 1)) {
245 strcpy (current_settings
.accelerant
, item
);
247 current_settings
.dumprom
= get_driver_boolean_parameter (settings_handle
, "dumprom", false, false);
250 item
= get_driver_parameter (settings_handle
, "logmask", "0x00000000", "0x00000000");
251 value
= strtoul (item
, &end
, 0);
252 if (*end
== '\0') current_settings
.logmask
= value
;
254 item
= get_driver_parameter (settings_handle
, "memory", "0", "0");
255 value
= strtoul (item
, &end
, 0);
256 if (*end
== '\0') current_settings
.memory
= value
;
258 current_settings
.hardcursor
= get_driver_boolean_parameter (settings_handle
, "hardcursor", false, false);
259 current_settings
.usebios
= get_driver_boolean_parameter (settings_handle
, "usebios", false, false);
260 current_settings
.switchhead
= get_driver_boolean_parameter (settings_handle
, "switchhead", false, false);
261 current_settings
.force_pci
= get_driver_boolean_parameter (settings_handle
, "force_pci", false, false);
262 current_settings
.unhide_fw
= get_driver_boolean_parameter (settings_handle
, "unhide_fw", false, false);
263 current_settings
.pgm_panel
= get_driver_boolean_parameter (settings_handle
, "pgm_panel", false, false);
265 unload_driver_settings (settings_handle
);
268 /* get a handle for the pci bus */
269 if (get_module(B_PCI_MODULE_NAME
, (module_info
**)&pci_bus
) != B_OK
)
272 /* get a handle for the isa bus */
273 if (get_module(B_ISA_MODULE_NAME
, (module_info
**)&isa_bus
) != B_OK
)
275 put_module(B_PCI_MODULE_NAME
);
279 /* get a handle for the agp bus if it exists */
280 get_module(B_AGP_MODULE_NAME
, (module_info
**)&agp_bus
);
282 /* driver private data */
283 pd
= (DeviceData
*)calloc(1, sizeof(DeviceData
));
285 put_module(B_PCI_MODULE_NAME
);
288 /* initialize the benaphore */
289 INIT_BEN(pd
->kernel
);
290 /* find all of our supported devices */
296 publish_devices(void) {
297 /* return the list of supported devices */
298 return (const char **)pd
->device_names
;
302 find_device(const char *name
) {
304 while (pd
->device_names
[index
]) {
305 if (strcmp(name
, pd
->device_names
[index
]) == 0)
306 return &graphics_device_hooks
;
313 void uninit_driver(void) {
315 /* free the driver data */
316 DELETE_BEN(pd
->kernel
);
320 /* put the pci module away */
321 put_module(B_PCI_MODULE_NAME
);
322 put_module(B_ISA_MODULE_NAME
);
324 /* put the agp module away if it's there */
325 if (agp_bus
) put_module(B_AGP_MODULE_NAME
);
328 static status_t
map_device(device_info
*di
)
330 char buffer
[B_OS_NAME_LENGTH
]; /*memory for device name*/
331 shared_info
*si
= di
->si
;
333 pci_info
*pcii
= &(di
->pcii
);
336 /*storage for the physical to virtual table (used for dma buffer)*/
337 // physical_entry physical_memory[2];
338 // #define G400_DMA_BUFFER_SIZE 1024*1024
340 /* variables for making copy of ROM */
344 /* Nvidia cards have registers in [0] and framebuffer in [1] */
346 int frame_buffer
= 0;
347 // int pseudo_dma = 2;
349 /* enable memory mapped IO, disable VGA I/O - this is defined in the PCI standard */
350 tmpUlong
= get_pci(PCI_command
, 2);
351 /* enable PCI access */
352 tmpUlong
|= PCI_command_memory
;
353 /* enable busmastering */
354 tmpUlong
|= PCI_command_master
;
355 /* disable ISA I/O access */
356 tmpUlong
&= ~PCI_command_io
;
357 set_pci(PCI_command
, 2, tmpUlong
);
359 /*work out which version of BeOS is running*/
360 get_system_info(&sysinfo
);
361 if (0)//sysinfo.kernel_build_date[0]=='J')/*FIXME - better ID version*/
363 si
->use_clone_bugfix
= 1;
367 si
->use_clone_bugfix
= 0;
370 /* work out a name for the register mapping */
371 sprintf(buffer
, DEVICE_FORMAT
" regs",
372 di
->pcii
.vendor_id
, di
->pcii
.device_id
,
373 di
->pcii
.bus
, di
->pcii
.device
, di
->pcii
.function
);
375 /* get a virtual memory address for the registers*/
376 si
->regs_area
= map_physical_memory(
378 /* WARNING: Nvidia needs to map regs as viewed from PCI space! */
379 di
->pcii
.u
.h0
.base_registers_pci
[registers
],
380 di
->pcii
.u
.h0
.base_register_sizes
[registers
],
381 B_ANY_KERNEL_ADDRESS
,
382 (si
->use_clone_bugfix
? B_READ_AREA
|B_WRITE_AREA
: 0),
383 (void **)&(di
->regs
));
384 si
->clone_bugfix_regs
= (uint32
*) di
->regs
;
386 /* if mapping registers to vmem failed then pass on error */
387 if (si
->regs_area
< 0) return si
->regs_area
;
389 /* work out a name for the ROM mapping*/
390 sprintf(buffer
, DEVICE_FORMAT
" rom",
391 di
->pcii
.vendor_id
, di
->pcii
.device_id
,
392 di
->pcii
.bus
, di
->pcii
.device
, di
->pcii
.function
);
394 /* disable ROM shadowing, we want the guaranteed exact contents of the chip */
396 * don't touch: (confirmed) NV04, NV05, NV05-M64, NV11 all shutoff otherwise.
397 * NV18, NV28 and NV34 keep working.
398 * confirmed NV28 and NV34 to use upper part of shadowed ROM for scratch purposes,
399 * however the actual ROM content (so the used part) is intact (confirmed). */
400 //set_pci(ENCFG_ROMSHADOW, 4, 0);
402 /* get ROM memory mapped base adress - this is defined in the PCI standard */
403 tmpUlong
= get_pci(PCI_rom_base
, 4);
406 /* ROM was assigned an adress, so enable ROM decoding - see PCI standard */
407 tmpUlong
|= 0x00000001;
408 set_pci(PCI_rom_base
, 4, tmpUlong
);
410 rom_area
= map_physical_memory(
412 di
->pcii
.u
.h0
.rom_base_pci
,
413 di
->pcii
.u
.h0
.rom_size
,
414 B_ANY_KERNEL_ADDRESS
,
419 /* check if we got the BIOS signature (might fail on laptops..) */
420 if (rom_temp
[0]!=0x55 || rom_temp
[1]!=0xaa)
422 /* apparantly no ROM is mapped here */
423 delete_area(rom_area
);
425 /* force using ISA legacy map as fall-back */
426 tmpUlong
= 0x00000000;
432 /* ROM was not assigned an adress, fetch it from ISA legacy memory map! */
433 rom_area
= map_physical_memory(
437 B_ANY_KERNEL_ADDRESS
,
443 /* if mapping ROM to vmem failed then clean up and pass on error */
445 delete_area(si
->regs_area
);
450 /* dump ROM to file if selected in skel.settings
451 * (ROM always fits in 64Kb: checked TNT1 - FX5950) */
452 if (current_settings
.dumprom
) dumprom (rom_temp
, 65536);
453 /* make a copy of ROM for future reference */
454 memcpy (si
->rom_mirror
, rom_temp
, 65536);
456 /* disable ROM decoding - this is defined in the PCI standard, and delete the area */
457 tmpUlong
= get_pci(PCI_rom_base
, 4);
458 tmpUlong
&= 0xfffffffe;
459 set_pci(PCI_rom_base
, 4, tmpUlong
);
460 delete_area(rom_area
);
462 /* work out a name for the framebuffer mapping*/
463 sprintf(buffer
, DEVICE_FORMAT
" framebuffer",
464 di
->pcii
.vendor_id
, di
->pcii
.device_id
,
465 di
->pcii
.bus
, di
->pcii
.device
, di
->pcii
.function
);
467 /* map the framebuffer into vmem, using Write Combining*/
468 si
->fb_area
= map_physical_memory(
470 /* WARNING: Nvidia needs to map framebuffer as viewed from PCI space! */
471 di
->pcii
.u
.h0
.base_registers_pci
[frame_buffer
],
472 di
->pcii
.u
.h0
.base_register_sizes
[frame_buffer
],
473 B_ANY_KERNEL_BLOCK_ADDRESS
| B_MTR_WC
,
474 B_READ_AREA
+ B_WRITE_AREA
,
477 /*if failed with write combining try again without*/
478 if (si
->fb_area
< 0) {
479 si
->fb_area
= map_physical_memory(
481 /* WARNING: Nvidia needs to map framebuffer as viewed from PCI space! */
482 di
->pcii
.u
.h0
.base_registers_pci
[frame_buffer
],
483 di
->pcii
.u
.h0
.base_register_sizes
[frame_buffer
],
484 B_ANY_KERNEL_BLOCK_ADDRESS
,
485 B_READ_AREA
+ B_WRITE_AREA
,
489 /* if there was an error, delete our other areas and pass on error*/
492 delete_area(si
->regs_area
);
496 //fixme: retest for card coldstart and PCI/virt_mem mapping!!
497 /* remember the DMA address of the frame buffer for BDirectWindow?? purposes */
498 si
->framebuffer_pci
= (void *) di
->pcii
.u
.h0
.base_registers_pci
[frame_buffer
];
500 // remember settings for use here and in accelerant
501 si
->settings
= current_settings
;
503 /* in any case, return the result */
507 static void unmap_device(device_info
*di
) {
508 shared_info
*si
= di
->si
;
510 pci_info
*pcii
= &(di
->pcii
);
512 /* disable memory mapped IO */
513 tmpUlong
= get_pci(PCI_command
, 4);
514 tmpUlong
&= 0xfffffffc;
515 set_pci(PCI_command
, 4, tmpUlong
);
516 /* delete the areas */
517 if (si
->regs_area
>= 0) delete_area(si
->regs_area
);
518 if (si
->fb_area
>= 0) delete_area(si
->fb_area
);
519 si
->regs_area
= si
->fb_area
= -1;
520 si
->framebuffer
= NULL
;
524 static void probe_devices(void) {
525 uint32 pci_index
= 0;
527 device_info
*di
= pd
->di
;
529 /* while there are more pci devices */
530 while ((count
< MAX_DEVICES
) && ((*pci_bus
->get_nth_pci_info
)(pci_index
, &(di
->pcii
)) == B_NO_ERROR
)) {
533 /* if we match a supported vendor */
534 while (SupportedDevices
[vendor
].vendor
) {
535 if (SupportedDevices
[vendor
].vendor
== di
->pcii
.vendor_id
) {
536 uint16
*devices
= SupportedDevices
[vendor
].devices
;
537 /* while there are more supported devices */
539 /* if we match a supported device */
540 if (*devices
== di
->pcii
.device_id
) {
541 /* publish the device name */
542 sprintf(di
->name
, "graphics/" DEVICE_FORMAT
,
543 di
->pcii
.vendor_id
, di
->pcii
.device_id
,
544 di
->pcii
.bus
, di
->pcii
.device
, di
->pcii
.function
);
546 /* remember the name */
547 pd
->device_names
[count
] = di
->name
;
548 /* mark the driver as available for R/W open */
550 /* mark areas as not yet created */
551 di
->shared_area
= -1;
552 /* mark pointer to shared data as invalid */
554 /* inc pointer to device info */
558 /* break out of these while loops */
561 /* next supported device */
568 /* next pci_info struct, please */
571 /* propagate count */
573 /* terminate list of device names with a null pointer */
574 pd
->device_names
[pd
->count
] = NULL
;
577 static uint32
thread_interrupt_work(int32
*flags
, vuint32
*regs
, shared_info
*si
) {
578 uint32 handled
= B_HANDLED_INTERRUPT
;
579 /* release the vblank semaphore */
580 if (si
->vblank
>= 0) {
582 if ((get_sem_count(si
->vblank
, &blocked
) == B_OK
) && (blocked
< 0)) {
583 release_sem_etc(si
->vblank
, -blocked
, B_DO_NOT_RESCHEDULE
);
584 handled
= B_INVOKE_SCHEDULER
;
591 eng_interrupt(void *data
)
593 int32 handled
= B_UNHANDLED_INTERRUPT
;
594 device_info
*di
= (device_info
*)data
;
595 shared_info
*si
= di
->si
;
596 int32
*flags
= &(si
->flags
);
599 /* is someone already handling an interrupt for this device? */
600 if (atomic_or(flags
, SKD_HANDLER_INSTALLED
) & SKD_HANDLER_INSTALLED
) {
607 if (caused_vbi(regs
)) {
608 /*clear the interrupt*/
610 /*release the semaphore*/
611 handled
= thread_interrupt_work(flags
, regs
, si
);
614 /* note that we're not in the handler any more */
615 atomic_and(flags
, ~SKD_HANDLER_INSTALLED
);
621 static status_t
open_hook (const char* name
, uint32 flags
, void** cookie
) {
627 status_t result
= B_OK
;
629 char shared_name
[B_OS_NAME_LENGTH
];
631 /* find the device name in the list of devices */
632 /* we're never passed a name we didn't publish */
633 while (pd
->device_names
[index
] && (strcmp(name
, pd
->device_names
[index
]) != 0)) index
++;
635 /* for convienience */
636 di
= &(pd
->di
[index
]);
638 /* make sure no one else has write access to the common data */
639 AQUIRE_BEN(pd
->kernel
);
641 /* if it's already open for writing */
643 /* mark it open another time */
646 /* create the shared area */
647 sprintf(shared_name
, DEVICE_FORMAT
" shared",
648 di
->pcii
.vendor_id
, di
->pcii
.device_id
,
649 di
->pcii
.bus
, di
->pcii
.device
, di
->pcii
.function
);
650 /* create this area with NO user-space read or write permissions, to prevent accidental dammage */
651 di
->shared_area
= create_area(shared_name
, (void **)&(di
->si
), B_ANY_KERNEL_ADDRESS
, ((sizeof(shared_info
) + (B_PAGE_SIZE
- 1)) & ~(B_PAGE_SIZE
- 1)), B_FULL_LOCK
, 0);
652 if (di
->shared_area
< 0) {
653 /* return the error */
654 result
= di
->shared_area
;
658 /* save a few dereferences */
661 /* save the vendor and device IDs */
662 si
->vendor_id
= di
->pcii
.vendor_id
;
663 si
->device_id
= di
->pcii
.device_id
;
664 si
->revision
= di
->pcii
.revision
;
665 si
->bus
= di
->pcii
.bus
;
666 si
->device
= di
->pcii
.device
;
667 si
->function
= di
->pcii
.function
;
669 /* note the amount of system RAM the system BIOS assigned to the card if applicable:
670 * unified memory architecture (UMA) */
671 switch ((((uint32
)(si
->device_id
)) << 16) | si
->vendor_id
)
673 case 0x01a010de: /* Nvidia GeForce2 Integrated GPU */
674 /* device at bus #0, device #0, function #1 holds value at byte-index 0x7C */
675 si
->ps
.memory_size
= 1024 * 1024 *
676 (((((*pci_bus
->read_pci_config
)(0, 0, 1, 0x7c, 4)) & 0x000007c0) >> 6) + 1);
677 /* last 64kB RAM is used for the BIOS (or something else?) */
678 si
->ps
.memory_size
-= (64 * 1024);
680 case 0x01f010de: /* Nvidia GeForce4 MX Integrated GPU */
681 /* device at bus #0, device #0, function #1 holds value at byte-index 0x84 */
682 si
->ps
.memory_size
= 1024 * 1024 *
683 (((((*pci_bus
->read_pci_config
)(0, 0, 1, 0x84, 4)) & 0x000007f0) >> 4) + 1);
684 /* last 64kB RAM is used for the BIOS (or something else?) */
685 si
->ps
.memory_size
-= (64 * 1024);
688 /* all other cards have own RAM: the amount of which is determined in the
694 result
= map_device(di
);
695 if (result
< 0) goto free_shared
;
698 /* create a semaphore for vertical blank management */
699 si
->vblank
= create_sem(0, di
->name
);
700 if (si
->vblank
< 0) {
705 /* change the owner of the semaphores to the opener's team */
706 /* this is required because apps can't aquire kernel semaphores */
707 thid
= find_thread(NULL
);
708 get_thread_info(thid
, &thinfo
);
709 set_sem_owner(si
->vblank
, thinfo
.team
);
711 /* assign local regs pointer for SAMPLExx() macros */
714 /* disable and clear any pending interrupts */
717 /* If there is a valid interrupt line assigned then set up interrupts */
718 if ((di
->pcii
.u
.h0
.interrupt_pin
== 0x00) ||
719 (di
->pcii
.u
.h0
.interrupt_line
== 0xff) || /* no IRQ assigned */
720 (di
->pcii
.u
.h0
.interrupt_line
<= 0x02)) /* system IRQ assigned */
722 /* we are aborting! */
723 /* Note: the R4 graphics driver kit lacks this statement!! */
725 /* interrupt does not exist so exit without installing our handler */
730 /* otherwise install our interrupt handler */
731 result
= install_io_interrupt_handler(di
->pcii
.u
.h0
.interrupt_line
, eng_interrupt
, (void *)di
, 0);
732 /* bail if we couldn't install the handler */
733 if (result
!= B_OK
) goto delete_the_sem
;
737 /* mark the device open */
740 /* send the cookie to the opener */
747 delete_sem(si
->vblank
);
753 /* clean up our shared area */
754 delete_area(di
->shared_area
);
755 di
->shared_area
= -1;
759 /* end of critical section */
760 RELEASE_BEN(pd
->kernel
);
762 /* all done, return the status */
767 read_hook - does nothing, gracefully
770 read_hook (void* dev
, off_t pos
, void* buf
, size_t* len
)
773 return B_NOT_ALLOWED
;
777 write_hook - does nothing, gracefully
780 write_hook (void* dev
, off_t pos
, const void* buf
, size_t* len
)
783 return B_NOT_ALLOWED
;
787 close_hook - does nothing, gracefully
790 close_hook (void* dev
)
792 /* we don't do anything on close: there might be dup'd fd */
797 free_hook - close down the device
800 free_hook (void* dev
) {
801 device_info
*di
= (device_info
*)dev
;
802 shared_info
*si
= di
->si
;
803 vuint32
*regs
= di
->regs
;
805 /* lock the driver */
806 AQUIRE_BEN(pd
->kernel
);
808 /* if opened multiple times, decrement the open count and exit */
810 goto unlock_and_exit
;
812 /* disable and clear any pending interrupts */
815 /* remove interrupt handler */
816 remove_io_interrupt_handler(di
->pcii
.u
.h0
.interrupt_line
, eng_interrupt
, di
);
818 /* delete the semaphores, ignoring any errors ('cause the owning team may have died on us) */
819 delete_sem(si
->vblank
);
822 /* free regs and framebuffer areas */
825 /* clean up our shared area */
826 delete_area(di
->shared_area
);
827 di
->shared_area
= -1;
831 /* mark the device available */
833 /* unlock the driver */
834 RELEASE_BEN(pd
->kernel
);
840 control_hook - where the real work is done
843 control_hook (void* dev
, uint32 msg
, void *buf
, size_t len
) {
844 device_info
*di
= (device_info
*)dev
;
845 status_t result
= B_DEV_INVALID_IOCTL
;
849 /* the only PUBLIC ioctl */
850 case B_GET_ACCELERANT_SIGNATURE
: {
851 char *sig
= (char *)buf
;
852 strcpy(sig
, current_settings
.accelerant
);
856 /* PRIVATE ioctl from here on */
857 case ENG_GET_PRIVATE_DATA
: {
858 eng_get_private_data
*gpd
= (eng_get_private_data
*)buf
;
859 if (gpd
->magic
== SKEL_PRIVATE_DATA_MAGIC
) {
860 gpd
->shared_info_area
= di
->shared_area
;
865 eng_get_set_pci
*gsp
= (eng_get_set_pci
*)buf
;
866 if (gsp
->magic
== SKEL_PRIVATE_DATA_MAGIC
) {
867 pci_info
*pcii
= &(di
->pcii
);
868 gsp
->value
= get_pci(gsp
->offset
, gsp
->size
);
873 eng_get_set_pci
*gsp
= (eng_get_set_pci
*)buf
;
874 if (gsp
->magic
== SKEL_PRIVATE_DATA_MAGIC
) {
875 pci_info
*pcii
= &(di
->pcii
);
876 set_pci(gsp
->offset
, gsp
->size
, gsp
->value
);
880 case ENG_DEVICE_NAME
: { // apsed
881 eng_device_name
*dn
= (eng_device_name
*)buf
;
882 if (dn
->magic
== SKEL_PRIVATE_DATA_MAGIC
) {
883 strcpy(dn
->name
, di
->name
);
887 case ENG_RUN_INTERRUPTS
: {
888 eng_set_bool_state
*ri
= (eng_set_bool_state
*)buf
;
889 if (ri
->magic
== SKEL_PRIVATE_DATA_MAGIC
) {
890 vuint32
*regs
= di
->regs
;
899 case ENG_GET_NTH_AGP_INFO
: {
900 eng_nth_agp_info
*nai
= (eng_nth_agp_info
*)buf
;
901 if (nai
->magic
== SKEL_PRIVATE_DATA_MAGIC
) {
903 nai
->agp_bus
= false;
906 if ((*agp_bus
->get_nth_agp_info
)(nai
->index
, &(nai
->agpi
)) == B_NO_ERROR
) {
913 case ENG_ENABLE_AGP
: {
914 eng_cmd_agp
*nca
= (eng_cmd_agp
*)buf
;
915 if (nca
->magic
== SKEL_PRIVATE_DATA_MAGIC
) {
918 (*agp_bus
->enable_agp
)(&(nca
->cmd
));
920 nca
->agp_bus
= false;
927 eng_in_out_isa
*io_isa
= (eng_in_out_isa
*)buf
;
928 if (io_isa
->magic
== SKEL_PRIVATE_DATA_MAGIC
) {
929 pci_info
*pcii
= &(di
->pcii
);
932 * no other graphics card may have ISA I/O enabled when we enter */
933 AQUIRE_BEN(pd
->kernel
);
935 /* enable ISA I/O access */
936 tmpUlong
= get_pci(PCI_command
, 2);
937 tmpUlong
|= PCI_command_io
;
938 set_pci(PCI_command
, 2, tmpUlong
);
940 if (io_isa
->size
== 1)
941 isa_bus
->write_io_8(io_isa
->adress
, (uint8
)io_isa
->data
);
943 isa_bus
->write_io_16(io_isa
->adress
, io_isa
->data
);
946 /* disable ISA I/O access */
947 tmpUlong
= get_pci(PCI_command
, 2);
948 tmpUlong
&= ~PCI_command_io
;
949 set_pci(PCI_command
, 2, tmpUlong
);
951 /* end of critical section */
952 RELEASE_BEN(pd
->kernel
);
956 eng_in_out_isa
*io_isa
= (eng_in_out_isa
*)buf
;
957 if (io_isa
->magic
== SKEL_PRIVATE_DATA_MAGIC
) {
958 pci_info
*pcii
= &(di
->pcii
);
961 * no other graphics card may have ISA I/O enabled when we enter */
962 AQUIRE_BEN(pd
->kernel
);
964 /* enable ISA I/O access */
965 tmpUlong
= get_pci(PCI_command
, 2);
966 tmpUlong
|= PCI_command_io
;
967 set_pci(PCI_command
, 2, tmpUlong
);
969 if (io_isa
->size
== 1)
970 io_isa
->data
= isa_bus
->read_io_8(io_isa
->adress
);
972 io_isa
->data
= isa_bus
->read_io_16(io_isa
->adress
);
975 /* disable ISA I/O access */
976 tmpUlong
= get_pci(PCI_command
, 2);
977 tmpUlong
&= ~PCI_command_io
;
978 set_pci(PCI_command
, 2, tmpUlong
);
980 /* end of critical section */
981 RELEASE_BEN(pd
->kernel
);