vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / drivers / audio / ac97 / sis7018 / Device.h
blob974d781d0afb5e418f7141a5ec37723cd36faffd
1 /*
2 * SiS 7018, Trident 4D Wave DX/NX, Acer Lab M5451 Sound Driver.
3 * Copyright (c) 2002, 2008-2011 S.Zharski <imker@gmx.li>
4 * Distributed under the terms of the MIT license.
6 */
7 #ifndef _SiS7018_DEVICE_H_
8 #define _SiS7018_DEVICE_H_
11 #include <KernelExport.h>
13 #include "Driver.h"
14 #include "Mixer.h"
15 #include "Registers.h"
16 #include "Settings.h"
17 #include "Stream.h"
20 // card ids for supported audio hardware
21 const uint32 SiS7018 = 0x70181039;
22 const uint32 ALi5451 = 0x545110b9;
23 const uint32 TridentDX = 0x20001023;
24 const uint32 TridentNX = 0x20011023;
27 class Device {
29 public:
30 class Info {
31 public:
32 const uint32 fId;
33 const char* fName;
34 inline const char* Name() { return fName; }
35 inline uint16 DeviceId() { return (fId >> 16) & 0xffff; }
36 inline uint16 VendorId() { return (fId) & 0xffff; }
37 inline uint32 Id() { return fId; }
40 uint32 HardwareId() { return fInfo.Id(); }
41 pci_info& PCIInfo() { return fPCIInfo; }
44 Device(Info &DeviceInfo, pci_info &PCIInfo);
45 ~Device();
47 status_t Setup();
48 status_t InitCheck() { return fStatus; };
50 status_t Open(uint32 flags);
51 status_t Read(uint8 *buffer, size_t *numBytes);
52 status_t Write(const uint8 *buffer, size_t *numBytes);
53 status_t Control(uint32 op, void *buffer, size_t length);
54 status_t Close();
55 status_t Free();
57 static int32 InterruptHandler(void *interruptParam);
58 void SignalReadyBuffers();
60 class Mixer& Mixer() { return fMixer; }
62 cpu_status Lock();
63 void Unlock(cpu_status st);
65 uint8 ReadPCI8(int offset);
66 uint16 ReadPCI16(int offset);
67 uint32 ReadPCI32(int offset);
68 void WritePCI8(int offset, uint8 value);
69 void WritePCI16(int offset, uint16 value);
70 void WritePCI32(int offset, uint32 value);
72 private:
73 status_t _ReserveDeviceOnBus(bool reserve);
74 void _ResetCard(uint32 resetMask, uint32 releaseMask);
76 status_t _MultiGetDescription(multi_description *Description);
77 status_t _MultiGetEnabledChannels(multi_channel_enable *Enable);
78 status_t _MultiSetEnabledChannels(multi_channel_enable *Enable);
79 status_t _MultiGetBuffers(multi_buffer_list* List);
80 status_t _MultiGetGlobalFormat(multi_format_info *Format);
81 status_t _MultiSetGlobalFormat(multi_format_info *Format);
82 status_t _MultiGetMix(multi_mix_value_info *Info);
83 status_t _MultiSetMix(multi_mix_value_info *Info);
84 status_t _MultiListMixControls(multi_mix_control_info* Info);
85 status_t _MultiBufferExchange(multi_buffer_info* Info);
87 status_t fStatus;
88 pci_info fPCIInfo;
89 Info& fInfo;
90 int fIOBase;
91 spinlock fHWSpinlock;
92 int32 fInterruptsNest;
93 sem_id fBuffersReadySem;
95 class Mixer fMixer;
96 Stream fPlaybackStream;
97 Stream fRecordStream;
100 #endif // _SiS7018_DEVICE_H_