accelerant: replace AreaCloner with AreaDeleter
Reduce code duplication. Change-Id: Ice1a14fc7378382e89c3e5a1aea6fa21b903e436 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3482 Reviewed-by: Axel Dörfler <[email protected]>
This commit is contained in:
@@ -3,6 +3,7 @@ SubDir HAIKU_TOP src add-ons accelerants intel_extreme ;
|
|||||||
UsePrivateHeaders graphics ;
|
UsePrivateHeaders graphics ;
|
||||||
UsePrivateHeaders [ FDirName graphics intel_extreme ] ;
|
UsePrivateHeaders [ FDirName graphics intel_extreme ] ;
|
||||||
UsePrivateHeaders [ FDirName graphics common ] ;
|
UsePrivateHeaders [ FDirName graphics common ] ;
|
||||||
|
UsePrivateHeaders shared ;
|
||||||
|
|
||||||
Addon intel_extreme.accelerant :
|
Addon intel_extreme.accelerant :
|
||||||
accelerant.cpp
|
accelerant.cpp
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include <AGP.h>
|
#include <AGP.h>
|
||||||
|
#include <AutoDeleterOS.h>
|
||||||
|
|
||||||
|
|
||||||
#undef TRACE
|
#undef TRACE
|
||||||
@@ -40,53 +41,6 @@ struct accelerant_info* gInfo;
|
|||||||
uint32 gDumpCount;
|
uint32 gDumpCount;
|
||||||
|
|
||||||
|
|
||||||
class AreaCloner {
|
|
||||||
public:
|
|
||||||
AreaCloner();
|
|
||||||
~AreaCloner();
|
|
||||||
|
|
||||||
area_id Clone(const char* name, void** _address,
|
|
||||||
uint32 spec, uint32 protection,
|
|
||||||
area_id sourceArea);
|
|
||||||
status_t InitCheck()
|
|
||||||
{ return fArea < 0 ? (status_t)fArea : B_OK; }
|
|
||||||
void Keep();
|
|
||||||
|
|
||||||
private:
|
|
||||||
area_id fArea;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
AreaCloner::AreaCloner()
|
|
||||||
:
|
|
||||||
fArea(-1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AreaCloner::~AreaCloner()
|
|
||||||
{
|
|
||||||
if (fArea >= 0)
|
|
||||||
delete_area(fArea);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
area_id
|
|
||||||
AreaCloner::Clone(const char* name, void** _address, uint32 spec,
|
|
||||||
uint32 protection, area_id sourceArea)
|
|
||||||
{
|
|
||||||
fArea = clone_area(name, _address, spec, protection, sourceArea);
|
|
||||||
return fArea;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AreaCloner::Keep()
|
|
||||||
{
|
|
||||||
fArea = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -134,6 +88,7 @@ init_common(int device, bool isClone)
|
|||||||
gInfo = (accelerant_info*)malloc(sizeof(accelerant_info));
|
gInfo = (accelerant_info*)malloc(sizeof(accelerant_info));
|
||||||
if (gInfo == NULL)
|
if (gInfo == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
MemoryDeleter infoDeleter(gInfo);
|
||||||
|
|
||||||
memset(gInfo, 0, sizeof(accelerant_info));
|
memset(gInfo, 0, sizeof(accelerant_info));
|
||||||
|
|
||||||
@@ -146,33 +101,26 @@ init_common(int device, bool isClone)
|
|||||||
data.magic = INTEL_PRIVATE_DATA_MAGIC;
|
data.magic = INTEL_PRIVATE_DATA_MAGIC;
|
||||||
|
|
||||||
if (ioctl(device, INTEL_GET_PRIVATE_DATA, &data,
|
if (ioctl(device, INTEL_GET_PRIVATE_DATA, &data,
|
||||||
sizeof(intel_get_private_data)) != 0) {
|
sizeof(intel_get_private_data)) != 0)
|
||||||
free(gInfo);
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
AreaCloner sharedCloner;
|
AreaDeleter sharedDeleter(clone_area("intel extreme shared info",
|
||||||
gInfo->shared_info_area = sharedCloner.Clone("intel extreme shared info",
|
|
||||||
(void**)&gInfo->shared_info, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA,
|
(void**)&gInfo->shared_info, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA,
|
||||||
data.shared_info_area);
|
data.shared_info_area));
|
||||||
status_t status = sharedCloner.InitCheck();
|
status_t status = gInfo->shared_info_area = sharedDeleter.Get();
|
||||||
if (status < B_OK) {
|
if (status < B_OK)
|
||||||
free(gInfo);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
|
||||||
|
|
||||||
AreaCloner regsCloner;
|
AreaDeleter regsDeleter(clone_area("intel extreme regs",
|
||||||
gInfo->regs_area = regsCloner.Clone("intel extreme regs",
|
|
||||||
(void**)&gInfo->registers, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA,
|
(void**)&gInfo->registers, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA,
|
||||||
gInfo->shared_info->registers_area);
|
gInfo->shared_info->registers_area));
|
||||||
status = regsCloner.InitCheck();
|
status = gInfo->regs_area = regsDeleter.Get();
|
||||||
if (status < B_OK) {
|
if (status < B_OK)
|
||||||
free(gInfo);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
|
||||||
|
|
||||||
sharedCloner.Keep();
|
infoDeleter.Detach();
|
||||||
regsCloner.Keep();
|
sharedDeleter.Detach();
|
||||||
|
regsDeleter.Detach();
|
||||||
|
|
||||||
// The overlay registers, hardware status, and cursor memory share
|
// The overlay registers, hardware status, and cursor memory share
|
||||||
// a single area with the shared_info
|
// a single area with the shared_info
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ UseHeaders [ FDirName $(SUBDIR) atombios ] ;
|
|||||||
UsePrivateHeaders graphics ;
|
UsePrivateHeaders graphics ;
|
||||||
UsePrivateHeaders [ FDirName graphics radeon_hd ] ;
|
UsePrivateHeaders [ FDirName graphics radeon_hd ] ;
|
||||||
UsePrivateHeaders [ FDirName graphics common ] ;
|
UsePrivateHeaders [ FDirName graphics common ] ;
|
||||||
|
UsePrivateHeaders shared ;
|
||||||
|
|
||||||
Addon radeon_hd.accelerant :
|
Addon radeon_hd.accelerant :
|
||||||
accelerant.cpp
|
accelerant.cpp
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <AutoDeleterOS.h>
|
||||||
|
|
||||||
#include "accelerant_protos.h"
|
#include "accelerant_protos.h"
|
||||||
|
|
||||||
#include "bios.h"
|
#include "bios.h"
|
||||||
@@ -46,53 +48,6 @@ connector_info* gConnector[ATOM_MAX_SUPPORTED_DEVICE];
|
|||||||
gpio_info* gGPIOInfo[MAX_GPIO_PINS];
|
gpio_info* gGPIOInfo[MAX_GPIO_PINS];
|
||||||
|
|
||||||
|
|
||||||
class AreaCloner {
|
|
||||||
public:
|
|
||||||
AreaCloner();
|
|
||||||
~AreaCloner();
|
|
||||||
|
|
||||||
area_id Clone(const char* name, void** _address,
|
|
||||||
uint32 spec, uint32 protection,
|
|
||||||
area_id sourceArea);
|
|
||||||
status_t InitCheck()
|
|
||||||
{return fArea < 0 ? (status_t)fArea : B_OK;}
|
|
||||||
void Keep();
|
|
||||||
|
|
||||||
private:
|
|
||||||
area_id fArea;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
AreaCloner::AreaCloner()
|
|
||||||
:
|
|
||||||
fArea(-1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AreaCloner::~AreaCloner()
|
|
||||||
{
|
|
||||||
if (fArea >= 0)
|
|
||||||
delete_area(fArea);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
area_id
|
|
||||||
AreaCloner::Clone(const char* name, void** _address, uint32 spec,
|
|
||||||
uint32 protection, area_id sourceArea)
|
|
||||||
{
|
|
||||||
fArea = clone_area(name, _address, spec, protection, sourceArea);
|
|
||||||
return fArea;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AreaCloner::Keep()
|
|
||||||
{
|
|
||||||
fArea = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -105,6 +60,7 @@ init_common(int device, bool isClone)
|
|||||||
// initialize global accelerant info structure
|
// initialize global accelerant info structure
|
||||||
|
|
||||||
gInfo = (accelerant_info*)malloc(sizeof(accelerant_info));
|
gInfo = (accelerant_info*)malloc(sizeof(accelerant_info));
|
||||||
|
MemoryDeleter infoDeleter(gInfo);
|
||||||
|
|
||||||
if (gInfo == NULL)
|
if (gInfo == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
@@ -161,24 +117,20 @@ init_common(int device, bool isClone)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
AreaCloner sharedCloner;
|
AreaDeleter sharedDeleter(clone_area("radeon hd shared info",
|
||||||
gInfo->shared_info_area = sharedCloner.Clone("radeon hd shared info",
|
|
||||||
(void**)&gInfo->shared_info, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA,
|
(void**)&gInfo->shared_info, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA,
|
||||||
data.shared_info_area);
|
data.shared_info_area));
|
||||||
status_t status = sharedCloner.InitCheck();
|
status_t status = gInfo->shared_info_area = sharedDeleter.Get();
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
free(gInfo);
|
|
||||||
TRACE("%s, failed to create shared area\n", __func__);
|
TRACE("%s, failed to create shared area\n", __func__);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
AreaCloner regsCloner;
|
AreaDeleter regsDeleter(clone_area("radeon hd regs",
|
||||||
gInfo->regs_area = regsCloner.Clone("radeon hd regs",
|
|
||||||
(void**)&gInfo->regs, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA,
|
(void**)&gInfo->regs, B_ANY_ADDRESS, B_READ_AREA | B_WRITE_AREA,
|
||||||
gInfo->shared_info->registers_area);
|
gInfo->shared_info->registers_area));
|
||||||
status = regsCloner.InitCheck();
|
status = gInfo->regs_area = regsDeleter.Get();
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
free(gInfo);
|
|
||||||
TRACE("%s, failed to create mmio area\n", __func__);
|
TRACE("%s, failed to create mmio area\n", __func__);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@@ -195,8 +147,9 @@ init_common(int device, bool isClone)
|
|||||||
if (gInfo->rom[0] != 0x55 || gInfo->rom[1] != 0xAA)
|
if (gInfo->rom[0] != 0x55 || gInfo->rom[1] != 0xAA)
|
||||||
TRACE("%s: didn't find a VGA bios in cloned region!\n", __func__);
|
TRACE("%s: didn't find a VGA bios in cloned region!\n", __func__);
|
||||||
|
|
||||||
sharedCloner.Keep();
|
infoDeleter.Detach();
|
||||||
regsCloner.Keep();
|
sharedDeleter.Detach();
|
||||||
|
regsDeleter.Detach();
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ SubDir HAIKU_TOP src add-ons accelerants vesa ;
|
|||||||
UsePrivateHeaders graphics ;
|
UsePrivateHeaders graphics ;
|
||||||
UsePrivateHeaders [ FDirName graphics vesa ] ;
|
UsePrivateHeaders [ FDirName graphics vesa ] ;
|
||||||
UsePrivateHeaders [ FDirName graphics common ] ;
|
UsePrivateHeaders [ FDirName graphics common ] ;
|
||||||
|
UsePrivateHeaders shared ;
|
||||||
|
|
||||||
#AddResources vesa.accelerant : vesa.accelerant.rdef ;
|
#AddResources vesa.accelerant : vesa.accelerant.rdef ;
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
|
#include <AutoDeleterOS.h>
|
||||||
|
|
||||||
|
|
||||||
//#define TRACE_ACCELERANT
|
//#define TRACE_ACCELERANT
|
||||||
#ifdef TRACE_ACCELERANT
|
#ifdef TRACE_ACCELERANT
|
||||||
@@ -27,51 +29,6 @@ extern "C" void _sPrintf(const char *format, ...);
|
|||||||
struct accelerant_info *gInfo;
|
struct accelerant_info *gInfo;
|
||||||
|
|
||||||
|
|
||||||
class AreaCloner {
|
|
||||||
public:
|
|
||||||
AreaCloner();
|
|
||||||
~AreaCloner();
|
|
||||||
|
|
||||||
area_id Clone(const char *name, void **_address, uint32 spec,
|
|
||||||
uint32 protection, area_id sourceArea);
|
|
||||||
status_t InitCheck() { return fArea < B_OK ? (status_t)fArea : B_OK; }
|
|
||||||
void Keep();
|
|
||||||
|
|
||||||
private:
|
|
||||||
area_id fArea;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
AreaCloner::AreaCloner()
|
|
||||||
:
|
|
||||||
fArea(-1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
AreaCloner::~AreaCloner()
|
|
||||||
{
|
|
||||||
if (fArea >= B_OK)
|
|
||||||
delete_area(fArea);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
area_id
|
|
||||||
AreaCloner::Clone(const char *name, void **_address, uint32 spec,
|
|
||||||
uint32 protection, area_id sourceArea)
|
|
||||||
{
|
|
||||||
fArea = clone_area(name, _address, spec, protection, sourceArea);
|
|
||||||
return fArea;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
AreaCloner::Keep()
|
|
||||||
{
|
|
||||||
fArea = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -84,6 +41,7 @@ init_common(int device, bool isClone)
|
|||||||
// initialize global accelerant info structure
|
// initialize global accelerant info structure
|
||||||
|
|
||||||
gInfo = (accelerant_info *)malloc(sizeof(accelerant_info));
|
gInfo = (accelerant_info *)malloc(sizeof(accelerant_info));
|
||||||
|
MemoryDeleter infoDeleter(gInfo);
|
||||||
if (gInfo == NULL)
|
if (gInfo == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -102,15 +60,12 @@ init_common(int device, bool isClone)
|
|||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
AreaCloner sharedCloner;
|
AreaDeleter sharedDeleter(clone_area("vesa shared info",
|
||||||
gInfo->shared_info_area = sharedCloner.Clone("vesa shared info",
|
|
||||||
(void **)&gInfo->shared_info, B_ANY_ADDRESS,
|
(void **)&gInfo->shared_info, B_ANY_ADDRESS,
|
||||||
B_READ_AREA | B_WRITE_AREA, sharedArea);
|
B_READ_AREA | B_WRITE_AREA, sharedArea));
|
||||||
status_t status = sharedCloner.InitCheck();
|
status_t status = gInfo->shared_info_area = sharedDeleter.Get();
|
||||||
if (status < B_OK) {
|
if (status < B_OK)
|
||||||
free(gInfo);
|
|
||||||
return status;
|
return status;
|
||||||
}
|
|
||||||
|
|
||||||
if (gInfo->shared_info->vesa_mode_count == 0)
|
if (gInfo->shared_info->vesa_mode_count == 0)
|
||||||
gInfo->vesa_modes = NULL;
|
gInfo->vesa_modes = NULL;
|
||||||
@@ -118,7 +73,8 @@ init_common(int device, bool isClone)
|
|||||||
gInfo->vesa_modes = (vesa_mode *)((uint8 *)gInfo->shared_info
|
gInfo->vesa_modes = (vesa_mode *)((uint8 *)gInfo->shared_info
|
||||||
+ gInfo->shared_info->vesa_mode_offset);
|
+ gInfo->shared_info->vesa_mode_offset);
|
||||||
|
|
||||||
sharedCloner.Keep();
|
infoDeleter.Detach();
|
||||||
|
sharedDeleter.Detach();
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user